HW6 Hypothesis Testing
HW6 Hypothesis Testing
2023-12-19
Question One
# Confidence Intervals
# Hypothesis Testing
1
# Claim: Percentage of Pies with More than 0.19 Alcohol Units (Toni vs. Tina)
p1_hat_tina <- pies_more_than_019_tina / n_tina
z_stat_tina <- (p_hat_toni - p1_hat_tina) / sqrt((p_hat_toni * (1 - p_hat_toni) / n_toni) + (p1_hat_tina
p_value_proportion_comparison <- pnorm(z_stat_tina, lower.tail = FALSE)
# Display results
cat("Confidence Intervals for Team Toni:\n")
cat("Claim: Percentage of Pies with More than 0.19 Alcohol Units - p-value:", p_value_proportion_compari
## Claim: Percentage of Pies with More than 0.19 Alcohol Units - p-value: 0.565278
Question Two
i. Representative Sample
2
# Given data
n <- 500
sample_median <- 53.1
population_median <- 52.3
sample_std_dev <- 11.3
# Test Statistic
t_stat_median <- (sample_median - population_median) / (sample_std_dev / sqrt(n))
# Two-tailed p-value
p_value_median <- 2 * pt(abs(t_stat_median), df = n - 1, lower.tail = FALSE)
# Display result
cat("i. Representative Sample Test Result:\n")
## p-value: 0.114042
# Given data
n_obese <- 89
mean_age_obese <- 52.6
std_dev_obese <- 13.5
# Test Statistic
t_stat_mean_diff <- (mean_age_obese - mean_age_non_obese) / sqrt((std_dev_obeseˆ2 / n_obese) + (std_dev_
# Degrees of freedom
df_mean_diff <- (std_dev_obeseˆ2 / n_obese + std_dev_non_obeseˆ2 / n_non_obese)ˆ2 / ((1 / (n_obese - 1))
# Two-tailed p-value
p_value_mean_diff <- 2 * pt(abs(t_stat_mean_diff), df = df_mean_diff, lower.tail = FALSE)
# Display result
cat("ii. Difference in Mean Age Test Result:\n")
3
cat("Test Statistic (t):", t_stat_mean_diff, "\n")
## p-value: 0.03091665
# Test Statistic
f_stat_var_diff <- (std_dev_obeseˆ2 / std_dev_non_obeseˆ2)
# Degrees of freedom
df1_var_diff <- n_obese - 1
df2_var_diff <- n_non_obese - 1
# Two-tailed p-value
p_value_var_diff <- 2 * pf(f_stat_var_diff, df1 = df1_var_diff, df2 = df2_var_diff, lower.tail = FALSE)
# Display result
cat("iii. Difference in Variability Test Result:\n")
## p-value: 2
# Given data
n_support_obese <- 26
n_support_non_obese <- 138
# Proportions
p_support_obese <- n_support_obese / n_obese
p_support_non_obese <- n_support_non_obese / n_non_obese
# Test Statistic
p_hat_pooled <- (n_support_obese + n_support_non_obese) / (n_obese + n_non_obese)
4
z_stat_prop_diff <- (p_support_obese - p_support_non_obese) / sqrt(p_hat_pooled * (1 - p_hat_pooled) * (
# Two-tailed p-value
p_value_prop_diff <- 2 * pnorm(abs(z_stat_prop_diff), lower.tail = FALSE)
# Display result
cat("iv. Difference in Proportions Test Result:\n")
## p-value: 0.4266739