What Is Hypothesis Testing?

Hypothesis testing let’s us use data to check whether a claim about a population is true or not true.

Example: A professor says that students in his class score 75% on average for the final exam. We want to test if that’s actually true by looking at the samples of exam scores.

Setting Up the Hypothesis

We define two competing statements:

\[H_0: \mu = 75 \quad \text{(null hypothesis)}\]

\[H_a: \mu \neq 75 \quad \text{(alternative hypothesis)}\]

  • \(H_0\) assumes that the claim is true.
  • \(H_a\) is what we are trying to find the evidence for.
  • \(H_0\), We reject only if the data gives us enough disproving evidence.

The Test Statistic

We measure how far the sample mean is from the claimed value using the t-statistic:

\[t = \frac{\bar{x} - \mu_0}{s / \sqrt{n}}\]

where:

  • \(\bar{x}\) is the sample mean
  • \(\mu_0 = 75\) is the claimed average exam score
  • \(s\) is the sample standard deviation
  • \(n\) is the sample size

Generating The Sample Data

set.seed(99)
# simulate 30 students exam scores
sample_data <- rnorm(30, mean = 72, sd = 8)

sample_mean <- mean(sample_data)
sample_sd <- sd(sample_data)
n <- length(sample_data)

t_stat <- (sample_mean - 75) / (sample_sd / sqrt(n))
p_value <- 2 * pt(-abs(t_stat), df = n - 1)

Exam Score Distributions

Visualizing the P-Value

Interactive Look at the Scores

Conclusion

  • The sample mean was 70.76 which is below the claimed 75.
  • We got a p-value of 0.0084.
  • Since the p-value is less than 0.05, we reject \(H_0\).
  • So the data suggests the true average score is probably not 75.