Using the mtcars Dataset
Conducting a significance test can allow us to understand if changes between results or data are actually worth noting or significant or if they are present due to chance.
2025-10-19
mtcars DatasetConducting a significance test can allow us to understand if changes between results or data are actually worth noting or significant or if they are present due to chance.
mtcars datasetOur hypothesis tests whether manual cars have higher mean miles per gallon (mpg) than automatic car
\[ H_0: \mu_{manual} = \mu_{automatic} \\ H_a: \mu_{manual} \neq \mu_{automatic} \]
We will use a two-sample t-test at a significance level of \(= 0.05\), meaning if it is less than the level, the decision will be rejected.
| mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | carb | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Mazda RX4 | 21.0 | 6 | 160 | 110 | 3.90 | 2.620 | 16.46 | 0 | Manual | 4 | 4 |
| Mazda RX4 Wag | 21.0 | 6 | 160 | 110 | 3.90 | 2.875 | 17.02 | 0 | Manual | 4 | 4 |
| Datsun 710 | 22.8 | 4 | 108 | 93 | 3.85 | 2.320 | 18.61 | 1 | Manual | 4 | 1 |
| Hornet 4 Drive | 21.4 | 6 | 258 | 110 | 3.08 | 3.215 | 19.44 | 1 | Automatic | 3 | 1 |
| Hornet Sportabout | 18.7 | 8 | 360 | 175 | 3.15 | 3.440 | 17.02 | 0 | Automatic | 3 | 2 |
| Valiant | 18.1 | 6 | 225 | 105 | 2.76 | 3.460 | 20.22 | 1 | Automatic | 3 | 1 |
# Perform the 2 sample t-test and display the results t_test_result <- t.test(mpg ~ am, data = mtcars) print(t_test_result)
## ## Welch Two Sample t-test ## ## data: mpg by am ## t = -3.7671, df = 18.332, p-value = 0.001374 ## alternative hypothesis: true difference in means between group Automatic and group Manual is not equal to 0 ## 95 percent confidence interval: ## -11.280194 -3.209684 ## sample estimates: ## mean in group Automatic mean in group Manual ## 17.14737 24.39231
As decided earlier, if the p-value < 0.05, we reject the null hypothesis.
Otherwise, we fail to reject it.
From our test:
\[ \text{Decision: Reject } H_0 \text{ if } p < 0.05 \]
Application where Significance Testing is Used: