Tutorials › Exam SRM - Statistics for Risk Modeling › Interpreting Interactions in Logistic Regression

Exam SRM · GLM Modeling Cases · Tutorial 866 of 926

Interpreting Interactions in Logistic Regression

Use logistic interaction terms to calculate group-specific effects and interpret coefficients without confusing conditional contrasts with overall effects.

Advanced 10 min read

What You'll Learn

  • Write a logistic model with a predictor-by-group interaction
  • Calculate the predictor slope and odds ratio separately for each group
  • Interpret a group contrast at a specified predictor value
  • Explain why a main-effect coefficient depends on the reference group and predictor origin
  • Detect common errors when interpreting interaction coefficients

Why Logistic Effects Can Differ by Group

A logistic regression model without an interaction assigns the same change in log odds to a one-unit increase in a predictor for every group. That may be too restrictive. For example, a hypothetical insurer might study whether the association between the number of risk inspections and claim occurrence differs between two policy types. An interaction allows the predictor’s association with the outcome to vary by policy type.

The key is to interpret the terms together. With an interaction in the model, the coefficient of the predictor alone describes its slope for the reference group, not a universal slope. The interaction coefficient measures how much the slope changes in the other group.

Definition: For a binary outcome \(Y\), let \(p=P(Y=1\mid x,g)\), where \(x\) is a numerical predictor and \(g\) is a group indicator coded 0 for the reference group and 1 for the comparison group. A logistic regression with a predictor-by-group interaction is $$ \operatorname{logit}(p)=\log\left(\frac{p}{1-p}\right)=\beta_0+\beta_1x+\beta_2g+\beta_3xg. $$ The coefficient \(\beta_3\) is the change in the predictor slope when moving from the reference group to the comparison group.

This model describes the conditional probability of the event \(Y=1\). In the usual individual-outcome formulation, observations are conditionally independent and \(Y\mid x,g\) has a Bernoulli distribution with probability \(p\). The model does not assert that the event is caused by \(x\), nor does it guarantee that the linear predictor is an adequate description of the data.

Slopes and Odds Ratios by Group

Set \(g=0\) to obtain the reference-group model. The interaction term becomes zero, leaving \(\beta_0+\beta_1x\), so its slope with respect to \(x\) is \(\beta_1\). Setting \(g=1\) gives \((\beta_0+\beta_2)+(\beta_1+\beta_3)x\), so the comparison group’s slope is \(\beta_1+\beta_3\).

In logistic regression, a one-unit increase in \(x\), holding the group fixed, multiplies the odds by the exponential of the relevant slope. Thus, the two group-specific odds ratios are \(\exp(\beta_1)\) and \(\exp(\beta_1+\beta_3)\). These are odds multipliers, not fixed probability changes.

$$ \begin{aligned} g=0:\quad &\operatorname{logit}(p)=\beta_0+\beta_1x, &\text{slope in }x&=\beta_1, &\text{one-unit odds ratio}&=\exp(\beta_1),\\ g=1:\quad &\operatorname{logit}(p)=(\beta_0+\beta_2)+(\beta_1+\beta_3)x, &\text{slope in }x&=\beta_1+\beta_3, &\text{one-unit odds ratio}&=\exp(\beta_1+\beta_3). \end{aligned} $$

The group contrast also depends on \(x\). At a fixed value of \(x\), the comparison-group log odds minus the reference-group log odds is \(\beta_2+\beta_3x\). Therefore, the comparison-group odds divided by the reference-group odds at that value of \(x\) is \(\exp(\beta_2+\beta_3x)\). In particular, \(\beta_2\) alone is the group log-odds contrast only at \(x=0\).

Why the odds-ratio formulas hold: The odds corresponding to a probability with logit \(\eta\) are \(\exp(\eta)\), since \(\log(p/(1-p))=\eta\) implies \(p/(1-p)=\exp(\eta)\). For a one-unit increase in \(x\) within a fixed group, the linear predictor changes by that group’s slope \(s\). The odds ratio is therefore \(\exp(\eta+s)/\exp(\eta)=\exp(s)\). Substituting \(s=\beta_1\) for \(g=0\), or \(s=\beta_1+\beta_3\) for \(g=1\), gives the stated formulas. Likewise, subtracting the reference-group linear predictor from the comparison-group linear predictor at fixed \(x\) gives \(\beta_2+\beta_3x\), whose exponential is the group odds ratio.

Worked Interpretations

Worked Example: Different Inspection Associations by Policy Type

Method and setup. Consider a hypothetical study of whether a policy has at least one claim in a year. Let \(Y=1\) denote at least one claim, \(x\) be the number of inspections, and \(g=1\) identify Type B policies; Type A is the reference group (\(g=0\)). Assume conditionally independent Bernoulli outcomes with probability \(p=P(Y=1\mid x,g)\), modeled by \(\operatorname{logit}(p)=-2+0.5x+0.7g-0.2xg\). No interest rate or mortality assumption applies: the modeled outcome is claim occurrence, not a financial accumulation or survival outcome. Find each group’s one-inspection odds ratio, each group’s odds multiplier for two additional inspections, and the Type B-to-Type A odds ratio at \(x=4\).

Reference group, Type A. With \(g=0\), the slope is \(\beta_1=0.5\). One additional inspection multiplies the odds by \(\exp(0.5)=1.6487\), to four decimals. Two additional inspections change the linear predictor by \(2(0.5)=1.0\), so the odds multiplier is \(\exp(1.0)=2.7183\).

Comparison group, Type B. Its slope is \(\beta_1+\beta_3=0.5-0.2=0.3\). One additional inspection multiplies the odds by \(\exp(0.3)=1.3499\). For two additional inspections, the change in the linear predictor is \(2(0.3)=0.6\), giving an odds multiplier of \(\exp(0.6)=1.8221\).

Group contrast at four inspections. The Type B minus Type A log-odds contrast is \(\beta_2+\beta_3x=0.7-0.2(4)=0.7-0.8=-0.1\). The corresponding odds ratio is \(\exp(-0.1)=0.9048\). At four inspections, the modeled Type B odds are about 0.9048 times the Type A odds.

Check. The Type B slope is smaller than the Type A slope by \(0.2\), exactly the interaction coefficient. The group contrast at \(x=4\) is not just \(0.7\), because the interaction contributes \(-0.2(4)\). The common mistake avoided here is using either coefficient alone when the relevant effect is a sum of coefficients.

Worked Example: A Group Effect That Changes Across the Predictor

Method and setup. In a hypothetical model, \(Y=1\) indicates that a submitted claim requires additional review. Let \(x\) be the number of documents received, and let \(g=1\) identify claims from Channel B, with Channel A as the reference group. Assume conditionally independent Bernoulli outcomes and \(\operatorname{logit}(p)=-1.2-0.4x-0.3g+0.6xg\). No interest rate or mortality assumption is relevant to this binary-outcome model. Find each channel’s one-document odds ratio, the Channel B-to-A odds ratio at \(x=0\) and \(x=2\), and the modeled probabilities at \(x=2\).

Channel A slope and odds ratio. With \(g=0\), the slope is \(-0.4\). The one-document odds ratio is \(\exp(-0.4)=0.6703\). Thus, for Channel A, one more document is associated with odds multiplied by 0.6703, according to this fitted model.

Channel B slope and odds ratio. Its slope is \(-0.4+0.6=0.2\). Its one-document odds ratio is \(\exp(0.2)=1.2214\). The positive interaction reverses the direction of the fitted slope relative to Channel A.

Group contrasts. At \(x=0\), the Channel B minus Channel A log-odds contrast is \(-0.3+0.6(0)=-0.3\), so the odds ratio is \(\exp(-0.3)=0.7408\). At \(x=2\), the contrast is \(-0.3+0.6(2)=-0.3+1.2=0.9\), so the odds ratio is \(\exp(0.9)=2.4596\).

Probabilities at \(x=2\). For Channel A, the linear predictor is \(-1.2-0.4(2)=-2.0\). Therefore \(p=1/(1+\exp(2))=0.1192\), to four decimals. For Channel B, the linear predictor is \(-1.2-0.4(2)-0.3+0.6(2)=-1.1\). Therefore \(p=1/(1+\exp(1.1))=0.2497\), to four decimals.

Check. The ratio of the two groups’ odds at \(x=2\) is \(\exp(0.9)=2.4596\), consistent with the difference between their linear predictors, \(-1.1-(-2.0)=0.9\). The common mistake avoided is treating \(\beta_2=-0.3\) as the group contrast at every document count; that coefficient gives the contrast only at \(x=0\).

Worked Example: Three Groups With Different Slopes

Method and setup. Suppose a hypothetical model predicts whether a small commercial building has a specified maintenance event during a year. Let \(x\) be years since the last major inspection. Group A is the reference category; \(G_1=1\) identifies Group B and \(G_2=1\) identifies Group C. Each building belongs to exactly one group, so the two indicators are never both 1. Assume conditionally independent Bernoulli outcomes and \(\operatorname{logit}(p)=-1+0.2x-0.5G_1+0.4G_2+0.3xG_1-0.6xG_2\). There is no interest-rate or mortality assumption in this event-probability model. Find the slope and one-year odds ratio for each group, and compare each non-reference group’s odds with Group A at \(x=2\).

Group A. Both indicators are zero, so the slope is \(0.2\), and the one-year odds ratio is \(\exp(0.2)=1.2214\).

Group B. Set \(G_1=1,G_2=0\). The slope is \(0.2+0.3=0.5\), and the one-year odds ratio is \(\exp(0.5)=1.6487\).

Group C. Set \(G_1=0,G_2=1\). The slope is \(0.2-0.6=-0.4\), and the one-year odds ratio is \(\exp(-0.4)=0.6703\).

Group comparisons at \(x=2\). Group B’s log-odds contrast with Group A is \(-0.5+0.3(2)=-0.5+0.6=0.1\), so its odds ratio is \(\exp(0.1)=1.1052\). Group C’s contrast with Group A is \(0.4-0.6(2)=0.4-1.2=-0.8\), so its odds ratio is \(\exp(-0.8)=0.4493\).

Check. Group B has a steeper slope than A, while Group C has a negative slope; these group-specific slopes agree with their respective interaction terms. The comparison-group coefficients \(-0.5\) and \(0.4\) alone are the group contrasts only at \(x=0\). The common mistake avoided is adding an interaction coefficient to a group intercept instead of to the predictor slope.

Reference Values, Coding, and Interpretation

A main-effect coefficient is conditional on the values used as references for the other variables in the model. In the binary-group model, \(\beta_1\) is the slope for the group coded 0, and \(\beta_2\) is the group contrast when \(x=0\). If zero is far outside the useful range of \(x\), the latter contrast may be mathematically correct but practically unhelpful.

Centering \(x\) can make the group main effect easier to interpret. If \(x_c=x-c\), then \(x=0\) corresponds to \(x_c=-c\), while \(x_c=0\) corresponds to the original value \(x=c\). In the centered model, the group main-effect coefficient describes the group contrast at original predictor value \(c\). Centering does not change the fitted probabilities or group-specific slopes; it changes which predictor value the group main effect refers to.

Changing the group reference category also changes coefficient values. For a two-group model, using the former comparison group as the reference makes its slope the new predictor main effect, and reverses the sign of the interaction coefficient. The underlying group-specific slopes and fitted contrasts remain the same when the model is re-expressed consistently.

QuantityInterpretation in the binary-group modelCondition
\(\beta_1\)Predictor slope for the reference group\(g=0\)
\(\beta_1+\beta_3\)Predictor slope for the comparison group\(g=1\)
\(\beta_2\)Comparison-group minus reference-group log odds\(x=0\)
\(\beta_2+\beta_3x\)Comparison-group minus reference-group log oddsAt the stated \(x\)
\(\beta_3\)Difference between group-specific predictor slopesSame units of \(x\) in both groups

Common Exam Traps

An interaction coefficient is a difference in log-odds slopes, not itself a group-specific odds ratio. To obtain the comparison-group slope, add the interaction coefficient to the predictor main effect, then exponentiate the sum if an odds ratio is requested.

For example, with \(\beta_1=0.4\) and \(\beta_3=-0.1\), a common incorrect calculation is to report the comparison group’s one-unit odds ratio as \(\exp(-0.1)=0.9048\). That exponentiates the slope difference, not the comparison-group slope. The correct slope is \(0.4-0.1=0.3\), so the comparison-group odds ratio is \(\exp(0.3)=1.3499\). The interaction coefficient by itself implies that the comparison group’s odds ratio is multiplied by \(\exp(-0.1)\) relative to the reference group’s odds ratio.

Also distinguish odds ratios from probability differences. Even when a group-specific odds ratio is constant across \(x\) for a given one-unit change, the corresponding probability change generally depends on the starting probability. Finally, coefficient estimates alone do not establish that an interaction is statistically distinguishable from zero; that requires an appropriate inferential procedure.

Key takeaway: For a logistic model with a predictor-by-group interaction, calculate the slope within each group before exponentiating. The predictor main effect belongs to the reference group, and a group main effect is a contrast at the predictor’s zero point unless the predictor has been centered.

Check Your Understanding

For each problem, identify the relevant conditional effect before calculating an odds ratio.

  1. A hypothetical model for an event has \(\operatorname{logit}(p)=-1+0.25x+0.4g+0.5xg\), where \(g=0\) is the reference group and \(g=1\) is the comparison group. Find both one-unit predictor odds ratios and the comparison-to-reference odds ratio at \(x=2\). (Answer: Reference odds ratio \(=1.2840\); comparison odds ratio \(=2.1170\); group odds ratio at \(x=2\) \(=4.0552\).)
  2. A fitted model has predictor coefficient \(-0.3\), group coefficient \(0.6\), and interaction coefficient \(-0.2\). For \(g=1\), find the one-unit predictor odds ratio. Then find the comparison-to-reference odds ratio at \(x=3\). (Answer: Comparison-group predictor odds ratio \(=\exp(-0.5)=0.6065\); group odds ratio at \(x=3\) \(=\exp(0)=1.0000\).)
  3. A model has reference-group slope \(0.1\), Group B main effect \(-0.2\), and Group B interaction coefficient \(0.4\). Find the slope and one-unit odds ratio for Group B, and the Group B-to-reference odds ratio at \(x=1\). (Answer: Group B slope \(=0.5\); one-unit odds ratio \(=1.6487\); group odds ratio at \(x=1\) \(=\exp(0.2)=1.2214\).)
  4. A binary-group model uses \(x_c=x-5\). Its group main-effect coefficient is \(-0.2\), and its interaction coefficient is \(0.1\). What group odds ratio does the group main-effect coefficient represent, and what is the difference between the two groups’ predictor slopes? (Answer: The group odds ratio at original \(x=5\) is \(\exp(-0.2)=0.8187\); the comparison-group slope exceeds the reference-group slope by \(0.1\) log-odds units per unit of \(x\).)
  5. In a three-group model, Group A is the reference with predictor slope \(-0.1\). Group B’s interaction coefficient is \(0.3\), and Group C’s is \(-0.2\). Find each group’s slope and one-unit odds ratio. (Answer: Group A slope \(=-0.1\), odds ratio \(=0.9048\); Group B slope \(=0.2\), odds ratio \(=1.2214\); Group C slope \(=-0.3\), odds ratio \(=0.7408\).)
Clinical Biostats