Hypothesis Testing with Two Samples
Background: Two-Sample t-Tests
Two-sample t-tests compare population means using two independent or paired samples.
- Independent t-test: Compares means of two unrelated groups (e.g., measurements from two sites).
- Assumptions:
- Independence between groups
- Normality (or large sample size for CLT)
- Homogeneity of variances not required (default in R uses Welch’s correction).
- Independence between groups
- Test Statistic:
\[ t = \frac{\bar{x}_1 - \bar{x}_2}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}} \]
Degrees of freedom approximated via Welch-Satterthwaite equation.
- Assumptions:
- Paired t-test: Compares means of two related groups (e.g., pre/post measurements).
- Assumptions:
- Paired observations
- Differences approximately normal
- Paired observations
- Test Statistic:
\[ t = \frac{\bar{d}}{s_d / \sqrt{n}} \]
where \(\bar{d}\) = mean difference, \(s_d\) = standard deviation of differences.
- Assumptions:
Example 1: Independent t-Test
Using the built‐in mtcars
dataset to compare miles per gallon between automatic (0) and manual (1) transmissions.
Example 2: Paired t-Test
Use the built‐in sleep
dataset to compare extra sleep under two drug treatments.