Introduction to Hypothesis Testing

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

Key Components:

  • Null Hypothesis (\(H_0\)): The default assumption
  • Alternative Hypothesis (\(H_a\)): What we want to prove
  • Test Statistic: Calculated from sample data
  • P-value: Probability of observing results as extreme as the data
  • Significance Level (\(\alpha\)): Threshold for decision making (commonly 0.05)

Mathematical Foundation

The test statistic for a one-sample t-test is calculated as: \[t = \frac{\bar{x} - \mu_0}{s/\sqrt{n}}\] where: - \(\bar{x}\) is the sample mean - \(\mu_0\) is the hypothesized population mean - \(s\) is the sample standard deviation - \(n\) is the sample size The p-value is then calculated as:

\[p\text{-value} = P(T \geq |t_{obs}|)\], where \(T\) follows a t-distribution with \(n-1\) degrees of freedom.

Example: Testing Coffee Shop Claims

Scenario: A coffee shop claims their average serving temperature is 165°F. We collect 30 temperature measurements to test this claim.

Hypotheses:

  • \(H_0: \mu = 165°F\)
  • \(H_a: \mu \neq 165°F\)

Significance level: \(\alpha = 0.05\)

Data Generation and Visualization

# Generate sample data
set.seed(123)
temps <- rnorm(30, mean = 162, sd = 5)

# Perform t-test
test_result <- t.test(temps, mu = 165)
print(test_result)
## 
##  One Sample t-test
## 
## data:  temps
## t = -3.6129, df = 29, p-value = 0.001132
## alternative hypothesis: true mean is not equal to 165
## 95 percent confidence interval:
##  159.9329 163.5961
## sample estimates:
## mean of x 
##  161.7645

Distribution of Sample Data

T-Distribution and Critical Regions

Interactive 3D Visualization: Power Analysis

Results Interpretation

Based on our coffee temperature example:

  • Test Statistic: t = -3.613
  • P-value: 0.0011
  • Sample Mean: 161.76°F
  • 95% Confidence Interval: [159.93, 163.6]

Decision: Since p-value < 0.05, we reject the null hypothesis.

Conclusion: There is sufficient evidence to conclude that the average coffee temperature differs from 165°F.

Types of Errors in Hypothesis Testing

Conclusion and Key Takeaways

Important Points:

  1. Hypothesis testing provides a framework for making decisions under uncertainty
  2. The p-value measures the strength of evidence against \(H_0\)
  3. A small p-value (< α) suggests the null hypothesis is unlikely
  4. Always consider both statistical significance and practical significance
  5. Type I error: False positive (rejecting true \(H_0\))
  6. Type II error: False negative (failing to reject false \(H_0\))

Applications: Quality control, medical research, A/B testing, social sciences, and many more fields rely on hypothesis testing for data-driven decisions.