Section B.2 One mean
Subsection B.2.1 Problem statement
The National Survey of Family Growth conducted by the Centers for Disease Control gathers information on family life, marriage and divorce, pregnancy, infertility, use of contraception, and menβs and womenβs health. One of the variables collected on this survey is the age at first marriage. 5,534 randomly sampled US women between 2006 and 2010 completed the survey. The women sampled here had been married at least once. Do we have evidence that the mean age of first marriage for all US women from 2006 to 2010 is greater than 23 years? (Tweaked a bit from [7], Chapter 4.)
Subsection B.2.2 Competing hypotheses
In words:
-
Null hypothesis: The mean age of first marriage for all US women from 2006 to 2010 is equal to 23 years.
-
Alternative hypothesis: The mean age of first marriage for all US women from 2006 to 2010 is greater than 23 years.
In symbols (with annotations):
-
\(H_0: \mu = \mu_0\text{,}\) where \(\mu\) represents the mean age of first marriage for all US women from 2006 to 2010 and \(\mu_0\) is 23.
-
\(\displaystyle H_A: \mu > 23\)
Itβs important to set the significance level before starting the testing using the data. Letβs set the significance level at 5% here.
Subsection B.2.3 Exploring the sample data
age_at_marriage <- read_csv("https://moderndive.com/data/ageAtMar.csv")
age_summ <- age_at_marriage |>
summarize(
sample_size = n(),
mean = mean(age),
sd = sd(age),
minimum = min(age),
lower_quartile = quantile(age, 0.25),
median = median(age),
upper_quartile = quantile(age, 0.75),
max = max(age)
)
age_summ
# A tibble: 1 Γ 5
sample_size mean sd min max
<int> <dbl> <dbl> <dbl> <dbl>
1 5534 23.4 4.72 10 43
ggplot(data = age_at_marriage, mapping = aes(x = age)) +
geom_histogram(binwidth = 3, color = "white")
The observed statistic of interest here is the sample mean:
x_bar <- age_at_marriage |>
specify(response = age) |>
calculate(stat = "mean")
x_bar
Subsection B.2.4 Simulation-based methods
We can use bootstrapping to simulate the population from which the sample came and generate samples to account for sampling variability.
set.seed(2018)
null_distn_one_mean <- age_at_marriage |>
specify(response = age) |>
hypothesize(null = "point", mu = 23) |>
generate(reps = 10000) |>
calculate(stat = "mean")
null_distn_one_mean |>
visualize() +
shade_p_value(obs_stat = x_bar, direction = "greater")
pvalue <- null_distn_one_mean |>
get_pvalue(obs_stat = x_bar, direction = "greater")
pvalue
The \(p\)-value is small and we reject the null hypothesis at the 5% level.
We can also create a confidence interval for the unknown population parameter \(\mu\) using bootstrapping:
boot_distn_one_mean <- age_at_marriage |>
specify(response = age) |>
generate(reps = 10000) |>
calculate(stat = "mean")
ci <- boot_distn_one_mean |>
get_ci()
ci
boot_distn_one_mean |>
visualize() +
shade_ci(endpoints = ci)
We see that 23 is not contained in this confidence interval and the entire interval is larger than 23. This matches with our hypothesis test results of rejecting the null hypothesis.
Interpretation: We are 95% confident the true mean age of first marriage for all US women from 2006 to 2010 falls within this interval.
Subsection B.2.5 Theory-based methods
Check conditions.
Remember that in order to use the shortcut (formula-based, theoretical) approach, we need to check that some conditions are met.
-
Independent observations: The cases are selected independently through random sampling so this condition is met.
-
Approximately normal: The distribution of the response variable should be normal or the sample size should be at least 30. The histogram shows some skew but the sample size is 5,534 which greatly exceeds 30. Both conditions are met.
Test statistic.
If conditions are met and assuming \(H_0\) is true, we can standardize \(\bar{X}\) into a \(T\) statistic:
\begin{equation*}
T = \frac{\bar{X} - \mu_0}{S / \sqrt{n}} \sim t(df = n - 1)
\end{equation*}
Observed test statistic.
While one could compute this observed test statistic by "hand", the focus here is on the set-up of the problem and in understanding which formula for the test statistic applies. We can use the
t_test() function to perform this analysis for us.
t_test_results <- age_at_marriage |>
t_test(
formula = age ~ NULL,
alternative = "greater",
mu = 23
)
t_test_results
Compute \(p\)-value.
The \(p\)-value is essentially 0, indicating strong evidence against the null hypothesis.
State conclusion.
We therefore have sufficient evidence to reject the null hypothesis. Based on this sample, we have evidence that the mean age of first marriage for all US women from 2006 to 2010 is greater than 23 years.
Confidence interval.
t.test(
x = age_at_marriage$age,
alternative = "two.sided",
mu = 23
)$conf
[1] 23.31577 23.56461 attr(,"conf.level") [1] 0.95
Subsection B.2.6 Comparing results
Observing the bootstrap distribution that was created, it makes quite a bit of sense that the results are so similar for traditional and non-traditional methods in terms of the \(p\)-value and the confidence interval since these distributions look very similar to normal distributions. The conditions also being met (the large sample size was the driver here) leads us to better guess that using any of the methods whether they are traditional (formula-based) or non-traditional (computational-based) will lead to similar results.
