- Goal: predict the probability a car has a manual transmission using logistic regression.
- Dataset:
mtcars, augmented with labels to mimic fleet planning. - Audience: a car‑sharing startup choosing models balancing performance and economy.
mtcars, augmented with labels to mimic fleet planning.| model | mpg | wt | hp | transmission | efficient |
|---|---|---|---|---|---|
| Mazda RX4 | 21.0 | 2.620 | 110 | Manual | Inefficient |
| Mazda RX4 Wag | 21.0 | 2.875 | 110 | Manual | Inefficient |
| Datsun 710 | 22.8 | 2.320 | 93 | Manual | Efficient |
| Hornet 4 Drive | 21.4 | 3.215 | 110 | Automatic | Inefficient |
| Hornet Sportabout | 18.7 | 3.440 | 175 | Automatic | Inefficient |
| Valiant | 18.1 | 3.460 | 105 | Automatic | Inefficient |
We model \(p_i = \Pr(\text{Manual}_i = 1)\) with a logit link:
\[ \text{logit}(p_i) = \log\!\left(\frac{p_i}{1-p_i}\right) = \beta_0 + \beta_1\,\text{wt}_i + \beta_2\,\text{hp}_i . \]
Interpretation at the margin:
glm_fit <- glm(am ~ wt + hp, data = mtcars, family = binomial()) summary(glm_fit)$coefficients
## Estimate Std. Error z value Pr(>|z|) ## (Intercept) 18.8662987 7.44355806 2.534581 0.011258199 ## wt -8.0834752 3.06867511 -2.634191 0.008433813 ## hp 0.0362556 0.01773415 2.044394 0.040914646
| Term | Estimate | Odds Ratio | Std. Error | Z | p-value |
|---|---|---|---|---|---|
| (Intercept) | 18.866 | 1.561455e+08 | 7.444 | 2.535 | 0.011 |
| wt | -8.083 | 0.000000e+00 | 3.069 | -2.634 | 0.008 |
| hp | 0.036 | 1.037000e+00 | 0.018 | 2.044 | 0.041 |