2026-06-08

Big Idea

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.

Research Question

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.

Hypotheses

For a two-sided one-sample t-test, the hypotheses are:

\[H_0: \mu = 8\]

\[H_a: \mu \ne 8\]

Where:

  • \(\mu\) is the true mean number of sleep hours
  • \(H_0\) is the null hypothesis
  • \(H_a\) is the alternative hypothesis

Simulated Sleep Data

First 10 observations from the simulated sample
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.

ggplot 1: Distribution of Sleep Hours

ggplot 2: Sample Mean Compared with 8 Hours

Test Statistic

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\]

p-value

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\]

Plotly Plot: p-value Surface

R Code Example

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

Decision

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.

Takeaways

Hypothesis testing helps us decide whether sample evidence is strong enough to challenge a claim about a population.

Key steps:

  1. State \(H_0\) and \(H_a\)
  2. Choose a test statistic
  3. Compute a p-value
  4. Compare the p-value with \(\alpha\)
  5. Make a conclusion in context