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

Exam SRM · Multiple Regression Estimation · Tutorial 48 of 926

Interactions Between a Binary and Continuous Predictor

See how a binary-by-continuous interaction changes both the group-specific intercepts and slopes in a linear regression model.

Intermediate 10 min read

What You'll Learn

  • Write a regression model containing a binary indicator, a continuous predictor, and their product
  • Derive the intercept and slope for each indicator group
  • Interpret the interaction coefficient as a difference in slopes
  • Find the difference between group-specific fitted means at a given predictor value
  • Explain how centering the continuous predictor changes intercept interpretations but not slopes
  • Recognize mistakes involving the reference group and the predictor value zero

Why Include a Binary-by-Continuous Interaction?

A regression with a binary predictor and a continuous predictor can represent more than a constant difference between two groups. For example, the association between years of experience and expected claim-handling cost might differ between two hypothetical coverage categories. If the fitted lines have different slopes, the model needs an interaction between the binary indicator and the continuous predictor.

The interaction model represents a separate straight line for each indicator group. Its coefficients have clear group-specific meanings, but those meanings depend on which group is coded as the reference and on the value zero of the continuous predictor.

Definition: Let \(D_i\) be a binary indicator equal to 0 for the reference group and 1 for the comparison group, and let \(x_i\) be a continuous predictor. A linear regression model with their interaction is $$ Y_i=\beta_0+\beta_1x_i+\beta_2D_i+\beta_3x_iD_i+\varepsilon_i. $$ The product \(x_iD_i\) is the interaction term. The conditional mean is assumed to have this form, with \(E[\varepsilon_i\mid x_i,D_i]=0\). This zero conditional mean condition allows the regression mean to be interpreted as the expected response at the stated predictor values; it does not by itself establish a causal effect.

When \(D_i=0\), both terms involving \(D_i\) vanish. When \(D_i=1\), the indicator term adds \(\beta_2\), and the product term adds \(\beta_3x_i\). Thus the coefficients describe the two groups jointly: \(\beta_0\) and \(\beta_1\) give the reference group's line, while \(\beta_2\) and \(\beta_3\) modify its intercept and slope for the comparison group.

Deriving the Two Group-Specific Lines

Substitution of each possible indicator value gives the group-specific conditional means. This is the essential calculation for interpreting an interaction; it is not enough to read each coefficient in isolation.

1
Set the indicator to zero.
For the reference group, \(D_i=0\), so \(D_i=0\) and \(x_iD_i=0\). The conditional mean is \(\beta_0+\beta_1x_i\).
2
Set the indicator to one.
For the comparison group, \(D_i=1\), so \(D_i=1\) and \(x_iD_i=x_i\). The conditional mean is \((\beta_0+\beta_2)+(\beta_1+\beta_3)x_i\).
3
Read the coefficient contrasts.
The intercept difference is \(\beta_2\); the slope difference is \(\beta_3\). The comparison group's intercept and slope are sums of the corresponding reference-group coefficient and its adjustment.
$$ \begin{aligned} E[Y_i\mid x_i,D_i=0]&=\beta_0+\beta_1x_i,\\ E[Y_i\mid x_i,D_i=1]&=(\beta_0+\beta_2)+(\beta_1+\beta_3)x_i. \end{aligned} $$

The difference in conditional means, comparison group minus reference group, at a particular value \(x\) is therefore

$$ \Delta(x)=\beta_2+\beta_3x. $$

This expression is important because the groups need not differ by a fixed amount at every \(x\). If \(\beta_3\ne 0\), their difference changes with \(x\). The coefficient \(\beta_2\) is the group difference specifically at \(x=0\), not necessarily the difference at a typical or practically important predictor value.

Worked Examples

Worked Example: Interpreting Fitted Group Lines

A hypothetical insurer models expected annual claim-handling cost \(Y\), in dollars per policy, using years of policy duration \(x\) and an indicator \(D\) for a coverage category. \(D=0\) denotes the reference category and \(D=1\) the comparison category. The fitted model is $$ \widehat{Y}=120+8x+25D-2xD. $$ Find each group's fitted line, compare the groups at \(x=5\), and identify the predictor value where the fitted lines meet. Treat the model as a description of conditional means; no inference about the coefficients is requested.

Method. Substitute \(D=0\) and \(D=1\) into the fitted equation.

For the reference category, \(D=0\), so \(25D=0\) and \(-2xD=0\). Its fitted line is $$ \widehat{Y}_0=120+8x. $$ Its fitted intercept is \(\$120\), and its slope is \(\$8\) per additional year.

For the comparison category, \(D=1\), so \(25D=25\) and \(-2xD=-2x\). Combining like terms gives $$ \widehat{Y}_1=120+8x+25-2x=145+6x. $$ Its fitted intercept is \(\$145\), and its slope is \(\$6\) per additional year. The intercept difference is \(25\), and the slope difference is \(-2\) dollars per year.

At \(x=5\), the reference-category fitted mean is \(120+8(5)=120+40=\$160\). The comparison-category fitted mean is \(145+6(5)=145+30=\$175\). The comparison-minus-reference difference is \(175-160=\$15\). The coefficient contrast gives the same result: \(25-2(5)=25-10=\$15\).

To find where the fitted lines meet, set their fitted means equal: $$ 120+8x=145+6x. $$ Subtract \(6x\) from both sides and subtract 120 from both sides to obtain \(2x=25\), so \(x=12.5\). Substitution checks the result: both fitted lines give \(\$220\) at \(x=12.5\). The calculation is algebraically correct, but if the observed policy durations do not include values near 12.5 years, this equality is an extrapolation rather than a comparison supported by nearby data.

Common mistake avoided: treating \(25\) as the group difference at every duration. It is the difference only at \(x=0\); at \(x=5\), the interaction changes the difference to \(\$15\).

Worked Example: Building Interaction Coefficients From Two Lines

A hypothetical study models the mean number of annual service calls \(Y\) by equipment age \(x\), in years, for two maintenance plans. A fitted line reported for plan \(D=0\) is \(\widehat{Y}_0=42+3.5x\), and the fitted line for plan \(D=1\) is \(\widehat{Y}_1=30+5x\). Express these lines as one interaction model, identify the interaction coefficient, and compare the plans at age \(x=8\).

Method. Match the reference line to \(\beta_0+\beta_1x\), then express the second line's intercept and slope as adjustments to those reference coefficients.

The reference line \(42+3.5x\) gives \(\beta_0=42\) and \(\beta_1=3.5\). For \(D=1\), the model's intercept is \(\beta_0+\beta_2=30\). Therefore $$ \beta_2=30-42=-12. $$ The comparison line's slope is \(\beta_1+\beta_3=5\). Therefore $$ \beta_3=5-3.5=1.5. $$ The combined model is $$ \widehat{Y}=42+3.5x-12D+1.5xD. $$

The interaction coefficient \(1.5\) means that the fitted slope for plan \(D=1\) is 1.5 service calls per year steeper than the fitted slope for plan \(D=0\). It does not mean the plans differ by 1.5 calls at every equipment age.

At \(x=8\), plan \(D=0\) has fitted mean \(42+3.5(8)=42+28=70\) calls. Plan \(D=1\) has fitted mean \(30+5(8)=30+40=70\) calls. Their difference is zero at this age. Using the interaction contrast gives the same check: $$ \Delta(8)=-12+1.5(8)=-12+12=0. $$ The lines meet at age 8, even though their intercepts and slopes are different.

Common mistake avoided: calling \(-12\) the difference between the plans for all equipment ages. It is the intercept adjustment, so it is the difference at age zero; the difference at age \(x\) is \(-12+1.5x\).

Worked Example: Centering Changes the Intercept Comparison

A hypothetical regression of expected annual benefit \(Y\), in dollars, on years of experience \(x\) and a binary program indicator \(D\) is $$ \widehat{Y}=70+4x+10D-1.5xD, $$ where \(D=0\) is the reference group. Rewrite the model using \(z=x-4\), interpret the group difference at four years of experience, and check that the fitted means agree at eight years.

Method. Since \(x=z+4\), substitute \(z+4\) everywhere \(x\) occurs and collect the terms involving \(z\), \(D\), and \(zD\).

Substitution gives $$ \widehat{Y}=70+4(z+4)+10D-1.5(z+4)D. $$ Expand each product: $$ \widehat{Y}=70+4z+16+10D-1.5zD-6D. $$ Combining constants and the \(D\) terms gives $$ \widehat{Y}=86+4z+4D-1.5zD. $$ The reference-group intercept is now 86, corresponding to \(z=0\), or \(x=4\). The comparison-group intercept at \(z=0\) is \(86+4=90\). Thus at four years, the comparison-minus-reference difference is \(\$4\). The slope remains 4 dollars per year for \(D=0\) and \(4-1.5=2.5\) dollars per year for \(D=1\).

Check at \(x=8\), which corresponds to \(z=8-4=4\). In the original model, the reference fitted mean is \(70+4(8)=102\), and the comparison fitted mean is \(70+4(8)+10-1.5(8)=102+10-12=100\). In the centered model, the reference fitted mean is \(86+4(4)=102\), and the comparison fitted mean is \(86+4(4)+4-1.5(4)=102+4-6=100\). Both parameterizations give the same fitted means.

The difference at \(x=8\) is \(-\$2\); the difference formula in centered units gives \(4-1.5(4)=-2\). Centering changed the intercept comparison from the difference at \(x=0\) to the difference at \(x=4\), but it did not change either group's slope or any fitted value.

Common mistake avoided: assuming the indicator coefficient must retain its original interpretation after changing the origin of \(x\). In the centered model, its coefficient is the group difference at \(x=4\), because that is where \(z=0\).

What the Coefficients Do—and Do Not—Say

The interpretation of each coefficient follows from the two substituted lines. In the model as written, \(\beta_1\) is the reference group's slope, \(\beta_1+\beta_3\) is the comparison group's slope, \(\beta_2\) is the group difference at \(x=0\), and \(\beta_3\) is the difference in slopes. A nonzero \(\beta_3\) describes nonparallel fitted lines. If \(\beta_3=0\), the fitted lines are parallel, though their intercepts can still differ by \(\beta_2\).

The intercepts are conditional means at \(x=0\). If zero is outside the range of the observed predictor or has no useful meaning in context, an intercept may be mathematically defined but practically unhelpful. Centering \(x\) at a meaningful value \(c\), using \(z=x-c\), makes the indicator coefficient the group difference at \(x=c\). The group slopes and fitted values remain unchanged.

The interaction describes a difference in fitted associations between groups. A regression interaction alone does not establish why the slopes differ, nor does it show that changing \(x\) causes a change in \(Y\). Also, the model assumes each group's conditional mean is linear in \(x\); if that form is unsuitable, the coefficient interpretations do not make the model suitable by themselves.

Common Exam Traps

  • Reading \(\beta_2\) as a universal group difference. The difference is \(\beta_2+\beta_3x\), so it depends on \(x\) whenever the interaction coefficient is nonzero.
  • Reading \(\beta_3\) as the comparison group's slope. It is the difference between slopes. The comparison slope is \(\beta_1+\beta_3\).
  • Forgetting the reference coding. The interpretations above assume \(D=0\) is the reference group and \(D=1\) is the comparison group. Reversing the coding changes the coefficient interpretations.
  • Ignoring units. If \(x\) is measured in months rather than years, a slope and the interaction's slope difference are expressed per month. Interpret the units that were actually used in the model.
  • Extrapolating an intercept or line intersection without comment. A mathematical value at \(x=0\), or where two lines meet, may lie outside the observed predictor range.
Key takeaway: First substitute \(D=0\) and \(D=1\) to obtain the two lines. Then interpret their intercepts and slopes in context. The difference between the lines at predictor value \(x\) is \(\beta_2+\beta_3x\), not simply the indicator coefficient.

Check Your Understanding

For each problem, identify the relevant group-specific quantities before giving the requested comparison.

  1. A hypothetical model for annual review time in hours is \(\widehat{Y}=18+2x+5D+0.5xD\), where \(x\) is years in a role and \(D=1\) indicates a specialized review team. Give both fitted lines and the comparison-minus-reference difference at \(x=6\). (Answer: \(D=0:\ 18+2x;\ D=1:\ 23+2.5x;\) difference at \(x=6\) is \(5+0.5(6)=8\) hours.)
  2. Two fitted lines for hypothetical equipment calibration error are \(D=0:\ 6-0.4x\) and \(D=1:\ 9-0.1x\). State \(\beta_0,\beta_1,\beta_2,\beta_3\) in the interaction model, using the first line as reference. (Answer: \(\beta_0=6,\ \beta_1=-0.4,\ \beta_2=3,\ \beta_3=0.3\).)
  3. A fitted model for hypothetical annual training cost is \(\widehat{Y}=240+12x-36D-3xD\), with \(x\) measured in hours of required training. Find each group's slope and the group difference at \(x=8\). (Answer: slopes are \(\$12\) per hour for \(D=0\) and \(\$9\) per hour for \(D=1\); the difference is \(-36-3(8)=-\$60\).)
  4. For \(\widehat{Y}=50+5x+8D-2xD\), find the value of \(x\) at which the two fitted lines meet, and their common fitted value. (Answer: \(8-2x=0\) gives \(x=4\); both lines give \(70\).)
  5. A model uses \(z=x-10\) and is \(\widehat{Y}=90+6z+15D-2zD\). What is the comparison-minus-reference difference when the original predictor is \(x=13\), and what is the comparison group's slope? (Answer: \(z=3\), so the difference is \(15-2(3)=9\); the comparison slope is \(6-2=4\) per unit of \(x\).)
Clinical Biostats