BM21 Business Analytics · Module 6
Logistic regression, overfitting and validation
Erasmus RSM
Logit (formula sheet)
- odds = p/(1 - p); log-odds z = ln(p/(1 - p)) = b0 + b1 x1 + ...
- p = 1/(1 + exp(-z)); odds ratio = exp(b)
- b = change in log-odds, not in percentage points. More units: exp(n b)
R
glm(y ~ x1 + x2, family = binomial, data = d)predict(fit, newdata, type = "response")gives probabilities; without type log-oddsexp(coef(fit)),exp(confint.default(fit)): odds ratios with Wald intervaltable(Predicted, Observed): confusion matrix.anova(m1, m2, test = "Chisq"): nested models
Reading output (Accepteert, n = 500)
- Inkomen 0.0432 (z = 4.52), Koophuis 1.0102 (z = 4.37), Leeftijd -0.0141 (p = 0.06: not significant)
- exp(b): Koophuis 2.746 [1.746; 4.320] = 2.75 times the odds, not the probability; Inkomen 10 units: exp(0.432) = 1.54; 1 = no effect
- z = -2.1147 gives p = 0.1077. Without type = "response" you get log-odds
- Null deviance 577.20, residual deviance 527.77, AIC 535.77 (lower is better)
- McFadden pseudo-R² = 1 - ln L(model)/ln L(null) = 0.0856: not explained variance
Confusion matrix (threshold τ)
| Actual 0 | Actual 1 | |
|---|---|---|
| Predicted 0 | TN | FN |
| Predicted 1 | FP | TP |
Mind the order. R (table) puts 0 first; practice exam 7.1 puts 1 first. Read the headers first.
- accuracy = (TP + TN)/n; sensitivity = TP/(TP + FN); specificity = TN/(TN + FP); precision = TP/(TP + FP)
- Cutoff 0.5: TN 356, FN 115, FP 12, TP 17: accuracy 0.746, sensitivity 0.129, specificity 0.967, precision 0.586
- Cutoff 0.3: sensitivity 0.576, specificity 0.715. Lower threshold: sensitivity up, specificity down
- Baseline "always no" = 0.736: accuracy 0.746 is barely better
- ROC curve and AUC: 0.5 is guessing, 1 is perfect. Train 0.689, test 0.714
Decision rules
- Skewed classes: accuracy against the baseline, look at sensitivity and precision
- High cost of a missed case: lower threshold; 0.5 is a habit
- Overfitting = gap between train and test (0.729 against 0.793: no overfitting). Too few predictors = underfitting
- Judge on a test set or with cross-validation. More flexible model: less bias, more variance
Pitfalls
- p = 0.06 is not a 6% chance of H0. Not significant = no evidence, not "no effect"
- e^0.8 = 2.2: 2.2 times the odds, not 80% more probability
- Largest coefficient is not the strongest predictor
Question 7.1 (9 p, 200 words)
- Coefficients: sign, significance, odds ratio, ceteris paribus
- Calculation with formula and numbers
- Why accuracy misleads
Key terms (never translate)
logistic regressionbinary dependent variablelogitprobitlog-oddsoddsodds ratiomaximum likelihoodlog-likelihooddevianceAICMcFadden pseudo-R²confusion matrixaccuracysensitivityspecificityprecisionthresholdROC-curveAUCoverfittingtraining settest setcross-validationbias-variance trade-offlink functionlikelihood functionnull modelsaturated modelmarginal effectclassificationtrue positivefalse positivetrue negativefalse negativefalse positive rategeneralizationin-samplelearning curveirreducible errormultinomial logitordinal logitconditional logitnested logitglm