2025-11-09

Why Hypothesis Testing?

Suppose a manufacturer claims their widget’s mean lifetime is 50 units. You collect a sample - how strong is the evidence against that claim?

Hypothesis Testing

We formalize with null and alternative hypotheses:

\[H_0: \mu = \mu_0 \text{ vs. } H_A: \mu \neq \mu_0\]

Test statistic (one-sample t):

\[t = \frac{\bar{X} - \mu_0}{s/\sqrt{n}}, \quad s^2 = \frac{1}{n-1}\sum_{i=1}^{n}(X_i - \bar{X})^2\]

Hypothesis Testing

Two-sided p-value definition:

\[\text{p-value} = P(|T_{n-1}| \geq |t_{\text{obs}}|) = 2 \cdot (1 - F_{T_{n-1}}(|t_{\text{obs}}|))\]

Decision rule (for significance level \(\alpha\)): reject \(H_0\) if p-value \(< \alpha\).

Final Dataset

Simulated example data - preview (first 8 rows)
id lifetime
Obs01 56.725
Obs02 53.214
Obs03 57.639
Obs04 60.635
Obs05 55.226
Obs06 52.023
Obs07 55.383
Obs08 52.520

Observed Test Values

Summary statistics and observed test result
n mean sd t_obs p_value
30 54.241 5.858 3.965 0.0004395

Final Dataset Histogram

Simulated Null Distribution

Core R Code for the t-test

n <- 30
mu0 <- 50
x <- sample_data$lifetime

xbar <- mean(x)
s <- sd(x)
t_obs <- (xbar - mu0) / (s / sqrt(n))

p_value <- 2 * (1 - pt(abs(t_obs), df = n - 1))

t.test(x, mu = mu0)

Interactive t-distribution

This interactive plot shows the t-distribution (df = n-1), shaded two-tailed p-value areas, and the observed t.

95% Confidence Interval for μ

## 95% CI for μ: [52.053, 56.428]

Results and Conclusion

## Sample size (n) = 30
## Observed mean (x̄) = 54.241
## Sample SD (s) = 5.858
## Observed t = 3.965
## Two-sided p-value = 0.0004395
## 
## Conclusion (α = 0.05): Reject H₀. There is statistically significant evidence that μ ≠ `μ₀`.