Skip to main content

Section B.6 Two means (paired samples)

Subsection B.6.1 Problem statement

Trace metals in drinking water affect the flavor and an unusually high concentration can pose a health hazard. Ten pairs of data were taken measuring zinc concentration in bottom water and surface water at 10 randomly selected locations on a stretch of river. Do the data suggest that the true average concentration in the surface water is smaller than that of bottom water?

Subsection B.6.2 Competing hypotheses

  • Null hypothesis: The mean concentration in the bottom water is the same as that of the surface water at different paired locations.
  • Alternative hypothesis: The mean concentration in the surface water is smaller than that of the bottom water at different paired locations.
  • \(H_0: \mu_{\text{diff}} = 0\text{,}\) where \(\mu_{\text{diff}}\) represents the mean difference in concentration for surface water minus bottom water.
  • \(\displaystyle H_A: \mu_{\text{diff}} < 0\)
Significance level: \(\alpha = 0.05\text{.}\)

Subsection B.6.3 Exploring the sample data

zinc_tidy <- read_csv("https://moderndive.com/data/zinc_tidy.csv")
zinc_diff <- zinc_tidy |>
  group_by(loc_id) |>
  summarize(pair_diff = diff(concentration)) |>
  ungroup()

d_hat <- zinc_diff |>
  specify(response = pair_diff) |>
  calculate(stat = "mean")
d_hat

ggplot(zinc_diff, aes(x = pair_diff)) +
  geom_histogram(binwidth = 0.04, color = "white")

Subsection B.6.4 Simulation-based methods

set.seed(2018)
null_distn_paired_means <- zinc_diff |>
  specify(response = pair_diff) |>
  hypothesize(null = "point", mu = 0) |>
  generate(reps = 10000) |>
  calculate(stat = "mean")

null_distn_paired_means |>
  visualize() +
  shade_p_value(obs_stat = d_hat, direction = "less")

pvalue <- null_distn_paired_means |>
  get_pvalue(obs_stat = d_hat, direction = "less")
pvalue
The \(p\)-value is essentially 0 and we reject the null hypothesis at the 5% level.
boot_distn_paired_means <- zinc_diff |>
  specify(response = pair_diff) |>
  generate(reps = 10000) |>
  calculate(stat = "mean")

ci <- boot_distn_paired_means |>
  get_ci()
ci

boot_distn_paired_means |>
  visualize() +
  shade_ci(endpoints = ci)
We see that 0 is not contained in this confidence interval. This matches with our hypothesis test results of rejecting the null hypothesis. Since the entire confidence interval falls below zero, we have evidence that surface zinc concentration levels are lower, on average, than bottom level zinc concentrations.

Subsection B.6.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 pairs are selected independently. This condition is met since the locations are randomly selected.
  2. Approximately normal: The distribution of the differences should be normal or the sample size should be at least 30. The sample size is small (n = 10), but the differences do not show extreme skewness.

Test statistic.

The paired \(t\)-test treats the differences as a single sample:
\begin{equation*} T = \frac{\bar{X}_{\text{diff}} - 0}{S_{\text{diff}} / \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.
t_test_results <- zinc_diff |>
  t_test(
    formula = pair_diff ~ NULL,
    alternative = "less",
    mu = 0
  )
t_test_results

Compute \(p\)-value.

The \(p\)-value can be calculated in R:
pt(-4.8638, df = nrow(zinc_diff) - 1, lower.tail = TRUE)

State conclusion.

We have sufficient evidence to reject the null hypothesis. Based on this sample, we have evidence that the mean concentration in the bottom water is greater than that of the surface water at different paired locations.

Subsection B.6.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 were not met since the number of pairs was small, but the sample data was not highly skewed. Using any of the methods whether they are traditional (formula-based) or non-traditional (computational-based) lead to similar results here.