Hypothesis testing is a statistical method for deciding whether sample data provides enough evidence against a claim about a population.
We are testing 8 hours of sleep per night.
2026-06-08
Hypothesis testing is a statistical method for deciding whether sample data provides enough evidence against a claim about a population.
We are testing 8 hours of sleep per night.
Suppose we collect sleep data from a random sample of 40 students.
Question:
Is the true average sleep time different from 8 hours?
The population mean is unknown, so we use a sample to make an evidence-based decision.
For a two-sided one-sample t-test, the hypotheses are:
\[H_0: \mu = 8\]
\[H_a: \mu \ne 8\]
Where:
| student | sleep_hours |
|---|---|
| 1 | 7.62 |
| 2 | 4.83 |
| 3 | 7.66 |
| 4 | 7.78 |
| 5 | 7.25 |
| 6 | 8.03 |
| 7 | 7.40 |
| 8 | 6.07 |
| 9 | 7.31 |
| 10 | 7.99 |
The full sample has 40 students.
The sample mean is 7.37 hours.
The one-sample t statistic is:
\[t = \frac{\bar{x} - \mu_0}{s / \sqrt{n}}\]
For this sample:
\[t = \frac{7.371 - 8}{0.789 / \sqrt{40}} = -5.041\]
The degrees of freedom are:
\[df = n - 1 = 39\]
The p-value is the probability of getting a result at least as extreme as the observed result, assuming the null hypothesis is true.
For a two-sided test:
\[p = 2P(T_{df} \ge |t|)\]
For this sample:
\[p = 0\]
This code calculates the t statistic and p-value.
mu0 <- 8 n <- nrow(sleep_data) xbar <- mean(sleep_data$sleep_hours) s <- sd(sleep_data$sleep_hours) se <- s / sqrt(n) t_stat <- (xbar - mu0) / se df <- n - 1 p_value <- 2 * pt(abs(t_stat), df = df, lower.tail = FALSE) round(c(t_stat = t_stat, p_value = p_value), 4)
## t_stat p_value ## -5.0411 0.0000
Using a significance level of \(\alpha = 0.05\):
## Reject the null hypothesis. ## ## The sample provides evidence that the true mean sleep time is different from 8 hours.
Hypothesis testing helps us decide whether sample evidence is strong enough to challenge a claim about a population.
Key steps: