Why the Group Difference Depends on the Predictor
When a regression model includes an interaction between a quantitative predictor and group membership, the fitted difference between groups need not be the same at every predictor value. For example, two groups may have different fitted outcomes at a low dose, and that gap may become larger or smaller as dose increases. The interaction model gives a direct way to calculate the fitted group difference at a specified dose and to describe how it changes.
The comparison must be made at the same value of the quantitative predictor. Comparing one group at one predictor value with another group at a different value mixes a group difference with a predictor difference. This tutorial focuses on the fitted difference between two groups at a common, specified predictor value.
The Two-Group Interaction Model
Let \(G=0\) identify the reference group and \(G=1\) identify the comparison group. Let \(x\) be a quantitative predictor and \(Y\) the outcome. A linear model with a group-by-predictor interaction is
Here, \(\varepsilon_i\) represents the part of the outcome not captured by the model. The model describes a conditional mean that is linear in \(x\) within each group. For the fitted group comparison to be meaningful, the outcome should be measured consistently, the group coding should be clear, and the linear form should adequately describe the mean relationship over the predictor values being discussed. Observations are ordinarily treated as independent unless the analysis accounts for dependence. The point calculation below does not require normally distributed errors; assumptions about error variance and distribution matter for some forms of inference, not for subtracting the two fitted means.
Setting \(G=0\) gives the fitted mean for the reference group. Setting \(G=1\) gives the fitted mean for the comparison group:
Subtract the reference-group fitted mean from the comparison-group fitted mean at the same \(x\). The shared terms \(\hat{\beta}_0+\hat{\beta}_1x\) cancel.
The coefficient \(\hat{\beta}_2\) is the fitted group difference at \(x=0\), not necessarily an overall or typical difference. The interaction coefficient \(\hat{\beta}_3\) is the change in the fitted group difference for each one-unit increase in \(x\). Equivalently, it is the difference between the groups’ fitted slopes: the slope for \(G=1\) is \(\hat{\beta}_1+\hat{\beta}_3\), while the slope for \(G=0\) is \(\hat{\beta}_1\).
Worked Example: Comparing Groups at Two Study Times
Suppose a hypothetical analysis relates a score in points to study time in hours, comparing students in a workshop group (\(G=1\)) with students in a reference group (\(G=0\)). The fitted model is
Assume the linear interaction model is adequate over the study times considered, and the compared students are independent observational units. The question is how the fitted score difference changes at study times of 2 and 5 hours.
At \(x=2\) hours, the fitted difference, workshop minus reference, is
Checking by calculating both fitted means, the reference-group mean is \(42+(3.0)(2)=48.0\) points. The workshop-group mean is \(42+(3.0)(2)+5.0+(1.2)(2)=55.4\) points. Their difference is \(55.4-48.0=7.4\) points.
At \(x=5\) hours, the fitted difference is
The gap increases by \(11.0-7.4=3.6\) points when study time increases from 2 to 5 hours. This is also \((1.2\text{ points per hour})(5-2\text{ hours})=3.6\) points. Thus, the fitted difference increases by 1.2 points for every additional study hour in the model. This describes a fitted association, not evidence that workshop participation causes the score difference.
How the Difference Changes
The group difference is a linear function of \(x\). Its intercept is \(\hat{\beta}_2\), and its slope is \(\hat{\beta}_3\). In particular, for two predictor values \(x_a\) and \(x_b\), subtracting the two conditional differences gives
This result follows by distributing the subtraction: the \(\hat{\beta}_2\) terms cancel, leaving \(\hat{\beta}_3x_b-\hat{\beta}_3x_a=\hat{\beta}_3(x_b-x_a)\). Therefore, if \(\hat{\beta}_3\) is positive, the fitted difference for \(G=1\) relative to \(G=0\) grows as \(x\) increases. If it is negative, that difference declines. If it is zero, the fitted difference is constant across \(x\) in this model. A declining difference does not necessarily mean the difference becomes negative; its sign at a particular value depends on both coefficients.
Worked Example: Interpreting a Centered Predictor
Consider a hypothetical model relating an outcome in millimeters to a quantitative predictor measured in years. The predictor is centered at 10 years, so \(x_c=x-10\). Let \(G=1\) identify the comparison group and \(G=0\) the reference group. Suppose the fitted model is
Assume the linear conditional mean is reasonable over the ages being compared and that observations are independent. Because the predictor is centered, \(x_c=0\) corresponds to an original predictor value of 10 years. The fitted group difference at 10 years is \(4.0\) mm. The interaction coefficient says this difference decreases by \(0.5\) mm for each additional year above 10, within the modeled range.
At 14 years, \(x_c=14-10=4\). The fitted difference is
At 6 years, \(x_c=6-10=-4\), giving
The fitted difference is 4.0 mm smaller at 14 years than at 6 years: \(2.0-6.0=-4.0\) mm. The change also follows directly from the interaction coefficient: \((-0.5)(14-6)=-4.0\) mm. Centering changes which predictor value corresponds to the group coefficient: here, 4.0 mm is the difference at 10 years rather than at zero years. It does not change the fitted differences at corresponding original predictor values.
When the Difference Reverses
A group difference can change sign if the two fitted lines cross within the range of interest. When \(\hat{\beta}_3\ne 0\), the crossing value solves \(\hat{\beta}_2+\hat{\beta}_3x=0\), so \(x=-\hat{\beta}_2/\hat{\beta}_3\). This is an algebraic feature of the fitted model. It should only be interpreted when the crossing lies in a range where the model is supported; a crossing far outside the observed predictor values may be an extrapolation with little practical value.
Worked Example: A Difference That Changes Sign
Suppose a hypothetical model compares two groups on an outcome measured in symptom-score points, with \(x\) measured in dose units:
Suppose doses from 2 to 8 units are represented in the data, observations are independent, and a linear mean relationship over that range is considered appropriate. The fitted difference for group \(G=1\) minus group \(G=0\) is \(-6+1.5x\) points.
At \(x=2\), the difference is \(-6+(1.5)(2)=-3.0\) points. At \(x=8\), it is \(-6+(1.5)(8)=6.0\) points. The difference increases by \(6.0-(-3.0)=9.0\) points across the six-unit dose increase, which agrees with \((1.5)(8-2)=9.0\) points. The fitted lines cross where
At 4 dose units, the model gives equal fitted means for the two groups. Below 4 units, the fitted outcome is lower for \(G=1\); above 4 units, it is higher for \(G=1\). These are comparisons of fitted means, and they do not by themselves establish a causal effect of dose or group membership.
Common Mistake: Treating the Group Coefficient as the Difference Everywhere
A frequent error is to report \(\hat{\beta}_2\) as the group difference at every value of \(x\). That reasoning ignores the interaction term. In the model above, \(-6\) points is the fitted group difference only at \(x=0\); at 2 dose units, the difference is \(-6+(1.5)(2)=-3.0\) points, and at 8 dose units it is 6.0 points. The correction is to substitute the specified predictor value into \(\hat{\beta}_2+\hat{\beta}_3x\), keeping the group order explicit.
Also avoid comparing fitted outcomes at different predictor values when the question asks for a group difference. First hold \(x\) fixed for both groups, then subtract. Include the outcome units, state which group is subtracted from which, and avoid describing a fitted association as a causal effect without a suitable causal design and assumptions.
Check Your Understanding
Use the model and the group order stated in each question.
- For \(\widehat{Y}=10+2x+3G-0.4xG\), calculate the fitted difference for \(G=1\) minus \(G=0\) at \(x=5\). Include the outcome units if \(Y\) is measured in kilograms.
- In the same model, by how much does the fitted group difference change when \(x\) increases by 3 units? State the calculation.
- In a model with a centered predictor \(x_c=x-12\), what original predictor value does the group coefficient describe the fitted difference at?
- For a fitted group difference of \(8-2x\), at what predictor value do the fitted group means cross? What should be checked before interpreting that value?
- Explain why a positive interaction coefficient does not guarantee that the fitted difference is positive at every predictor value.