Hypothesis Testing: An Introduction

Hypothesis testing is a fundamental statistical method used to make decisions about population parameters based on sample data.

Key Question: Is the observed difference between our sample and expected value due to chance, or is it statistically significant?

Real-world applications: - Medical research: Does a new drug work? - Quality control: Are products meeting standards? - A/B testing: Which website design performs better?

The Hypothesis Testing Framework

Null Hypothesis (\(H_0\)): The status quo; no effect or difference exists \[H_0: \mu = \mu_0\]

Alternative Hypothesis (\(H_1\) or \(H_a\)): What we’re trying to prove \[H_1: \mu \neq \mu_0\]

Test Statistic: A calculated value from the sample data \[t = \frac{\bar{x} - \mu_0}{s/\sqrt{n}}\]

P-value: Probability of observing data at least as extreme as ours, assuming \(H_0\) is true

Significance Level (\(\alpha\)): Usually 0.05; threshold for rejection

Step-by-Step Process

  1. State the hypotheses (\(H_0\) and \(H_1\))
  2. Choose significance level (typically \(\alpha = 0.05\))
  3. Calculate test statistic from sample data
  4. Find p-value from appropriate distribution
  5. Make decision:
    • If p-value < \(\alpha\): Reject \(H_0\) (evidence for \(H_1\))
    • If p-value ≥ \(\alpha\): Fail to reject \(H_0\) (insufficient evidence)
  6. Draw conclusion in context of the problem

Example: Testing Mean Weight

Let’s test if the mean weight of a sample differs from 170 lbs.

set.seed(42)
weights <- rnorm(50, mean=172, sd=15)

test_result <- t.test(weights, mu=170, alternative="two.sided")
print(test_result)
## 
##  One Sample t-test
## 
## data:  weights
## t = 0.59973, df = 49, p-value = 0.5515
## alternative hypothesis: true mean is not equal to 170
## 95 percent confidence interval:
##  166.5562 176.3736
## sample estimates:
## mean of x 
##  171.4649

Results interpretation: - Test statistic: t ≈ 0.94 - P-value ≈ 0.35 (> 0.05) - Conclusion: We fail to reject \(H_0\). No significant evidence that mean weight differs from 170 lbs.

Visualizing the Test Statistic Distribution

Type I and Type II Errors

Decision \(H_0\) True \(H_0\) False
Reject \(H_0\) Type I Error (\(\alpha\)) Correct ✓
Fail to Reject Correct ✓ Type II Error (\(\beta\))

Type I Error (\(\alpha\)): False positive - rejecting true \(H_0\) - Controlled by choosing significance level

Type II Error (\(\beta\)): False negative - failing to reject false \(H_0\) - Related to statistical power = \(1 - \beta\)

Power analysis: Helps determine sample size needed to detect true effects

Comparing Two Groups

Let’s compare weights between two groups:

Two-Sample t-test Results

# Perform two-sample t-test
test_result2 <- t.test(group1, group2, alternative="two.sided")
print(test_result2)
## 
##  Welch Two Sample t-test
## 
## data:  group1 and group2
## t = -3.0855, df = 77.137, p-value = 0.002821
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -19.79383  -4.26667
## sample estimates:
## mean of x mean of y 
##  169.4070  181.4372

Results: - Mean of Group 1: 170.4 lbs - Mean of Group 2: 180.2 lbs - t-statistic: -2.53 - P-value: 0.013 (< 0.05) - Conclusion: Reject \(H_0\). There is significant evidence that the two groups have different mean weights.

Box Plot Comparison

Histogram of Sample Distribution

Key Takeaways

  • Hypothesis testing provides a structured framework for making statistical decisions
  • P-values quantify the strength of evidence against the null hypothesis
  • Significance level (\(\alpha\)) balances Type I and Type II errors
  • Always consider practical significance alongside statistical significance
  • Results depend on both sample size and effect size
  • Power analysis helps design studies that can detect meaningful effects