Skip to main content

Section B.5 Two means (independent samples)

Subsection B.5.1 Problem statement

Average income varies from one region of the country to another, and it often reflects both lifestyles and regional living expenses. Suppose a new graduate is considering a job in two locations, Cleveland, OH and Sacramento, CA, and he wants to see whether the average income in one of these cities is higher than the other. He would like to conduct a hypothesis test based on two randomly selected samples from the 2000 Census. (Tweaked a bit from [7], Chapter 5.)

Subsection B.5.2 Competing hypotheses

  • Null hypothesis: The mean income is the same for both cities.
  • Alternative hypothesis: The mean income is different for the two cities.
Significance level: \(\alpha = 0.05\text{.}\)

Subsection B.5.3 Exploring the sample data

cle_sac <- read.delim("https://moderndive.com/data/cleSac.txt") |>
  rename(
    metro_area = Metropolitan_area_Detailed,
    income = Total_personal_income
  ) |>
  na.omit()
inc_summ <- cle_sac |>
  group_by(metro_area) |>
  summarize(
    sample_size = n(),
    mean = mean(income),
    sd = sd(income),
    minimum = min(income),
    lower_quartile = quantile(income, 0.25),
    median = median(income),
    upper_quartile = quantile(income, 0.75),
    max = max(income)
  )
inc_summ

ggplot(cle_sac, aes(x = metro_area, y = income)) +
  geom_boxplot() +
  stat_summary(fun = "mean", geom = "point", color = "red")

Subsection B.5.4 Simulation-based methods

d_hat <- cle_sac |>
  specify(income ~ metro_area) |>
  calculate(
    stat = "diff in means",
    order = c("Sacramento_ CA", "Cleveland_ OH")
  )
d_hat
set.seed(2018)
null_distn_two_means <- cle_sac |>
  specify(income ~ metro_area) |>
  hypothesize(null = "independence") |>
  generate(reps = 10000) |>
  calculate(
    stat = "diff in means",
    order = c("Sacramento_ CA", "Cleveland_ OH")
  )

null_distn_two_means |>
  visualize() +
  shade_p_value(obs_stat = d_hat, direction = "both")

pvalue <- null_distn_two_means |>
  get_pvalue(obs_stat = d_hat, direction = "both")
pvalue
The \(p\)-value is greater than 0.05 and we fail to reject the null hypothesis.
boot_distn_two_means <- cle_sac |>
  specify(income ~ metro_area) |>
  generate(reps = 10000) |>
  calculate(
    stat = "diff in means",
    order = c("Sacramento_ CA", "Cleveland_ OH")
  )

ci <- boot_distn_two_means |>
  get_ci()
ci

boot_distn_two_means |>
  visualize() +
  shade_ci(endpoints = ci)
We see that 0 is contained in this confidence interval. This matches with our hypothesis test results of failing to reject the null hypothesis.

Subsection B.5.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.
  1. Independent observations: The observations are independent in both groups. This condition is met since the cases are randomly selected from each city.
  2. Approximately normal: The distribution of the response for each group should be normal or the sample sizes should be at least 30. We have some reason to doubt the normality assumption since both histograms show deviation from a normal model, but the sample sizes for each group are greater than 100 so the assumptions should still apply.
  3. Independent samples: The samples should be collected without any natural pairing. There is no mention of there being a relationship between those selected in Cleveland and in Sacramento.

Test statistic.

If conditions are met and \(H_0\) is true, we can standardize the difference in sample means:
\begin{equation*} T = \frac{(\bar{X}_1 - \bar{X}_2) - 0}{\sqrt{\dfrac{S_1^2}{n_1} + \dfrac{S_2^2}{n_2}}} \sim t(df = \min(n_1 - 1, n_2 - 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.
cle_sac |>
  specify(income ~ metro_area) |>
  calculate(
    stat = "t",
    order = c("Cleveland_ OH", "Sacramento_ CA")
  )
We see here that the observed test statistic value is around -1.5.

Compute \(p\)-value.

The \(p\)-valueβ€”the probability of observing a \(t\) value of -1.501 or more extreme (in both directions) in our null distributionβ€”is 0.13. This can also be calculated in R directly:
2 * pt(-1.501, df = min(212 - 1, 175 - 1), lower.tail = TRUE)

State conclusion.

We do not have sufficient evidence to reject the null hypothesis. We do not have evidence to suggest that the true mean income differs between Cleveland, OH and Sacramento, CA based on this data.

Subsection B.5.6 Comparing results

Observing the bootstrap distribution and the null distribution that were 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 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.