Logistic regression and mediation
Predict a yes/no outcome with odds ratios, then test whether social support affects performance indirectly through stress.
Two common thesis questions go beyond ordinary regression. The first has a yes/no outcome: did the student pass? The second asks about a mechanism: does social support help students because it reduces stress? This lesson covers binary logistic regression and simple mediation.
Binary logistic regression
Linear regression is the wrong tool for a binary outcome: it can predict probabilities below 0 or above 1, and its assumptions fail. Logistic regression models the log-odds of the event instead, and the results are reported as odds ratios.
Predict who passes the final exam
- Outcome Passed, event “Yes”; predictors StudyHours and Stress.
- χ²(2) = 22.75, p < .001, Nagelkerke R² = .138.
- Read the odds ratios: 1.08 for StudyHours and 0.51 for Stress.
Here 184 of 239 students passed (77%). The model with study hours and stress predicts passing better than a model without predictors, χ²(2) = 22.75, p < .001. Nagelkerke R² = .138 is a pseudo-R², roughly comparable to an ordinary R², although pseudo-R² values tend to be lower. The Hosmer-Lemeshow test (p = .861) shows no evidence of poor fit.
| Predictor | B | SE | Wald | p | OR | 95% CI for OR |
|---|---|---|---|---|---|---|
| StudyHours | 0.080 | 0.027 | 8.61 | .003 | 1.08 | [1.03, 1.14] |
| Stress | −0.679 | 0.197 | 11.84 | < .001 | 0.51 | [0.35, 0.75] |
An odds ratio above 1 raises the odds of the event, below 1 lowers them. Each extra weekly study hour multiplies the odds of passing by 1.08 (an 8% increase), so ten extra hours multiply them by 1.0810 ≈ 2.2. Each one-point increase in stress multiplies the odds by 0.51, roughly halving them. The confidence intervals exclude 1, so both effects are significant.
Do not over-read the classification table
The model classifies 78.7% of students correctly, which sounds good until you notice that predicting “pass” for everyone would already be right 77% of the time. The table shows that only 6 of the 55 students who failed are correctly identified (10.9%). The model is useful for understanding which factors matter, but it would be a poor early-warning tool. When the outcome is unbalanced, look at the classification of each group, not just the overall percentage, and consider the ROC curve tool for the area under the curve.
Mediation: how does support work?
In Lesson 9, social support did not predict exam scores directly (r = .09). Does that mean support is irrelevant? Not necessarily. A mediation model tests whether X affects Y indirectly through a mediator M: support (X) lowers stress (M), and lower stress raises exam scores (Y).
Test whether stress mediates the effect of support
- PROCESS model 4: X = Support, M = Stress, Y = Final, 5,000 bootstrap samples.
- Path a = −0.37, path b = −5.38, indirect effect ≈ 2.0 with a bootstrap CI that excludes zero.
- Your CI limits may differ slightly in the second decimal, because the bootstrap draws random samples.
The model has three parts:
- Path a (X → M): students with more support report less stress, a = −0.37, p < .001.
- Path b (M → Y, controlling for X): more stress goes with lower final scores, b = −5.38, p < .001.
- Indirect effect a × b = 2.01: one point more support predicts about 2 more exam points through lower stress. The 95% bootstrap confidence interval (about [1.06, 3.22]) excludes zero, so the indirect effect is significant.
The direct effect of support, controlling for stress, is −0.36 (p = .767), and the total effect is 1.65 (p = .171). Neither is significant. This pattern is called indirect-only mediation: support has no detectable effect overall, yet it has a significant effect through stress. Older approaches (Baron and Kenny’s steps) required a significant total effect before testing mediation and would have stopped here, missing the finding. Modern practice, following Hayes (2018) and Zhao, Lynch and Chen (2010), tests the indirect effect directly with bootstrapping.
Why bootstrapping?
The product a × b does not follow a normal distribution, so the Sobel z-test is inaccurate. Bootstrapping resamples the data thousands of times (5,000 here), estimates the indirect effect in each resample and uses the middle 95% of the estimates as the confidence interval. Because the resamples are random, your interval limits may differ slightly from the ones above; that is expected. Report the number of bootstrap samples.
A causal caution
Mediation is a causal claim: X causes M, which causes Y. With cross-sectional survey data, the statistics are consistent with that story but cannot prove it; the order could even be reversed (poor exam performance raising stress, for instance). Justify the order with theory and, ideally, with a design in which X is measured before M and M before Y.
Writing it up
A binary logistic regression showed that study hours and stress predicted passing the final exam, χ²(2) = 22.75, p < .001, Nagelkerke R² = .14. Each additional weekly study hour increased the odds of passing (OR = 1.08, 95% CI [1.03, 1.14]), and each one-point increase in stress reduced them (OR = 0.51, 95% CI [0.35, 0.75]). A simple mediation analysis (PROCESS Model 4, 5,000 bootstrap samples) showed that social support had a significant indirect effect on final exam scores through stress, ab = 2.01, 95% CI [1.06, 3.22], while the direct effect was not significant, c′ = −0.36, p = .767, indicating indirect-only mediation.
Key takeaways
- Use logistic regression for binary outcomes and report odds ratios with 95% CIs.
- Judge classification accuracy against the base rate and look at each outcome group.
- Test mediation with a bootstrapped indirect effect; a significant total effect is not required.
- Mediation with cross-sectional data needs a strong theoretical justification for the causal order.
Check your understanding
Answer each question to see the explanation. Finishing the quiz marks this lesson as complete.