Tutorials › Exam SRM - Statistics for Risk Modeling › A Worked Logistic Model With Categorical Interactions

Exam SRM · Logistic Regression · Tutorial 319 of 926

A Worked Logistic Model With Categorical Interactions

Learn to combine indicator coding and interaction coefficients to calculate conditional odds ratios and fitted probabilities.

Intermediate 12 min read

What You'll Learn

  • Set up a logistic model with a multi-level factor and a binary predictor
  • Identify reference categories and write the linear predictor for a specified group
  • Calculate the binary predictor’s odds ratio separately for each factor category
  • Compare factor categories at a fixed value of the binary predictor
  • Convert a fitted linear predictor into a probability
  • Check interaction interpretations against the model’s coding

Why Categorical Interactions Need Careful Interpretation

A logistic model with an interaction can give different odds ratios for the same binary predictor in different groups. For example, a hypothetical insurer might model whether a policyholder renews using plan type and whether the policyholder received a reminder. If the reminder effect varies by plan type, one overall reminder odds ratio does not describe every plan. The interaction terms encode those differences.

The essential calculation is to write the linear predictor for the particular group and predictor value of interest. From that predictor, take the relevant difference to obtain an odds ratio, or apply the inverse-logit function to obtain a fitted probability. The examples below use hypothetical fitted models and are aligned with the SOA Exam SRM (Statistics for Risk Modeling) syllabus.

Definition: Let \(Y\) be a binary response, and let \(p=P(Y=1\mid \text{predictors})\). A logistic regression model specifies \(\log\{p/(1-p)\}\), the log odds of the response, as a linear function of its predictors. For a factor with reference category \(A\), nonreference categories \(B,C,\ldots\), and a binary predictor \(x\in\{0,1\}\), one possible model is $$ \log\left(\frac{p}{1-p}\right) =\beta_0+\beta_B I_B+\beta_C I_C+\cdots+\gamma x+\delta_B(I_Bx)+\delta_C(I_Cx)+\cdots. $$ Here \(I_B=1\) for category \(B\) and \(0\) otherwise; \(I_C\) is defined similarly. The reference category has all factor indicators equal to zero. The inverse-logit function converts a linear predictor \(\eta\) to a fitted probability: \(p=e^\eta/(1+e^\eta)=1/(1+e^{-\eta})\).

The model assumes that the conditional response probability follows the stated logit form. In the usual binary-response setup, observations are modeled as conditionally independent Bernoulli outcomes given their predictors. A fitted model supplies coefficient estimates; calculations below treat those estimates as given. These calculations alone do not establish a causal effect, and they do not account for estimation uncertainty.

How the Interaction Changes the Odds Ratio

For the reference category, the coefficient of \(x\) is \(\gamma\). For category \(B\), the coefficient of \(x\) is \(\gamma+\delta_B\), and for category \(C\) it is \(\gamma+\delta_C\). The binary predictor’s odds ratio is therefore category-specific whenever an interaction coefficient is nonzero.

$$ \operatorname{OR}_{x=1\text{ versus }x=0\mid A}=e^\gamma,\qquad \operatorname{OR}_{x=1\text{ versus }x=0\mid B}=e^{\gamma+\delta_B},\qquad \operatorname{OR}_{x=1\text{ versus }x=0\mid C}=e^{\gamma+\delta_C}. $$

This follows directly from the definition of odds. Holding the category fixed, changing \(x\) from zero to one changes the linear predictor by the coefficient of \(x\) for that category. If the two linear predictors are \(\eta_0\) and \(\eta_1\), the odds are \(e^{\eta_0}\) and \(e^{\eta_1}\). Their ratio is \(e^{\eta_1}/e^{\eta_0}=e^{\eta_1-\eta_0}\). Thus, the odds ratio is the exponential of the relevant linear-predictor difference.

The same difference method compares factor categories at a fixed \(x\). For example, the log odds contrast \(B\) versus \(A\) is \(\beta_B\) when \(x=0\), but \(\beta_B+\delta_B\) when \(x=1\). Exponentiating gives the corresponding odds ratio. An interaction coefficient is not, by itself, the group-specific odds ratio: it modifies the binary predictor’s log odds effect relative to the reference category.

Worked Example: Odds Ratios and Probabilities in Three Groups

A hypothetical fitted model predicts whether a customer renews a policy. Let \(A\) be the reference plan, \(B\) and \(C\) be the other plan categories, and let \(x=1\) indicate receipt of a reminder. The fitted model is

$$ \eta=-2+0.5I_B-0.4I_C+0.8x+0.6(I_Bx)-0.3(I_Cx). $$

Calculate the reminder odds ratio in each plan category, and calculate the fitted renewal probability for each category both without and with a reminder.

Method. Substitute the category indicators and \(x\) into the linear predictor. The reminder odds ratio in a category is the exponential of the change in \(\eta\) from \(x=0\) to \(x=1\). The fitted probability is \(1/(1+e^{-\eta})\).

Plan \(A\). Both factor indicators are zero. At \(x=0\), \(\eta=-2\); at \(x=1\), \(\eta=-2+0.8=-1.2\). The log odds change is \(0.8\), so the odds ratio is \(e^{0.8}=2.2255\). The probabilities are \(1/(1+e^2)=0.1192\) and \(1/(1+e^{1.2})=0.2315\).

Plan \(B\). Set \(I_B=1\) and \(I_C=0\). At \(x=0\), \(\eta=-2+0.5=-1.5\). At \(x=1\), \(\eta=-2+0.5+0.8+0.6=-0.1\). The log odds change is \((-0.1)-(-1.5)=1.4\), also equal to \(0.8+0.6\). Thus the odds ratio is \(e^{1.4}=4.0552\). The probabilities are \(1/(1+e^{1.5})=0.1824\) and \(1/(1+e^{0.1})=0.4750\).

Plan \(C\). Set \(I_B=0\) and \(I_C=1\). At \(x=0\), \(\eta=-2-0.4=-2.4\). At \(x=1\), \(\eta=-2-0.4+0.8-0.3=-1.9\). The log odds change is \((-1.9)-(-2.4)=0.5\), equal to \(0.8-0.3\). The odds ratio is \(e^{0.5}=1.6487\). The probabilities are \(1/(1+e^{2.4})=0.0832\) and \(1/(1+e^{1.9})=0.1301\).

Check. The reminder odds ratios are \(e^{0.8}\), \(e^{0.8+0.6}\), and \(e^{0.8-0.3}\), matching the three calculated log odds changes. Probabilities lie between zero and one, and the odds ratios are all positive.

Comparing Categories at a Fixed Predictor Value

A question about the effect of \(x\) within a category is different from a question comparing categories at the same \(x\). For the latter, subtract the two category-specific linear predictors while holding \(x\) fixed. Both the main-effect and interaction terms can contribute to that contrast. State which category is in the numerator of the odds ratio; reversing the comparison takes the reciprocal.

Worked Example: Comparing Two Nonreference Categories

A hypothetical fitted model uses reference category \(A\), with nonreference categories \(B,C,D\), and a binary predictor \(x\):

$$ \eta=-1.5+0.7I_B-0.2I_C+0.4I_D+0.6x-0.3(I_Bx)+0.5(I_Cx). $$

Find the odds ratio for category \(C\) versus category \(B\) when \(x=1\), and find the fitted probability for category \(C\) when \(x=1\).

Method. Evaluate the two linear predictors at the same \(x\), subtract \(B\) from \(C\), and exponentiate. For the probability, evaluate the linear predictor for \(C\) and apply the inverse logit.

For category \(C\), \(I_C=1\), \(I_B=I_D=0\), and \(x=1\). Therefore \(\eta_C=-1.5-0.2+0.6+0.5=-0.6\). For category \(B\), \(I_B=1\), \(I_C=I_D=0\), and \(x=1\), so \(\eta_B=-1.5+0.7+0.6-0.3=-0.5\). The log odds contrast \(C\) versus \(B\) is \(-0.6-(-0.5)=-0.1\), giving an odds ratio of \(e^{-0.1}=0.9048\). Equivalently, the category contrast is \((\beta_C+\delta_C)-(\beta_B+\delta_B)=(-0.2+0.5)-(0.7-0.3)=-0.1\); the shared intercept and \(x\) effect cancel.

For category \(C\), \(\eta_C=-0.6\), so the fitted probability is \(1/(1+e^{0.6})=0.3543\). The odds ratio below one is consistent with category \(C\) having lower fitted odds than category \(B\) at \(x=1\).

Check. The comparison uses the same \(x\) value in both categories, and the stated direction is \(C\) relative to \(B\). Reversing the contrast would give \(e^{0.1}=1.1052\).

A Second Interaction Contrast

The interaction can also be understood as a comparison of odds ratios. For category \(B\), the binary predictor’s odds ratio is \(e^{\gamma+\delta_B}\); for reference category \(A\), it is \(e^\gamma\). The ratio of these odds ratios is \(e^{\delta_B}\). This is sometimes called a ratio of odds ratios. It describes how the binary predictor’s odds ratio changes across categories on the multiplicative odds scale.

Worked Example: Reading the Ratio of Odds Ratios

A hypothetical fitted model compares direct distribution (reference), mail distribution, and agent distribution for a binary outcome. Let \(x=1\) indicate a service intervention. The model is

$$ \eta=-1.2+0.4I_M-0.5I_A+0.9x+0.2(I_Mx)-0.6(I_Ax). $$

Find the intervention odds ratio for the agent category, the odds ratio comparing agent with mail when \(x=1\), and the fitted probability for the agent category when \(x=1\).

Agent intervention odds ratio. The coefficient of \(x\) in the agent category is \(0.9-0.6=0.3\), so the odds ratio is \(e^{0.3}=1.3499\).

Agent versus mail at \(x=1\). The category-specific terms are \(-0.5-0.6=-1.1\) for agent and \(0.4+0.2=0.6\) for mail. The log odds contrast is \(-1.1-0.6=-1.7\), so the odds ratio is \(e^{-1.7}=0.1827\). The agent category has lower fitted odds than mail at this value of \(x\).

Agent fitted probability at \(x=1\). Its linear predictor is \(-1.2-0.5+0.9-0.6=-1.4\). Thus the fitted probability is \(1/(1+e^{1.4})=0.1978\).

Check. The intervention odds ratio for direct distribution is \(e^{0.9}\). The ratio of agent to direct intervention odds ratios is \(e^{0.3}/e^{0.9}=e^{-0.6}\), which agrees with the agent interaction coefficient. The odds ratio comparing agent with mail is less than one, as indicated by its negative log odds contrast.

Common Mistakes and a Reliable Workflow

One frequent mistake is to interpret a main-effect coefficient as applying to every category. In the model above, \(0.9\) is the intervention log odds effect for the reference category, not the agent category; the agent effect is \(0.9-0.6=0.3\).

Another mistake is to interpret an odds ratio as a probability ratio or a probability difference. In the first example, the odds ratio for plan \(B\) is about \(4.0552\), but that does not mean the renewal probability is multiplied by \(4.0552\). The probabilities are \(0.1824\) and \(0.4750\); their ratio is not the odds ratio. Convert each linear predictor separately when a probability is requested.

Use this sequence to keep the calculations straight:

1
Set the coding.
Identify the reference category, the relevant indicator values, and whether the binary predictor is zero or one.
2
Write the requested linear predictor or contrast.
For an odds ratio, subtract the linear predictors in the stated order. For a probability, calculate the full linear predictor.
3
Transform once, in the right way.
Exponentiate a log odds difference to get an odds ratio; apply the inverse logit to a linear predictor to get a probability.
4
Check direction and scale.
A reversed contrast gives the reciprocal odds ratio. A fitted probability must be between zero and one.

For example, incorrectly using \(e^{0.9}\) as the agent intervention odds ratio in the third worked example ignores the interaction. The corrected calculation includes the agent interaction: \(e^{0.9-0.6}=e^{0.3}=1.3499\). Always substitute the category indicators before identifying the coefficient of the binary predictor.

Key takeaway: In a logistic model with categorical interactions, an odds ratio is determined by a linear-predictor difference for the specific comparison being asked. A fitted probability instead comes from the complete linear predictor for one specified combination of predictors.

Check Your Understanding

For each problem, identify the relevant contrast before applying the exponential or inverse-logit transformation.

  1. A fitted model has reference category \(A\), category \(B\), and binary predictor \(x\): \(\eta=-1+0.5I_B+0.4x+0.7(I_Bx)\). Find the odds ratio for \(x=1\) versus \(x=0\) in category \(B\), and the fitted probability for \(B\) when \(x=1\). (Answer: odds ratio \(e^{1.1}=3.0042\); probability \(1/(1+e^{-0.6})=0.6457\))
  2. A model has categories \(A\) (reference), \(B\), and \(C\), with \(\eta=-2-0.3I_B+0.8I_C+0.5x+0.2(I_Bx)-0.4(I_Cx)\). Find the odds ratio for \(C\) versus \(B\) when \(x=1\). (Answer: \(e^{0.5}=1.6487\))
  3. A model has reference category \(A\), category \(B\), and binary predictor \(x\): \(\eta=-2+0.6I_B+0.2x+0.5(I_Bx)\). Find the odds ratio for \(x=1\) versus \(x=0\) in \(B\), then find the fitted probability for \(B\) at \(x=1\). (Answer: odds ratio \(e^{0.7}=2.0138\); probability \(1/(1+e^{0.7})=0.3318\))
  4. A model has reference category \(A\), category \(B\), and binary predictor \(x\), with \(\eta=-1.4+0.3I_B+0.6x-0.2(I_Bx)\). Calculate the binary predictor odds ratio in each category, then state the ratio of the \(B\) odds ratio to the \(A\) odds ratio. (Answer: \(A\): \(e^{0.6}=1.8221\); \(B\): \(e^{0.4}=1.4918\); ratio \(e^{-0.2}=0.8187\))
  5. A model has reference category \(A\) and categories \(B,C\), with \(\eta=-1.8+0.4I_B-0.5I_C+0.7x+0.3(I_Bx)-0.2(I_Cx)\). At \(x=1\), find the odds ratio for \(C\) versus \(B\), and the fitted probability for \(C\). (Answer: odds ratio \(e^{-1.4}=0.2466\); probability \(1/(1+e^{1.8})=0.1419\))
Clinical Biostats