2025-06-10

Presentation Overview

  • Why we test hypotheses
  • The 5-step logic of a hypothesis test
  • What a p-value really means
  • PlantGrowth data example
  • Visualizations with ggplot2 & Plotly
  • R code example
  • Interpreting our results and next steps

Why Hypothesis Testing?

Every dataset has noise. Hypothesis testing gives us a consistent rule to decide if an observed effect is real or just chance.

  • The test assumes “no effect” by default (null hypothesis)
  • Quantifies how surprising our data is
  • Provides a clear cutoff (α) for decision-making

Formulating Hypotheses

Null hypothesis (H₀): \[ H_0: \mu_{\text{ctrl}} = \mu_{\text{trt1}} \] Alternative hypothesis (Hₐ): \[ H_a: \mu_{\text{ctrl}} \neq \mu_{\text{trt1}} \]

The 5-Step Testing Process

  1. State H₀ and Hₐ
  2. Pick a test statistic (e.g., t)
  3. Compute the statistic from your sample
  4. Refer to its distribution under H₀
  5. Decide: reject H₀ if p-value ≤ α

Test Statistic

For a two-sample t-test: \[ t = \frac{\bar{x}_1 - \bar{x}_2}{s_p \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}}, \quad s_p = \sqrt{\frac{(n_1 - 1)s_1^2 + (n_2 - 1)s_2^2}{n_1 + n_2 - 2}}. \]

What Is a p-Value?

A p-value is the probability of obtaining a test statistic at least as extreme as the one observed, assuming the null hypothesis is true.

  • Small p (≤ .05) → data unlikely under H₀ → reject H₀
  • Large p (> .05) → data plausible under H₀ → fail to reject H₀
  • Note: p-values do not tell you the probability that H₀ is true

PlantGrowth Example

The data contains 10 plants in “ctrl” vs. 10 plants in “trt1”
Question: Does Treatment 1 change plant weight?
- H₀: μ(ctrl) = μ(trt1)
- Hₐ: μ(ctrl) ≠ μ(trt1)

Boxplot Weight by Group

The boxplot shows a small shift. But is it statistically significant?

Histogram of Weights Distribution

The histograms show the spread of the data.

Reference t-Distribution

This interactive curve is our null distribution.

Running the Two-Sample t-Test

Here’s the R command to perform a Welch two-sample t-test (R’s default):

t.test(weight ~ group, data = pg2)

Interpreting Our Results

  • t = 1.19, p = 0.25 → p > 0.05 → fail to reject H₀
  • 25% chance of this difference if H₀ true
  • Effect size (Cohen’s d ≈ 0.29) is small
  • Conclusion: No strong evidence that trt1 changes weight

Next Steps & Takeaways

  • Check assumptions: normality, independence, equal variances
  • Increase power: larger n or paired design
  • Report effect sizes alongside p-values
    Hypothesis testing is a tool. It should always be paired with visuals & context

Thank You!