Tutorials › Exam SRM - Statistics for Risk Modeling › Interactions Between Binary and Continuous Predictors

Exam SRM · Logistic Regression · Tutorial 308 of 926

Interactions Between Binary and Continuous Predictors

Build and interpret a logistic regression with a binary-by-continuous interaction, including group-specific slopes, odds ratios, and fitted probabilities.

Intermediate 11 min read

What You'll Learn

  • Write a logistic model with a binary-by-continuous product term
  • Identify the continuous-predictor slope for each binary group
  • Convert group-specific slopes into odds ratios for stated predictor changes
  • Interpret the binary-group difference at a specified continuous-predictor value
  • Center a continuous predictor without changing fitted values or group slopes
  • Avoid treating the continuous main-effect coefficient as the slope for both groups

Why Include an Interaction?

A logistic regression without an interaction assumes that a one-unit increase in a continuous predictor has the same effect on the odds of the outcome in every binary group. That assumption can be too restrictive. For example, the relationship between a measured risk score and the probability of a hypothetical event may differ between two treatment groups. An interaction allows the continuous-predictor slope to depend on group membership.

The focus here is the model and its interpretation: how to represent the interaction, determine each group’s slope on the log-odds scale, and translate a slope into an odds ratio. The outcome is binary, and all scenarios and data below are hypothetical.

Definition: Let \(Y\) be a binary outcome, \(x\) a continuous predictor, and \(z\) a binary indicator coded \(0\) or \(1\). A binary-by-continuous interaction model is $$ Y\mid x,z\sim\operatorname{Bernoulli}(p(x,z)),\qquad \operatorname{logit}(p(x,z))=\log\left(\frac{p(x,z)}{1-p(x,z)}\right) =\beta_0+\beta_1x+\beta_2z+\beta_3xz. $$ The term \(xz\) is the interaction term. The model describes the conditional probability \(p(x,z)=P(Y=1\mid x,z)\); it does not require the probability to change linearly with \(x\).

For independent observations \((y_i,x_i,z_i)\), the model is fitted by estimating the coefficients in the Bernoulli likelihood. Each observation contributes \(p_i^{y_i}(1-p_i)^{1-y_i}\), where \(p_i=p(x_i,z_i)\). Equivalently, the design matrix has columns \(1\), \(x\), \(z\), and \(xz\). The fitted coefficients are generally obtained by numerical maximum likelihood, not by applying a simple least-squares formula.

Group-Specific Slopes and Odds Ratios

Because \(z\) can only be \(0\) or \(1\), substitute each value into the linear predictor. For group \(z=0\), the \(z\) and \(xz\) terms vanish, leaving \(\beta_0+\beta_1x\). For group \(z=1\), the predictor is \((\beta_0+\beta_2)+(\beta_1+\beta_3)x\). Thus \(\beta_1\) is the slope for the reference group, while \(\beta_1+\beta_3\) is the slope for the group coded 1.

$$ \begin{aligned} z=0:\quad &\operatorname{logit}(p)=\beta_0+\beta_1x, &\text{slope in }x&=\beta_1,\\ z=1:\quad &\operatorname{logit}(p)=(\beta_0+\beta_2)+(\beta_1+\beta_3)x, &\text{slope in }x&=\beta_1+\beta_3. \end{aligned} $$

For a change of \(c\) units in \(x\), holding group \(z\) fixed, the odds are multiplied by the exponential of \(c\) times that group’s slope. Therefore, the odds ratios are \(\exp(c\beta_1)\) for \(z=0\) and \(\exp(c(\beta_1+\beta_3))\) for \(z=1\). A one-unit odds ratio is obtained by setting \(c=1\). The unit must be stated: a one-year change and a ten-year change generally have different odds ratios.

Derivation: In a group with logit \(\alpha+sx\), increasing \(x\) by \(c\) changes the logit by \(sc\). Since the logit is the logarithm of the odds, the new log-odds equal the old log-odds plus \(sc\). Exponentiating shows that new odds equal old odds multiplied by \(\exp(sc)\). In the interaction model, \(s=\beta_1+\beta_3z\), which gives the group-specific odds ratio \(\exp\{c(\beta_1+\beta_3z)\}\).

The coefficient \(\beta_2\) is the difference between the groups’ logits when \(x=0\). At another value of \(x\), the difference between the group \(z=1\) and group \(z=0\) logits is \(\beta_2+\beta_3x\). Consequently, \(\beta_2\) is not a universal group effect unless \(x=0\) is the value of interest. Centering \(x\) at a meaningful value can make this reference point easier to interpret.

Worked Example: Different Age Slopes by Group

In a hypothetical study, \(Y=1\) indicates that a participant experiences a specified event during a follow-up period. Let \(z=0\) denote the reference group and \(z=1\) the other group. Age is measured in years relative to age 40, so \(x=\text{age}-40\). The fitted model is \(\operatorname{logit}(p)=-0.8+0.12x+0.3z-0.05xz\). Find each group’s one-year odds ratio and the fitted event probability for \(z=1\) at age 50.

Method. Substitute each group code to find its logit slope, exponentiate the slope for a one-year odds ratio, and then evaluate the full linear predictor at the specified age and group.

Group \(z=0\). Its slope is \(\beta_1=0.12\) per year. The one-year odds ratio is \(\exp(0.12)=1.1275\), to four decimal places.

Group \(z=1\). Its slope is \(\beta_1+\beta_3=0.12-0.05=0.07\) per year. The one-year odds ratio is \(\exp(0.07)=1.0725\), to four decimal places.

Probability at age 50 in group \(z=1\). The centered age is \(x=50-40=10\). The linear predictor is \(-0.8+0.12(10)+0.3(1)-0.05(10)(1)=-0.8+1.2+0.3-0.5=0.2\). Thus \(p=1/(1+\exp(-0.2))=0.5498\), to four decimal places.

Check. The logit \(0.2\) corresponds to odds \(\exp(0.2)\), and converting those odds to a probability gives \(\exp(0.2)/(1+\exp(0.2))=0.5498\). The common mistake is to use \(0.12\) as the slope for both groups; the interaction changes the \(z=1\) slope to \(0.07\).

Reading and Constructing the Model

A useful way to check an interaction model is to write its two group-specific equations explicitly. This also works in reverse: if group-specific logit equations are supplied, their intercepts and slopes determine the four coefficients in the interaction model. The intercept for \(z=0\) is \(\beta_0\); the difference in intercepts is \(\beta_2\). The slope for \(z=0\) is \(\beta_1\); the difference in slopes is \(\beta_3\).

Worked Example: Building the Interaction from Group Equations

A hypothetical study models whether a device records a specified alert during a monitoring period. Let \(x\) be the number of hours of exposure and let \(z=0\) and \(z=1\) identify two device settings. The fitted group equations are \(\operatorname{logit}(p\mid z=0)=-1.2+0.08x\) and \(\operatorname{logit}(p\mid z=1)=-0.6+0.02x\). Write the combined interaction model, then find each group’s odds ratio for a five-hour increase and the probability in each group at \(x=10\).

Step 1: Identify the reference-group coefficients. The \(z=0\) equation is \(\beta_0+\beta_1x\), so \(\beta_0=-1.2\) and \(\beta_1=0.08\).

Step 2: Find the changes for \(z=1\). The intercept changes from \(-1.2\) to \(-0.6\), so \(\beta_2=-0.6-(-1.2)=0.6\). The slope changes from \(0.08\) to \(0.02\), so \(\beta_3=0.02-0.08=-0.06\). The combined model is \(\operatorname{logit}(p)=-1.2+0.08x+0.6z-0.06xz\).

Step 3: Calculate the five-hour odds ratios. For \(z=0\), the slope is \(0.08\), giving \(\exp(5(0.08))=\exp(0.4)=1.4918\). For \(z=1\), the slope is \(0.08-0.06=0.02\), giving \(\exp(5(0.02))=\exp(0.1)=1.1052\). Both are rounded to four decimal places.

Step 4: Calculate probabilities at \(x=10\). For \(z=0\), the logit is \(-1.2+0.08(10)=-0.4\), so \(p=1/(1+\exp(0.4))=0.4013\). For \(z=1\), it is \(-0.6+0.02(10)=-0.4\), so \(p=1/(1+\exp(0.4))=0.4013\). Probabilities are rounded to four decimal places.

Check. The two group logits agree at \(x=10\), so their fitted probabilities must agree there. The five-hour odds ratios differ because the group slopes differ. A common mistake is to treat the \(z=1\) slope \(0.02\) as the interaction coefficient; the interaction coefficient is the slope difference, \(-0.06\).

Centering the Continuous Predictor

The value \(x=0\) determines the interpretation of the intercept and of the binary coefficient. If zero is far outside the data range or has no useful meaning, define a centered predictor \(t=x-a\), where \(a\) is a chosen reference value. Re-expressing the model changes the intercept terms but does not change fitted probabilities or either group’s slope. In particular, the interaction coefficient remains the difference between the group slopes.

Worked Example: Centering at a Meaningful Age

For a hypothetical binary outcome, suppose a fitted model uses age in years and is \(\operatorname{logit}(p)=-6+0.08(\text{age})+0.3z-0.03(\text{age})z\). Set \(t=\text{age}-50\), rewrite the model in terms of \(t\), and find the group-specific odds ratios for a ten-year age increase. Also calculate the probability for each group at age 50.

Step 1: Substitute age \(=t+50\). The model becomes \(-6+0.08(t+50)+0.3z-0.03(t+50)z\). Expanding gives \(-6+0.08t+4+0.3z-0.03tz-1.5z\), or \(-2+0.08t-1.2z-0.03tz\).

Step 2: Find the group slopes. For \(z=0\), the slope in \(t\) is \(0.08\). For \(z=1\), it is \(0.08-0.03=0.05\). A ten-year increase therefore multiplies the odds by \(\exp(10(0.08))=\exp(0.8)=2.2255\) for \(z=0\), and by \(\exp(10(0.05))=\exp(0.5)=1.6487\) for \(z=1\), to four decimal places.

Step 3: Evaluate age 50. At age 50, \(t=0\). For \(z=0\), the logit is \(-2\), giving \(p=1/(1+\exp(2))=0.1192\). For \(z=1\), the logit is \(-2-1.2=-3.2\), giving \(p=1/(1+\exp(3.2))=0.0392\). Probabilities are rounded to four decimal places.

Check. Setting \(t=0\) means evaluating the original model at age 50. Substitution in the original equation gives logits \(-2\) and \(-3.2\), matching the centered model. Centering changed the coefficient attached to the group indicator because its interpretation is now the group difference at age 50.

Common Interpretation Traps

The interaction coefficient is not, by itself, either group’s continuous-predictor slope. It is the amount by which the slope for \(z=1\) differs from the slope for \(z=0\). Likewise, the binary coefficient is the group logit difference only at \(x=0\), or at the centering value if a centered predictor is used. These are statements about log-odds, not direct differences in probabilities.

For example, in the first worked example, the incorrect calculation for the \(z=1\) one-year odds ratio would be \(\exp(0.12)=1.1275\), using the reference-group slope. The correction is to include the interaction: the \(z=1\) slope is \(0.12-0.05=0.07\), so its odds ratio is \(\exp(0.07)=1.0725\). Always substitute the group code into the entire linear predictor before interpreting a coefficient.

Key takeaway: With \(z\) coded \(0/1\), the continuous-predictor slopes are \(\beta_1\) for \(z=0\) and \(\beta_1+\beta_3\) for \(z=1\). For a \(c\)-unit increase, exponentiate \(c\) times the relevant slope to obtain the odds ratio. Interpret the binary coefficient at the predictor’s zero point, and state the units of every change.

Check Your Understanding

For each problem, identify the relevant group slope before calculating an odds ratio or probability. Probabilities and odds ratios are rounded to four decimal places where needed.

  1. A hypothetical outcome follows \(\operatorname{logit}(p)=-1+0.06x+0.5z-0.02xz\). Find the one-unit odds ratio in each group and the probability for \(z=1\) at \(x=5\). (Answer: slopes \(0.06\) and \(0.04\); odds ratios \(1.0618\) and \(1.0408\); probability \(0.4256\).)
  2. The fitted group logits are \(0.4-0.1x\) for \(z=0\) and \(-0.2+0.05x\) for \(z=1\). Give the coefficients \((\beta_0,\beta_1,\beta_2,\beta_3)\) in the interaction model, the \(z=1\) odds ratio for a two-unit increase, and its probability at \(x=4\). (Answer: \((0.4,-0.1,-0.6,0.15)\); odds ratio \(1.1052\); probability \(0.5000\).)
  3. A hypothetical model is \(\operatorname{logit}(p)=-2+0.1x+0.7z-0.04xz\). Find each group’s odds ratio for a ten-unit increase and the probability for \(z=1\) at \(x=5\). (Answer: odds ratios \(2.7183\) for \(z=0\) and \(1.8221\) for \(z=1\); probability \(0.2689\).)
  4. For \(\operatorname{logit}(p)=0.3-0.04x+0.2z+0.03xz\), calculate the odds ratios for a five-unit increase in \(x\) for both groups. (Answer: \(0.8187\) for \(z=0\) and \(0.9512\) for \(z=1\).)
  5. A model is \(\operatorname{logit}(p)=-1.5+0.09(\text{age}-20)+0.4z-0.05(\text{age}-20)z\). Find the \(z=1\) odds ratio for a two-year increase and the probability for \(z=1\) at age 20. (Answer: odds ratio \(1.0833\); probability \(0.2497\).)
Clinical Biostats