2025-11-16

What is Hypothesis Testing?

Hypothesis testing is a statistical framework used to evaluate a claim about a population using data from a sample. We form two contradictory hypotheses and use probability to make a decision based on evidence rather than proof.

  • H₀: No effect / no difference
  • H₁: There is an effect / difference

The result is determined using a test statistic and p-value.

Mathematical Formulation

\[ H_0: \mu = \mu_0 \]

\[ H_1: \mu \neq \mu_0 \]

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

The resulting t-value is compared against a t-distribution to calculate a p-value.

Practical Example

A company claims the mean sugar content in a snack bar is 10g. A random sample of 20 items gives:

  • Mean = 11.2g
  • Standard deviation = 3.1g

At significance level α = 0.05, test if the claim holds.

\[ H_0: \mu = 10 \]

\[ H_1: \mu \neq 10 \]

R Code (Manual t-Test Computation)

x_bar     <- 11.2
mu_null   <- 10
sd_sample <- 3.1
n_sample  <- 20

t_statistic <- (x_bar - mu_null) / (sd_sample / sqrt(n_sample))
p_value <- 2 * (1 - pt(abs(t_statistic), df = n_sample - 1))

t_statistic
## [1] 1.731149
p_value
## [1] 0.09963233

Simulating Sample Means Under H₀

t-Distribution Visualization

plotly 3D Exploration: t-Statistic vs Mean & SD

Conclusion

  • Hypothesis testing allows statistical decision-making using sample evidence.
  • The computed t-value and p-value determine if the claim differs significantly.
  • Simulation and visualization help build intuitive understanding of sampling behavior.

Final decision rule:

Reject \(H_0\) if p-value < 0.05, otherwise fail to reject \(H_0\).