What is Hypothesis Testing?

Hypothesis testing is a statistical method used to make decisions.

We test:

\[H_0: \mu = \mu_0\] \[H_a: \mu \ne \mu_0\]

Test Statistic

We calculate:

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

Decision Rule

  • If \(|t| > t^*\) → Reject \(H_0\)
  • If \(|t| \le t^*\) → Fail to reject \(H_0\)

The significance level (\(\alpha\)) is usually 0.05 or 0.01.

P-value

The p-value measures how strong the evidence is against \(H_0\).

  • Small p-value → strong evidence
  • Large p-value → weak evidence

If p-value < \(\alpha\), reject \(H_0\).

Example

Suppose we test:

  • \(H_0: \mu = 5\)
  • Sample mean = 5.2
  • Standard deviation = 1.5
  • Sample size = 30

We calculate the test statistic and make a decision.

Histogram

set.seed(1)
data <- data.frame(x = rnorm(100))

ggplot(data, aes(x)) +
  geom_histogram(bins = 20)

QQ Plot

ggplot(data, aes(sample = x)) +
  stat_qq() +
  stat_qq_line()

Interactive Plot

plot_ly(x = ~data$x, type = "histogram")

R Code Example

mean(data$x)
## [1] 0.1088874
sd(data$x)
## [1] 0.8981994

Conclusion

Hypothesis testing helps us make decisions using data.

  • Start with hypotheses
  • Calculate a test statistic
  • Compare to a critical value or p-value
  • Make a conclusion