2025-11-09

What is Hypothesis Testing?

  • A statistical method for making decisions about a population using sample data.
  • We start with a null hypothesis \(H_0\) and an alternative hypothesis \(H_a\).

\[ H_0: \text{no difference between groups} \]

\[ H_a: \text{a difference exists between groups} \]

The t-Test Formula (Math Slide)

\[ t = \frac{\bar{x}_1 - \bar{x}_2}{s_p \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}} \]

where

\[ s_p = \sqrt{\frac{(n_1-1)s_1^2 + (n_2-1)s_2^2}{n_1 + n_2 - 2}} \]

Example: Are Manual Cars More Fuel Efficient?

Dataset: mtcars

  • mpg = miles per gallon
  • am = transmission (0 = automatic, 1 = manual)

We’ll test:

\[ H_0: \mu_{manual} = \mu_{auto} \]

\[ H_a: \mu_{manual} > \mu_{auto} \]

Exploring the Data (ggplot 1)

MPG Comparison (ggplot 2)

Running the t-Test (R Code Slide)

## 
##  Welch Two Sample t-test
## 
## data:  mpg by am
## t = -3.7671, df = 18.332, p-value = 0.9993
## alternative hypothesis: true difference in means between group Automatic and group Manual is greater than 0
## 95 percent confidence interval:
##  -10.57662       Inf
## sample estimates:
## mean in group Automatic    mean in group Manual 
##                17.14737                24.39231

Interactive Visualization (Plotly)

Results and Interpretation

## [1] 0.0006868192

Summary

  • We performed a one-sided t-test using real data from R’s built-in mtcars dataset.
  • Calculated the t-statistic and p-value in R.
  • Visualized the data with ggplot2 and Plotly.
  • Found strong evidence that manual transmission cars get better gas mileage than automatic cars.
  • This example demonstrates how hypothesis testing helps us make data-driven conclusions.