One Regression Equation, a Separate Line for Each Group
When a quantitative predictor relates differently to an outcome in different groups, a single common slope is not enough to describe the fitted relationship. A group-by-predictor interaction allows the fitted slope to vary by group. The same regression equation then gives a separate fitted line for each group, making it possible to calculate and compare fitted means at particular predictor values.
The calculations depend on keeping track of the group coding and applying every term in the equation. In particular, the product term combines the group indicator with the quantitative predictor: it contributes nothing for the reference group, but changes both the intercept and the slope for the other group.
The Group-Specific Slope Model
The interaction coefficient \(\beta_3\) allows the slope to differ between groups. To calculate a fitted mean, replace the unknown population coefficients with their estimated values, written \(b_0,b_1,b_2,b_3\). Denote the resulting fitted conditional mean at predictor value \(x\) and group \(g\) by \(\hat{\mu}(x,g)\).
The model assumes that the conditional mean is linear in \(X\) within each group and that the groups are represented by the stated indicator coding. For the coefficients to describe those conditional means, the error must have conditional mean zero given \(X\) and \(G\). The arithmetic also requires using the predictor in the same units and form used to fit the equation. Predictions well outside the observed predictor range rely on extending the fitted lines beyond the data and should be treated cautiously.
Deriving Each Group’s Fitted Line
Set \(g=0\) for the reference group. Both terms containing \(g\) become zero, leaving the reference group’s fitted mean. Set \(g=1\) for the other group; then its indicator term adds to the intercept and its product term adds to the slope.
Thus, the reference group has fitted intercept \(b_0\) and slope \(b_1\). The group coded \(1\) has fitted intercept \(b_0+b_2\) and slope \(b_1+b_3\). The coefficient \(b_2\) is the difference in fitted intercepts, and \(b_3\) is the difference in fitted slopes, with the group coded \(1\) compared with the reference group.
At a shared predictor value \(x\), subtracting the reference-group fitted mean from the group-1 fitted mean gives
This difference may vary with \(x\). It is a difference between fitted conditional means at the same predictor value, not automatically a causal effect of group membership.
Worked Example: Calculating Both Group Lines and Comparing Predictions
Suppose a hypothetical model predicts a training assessment score \(Y\), measured in points, from practice hours \(X\). Group A is coded \(G=0\) and Group B is coded \(G=1\). The fitted equation is
First, write the fitted line for each group. For Group A, \(g=0\), so
For Group B, \(g=1\), so its intercept is \(12+4=16\) points and its slope is \(2.5-0.8=1.7\) points per practice hour:
At 2 practice hours, the fitted mean for Group A is
For Group B, it is
At 2 hours, the fitted mean for Group B is \(19.4-17=2.4\) points higher than the fitted mean for Group A. This is a comparison of model-based means at the same practice time.
At 6 practice hours, the fitted means are
At 6 hours, Group B’s fitted mean is \(26.2-27=-0.8\) points lower. The direction of the fitted difference changes with practice hours because the groups have different fitted slopes. Both calculations follow the same equation; only \(x\) and the group indicator change.
A Reliable Calculation Process
Writing out the group-specific equations before substituting values reduces the chance of dropping an interaction term or using the wrong group code. For each requested prediction, record the group, the predictor value and the units, then substitute into that group’s line.
Identify which group has \(G=0\) and which has \(G=1\), as specified for the fitted equation.
Use \(b_0+b_1x\) for \(G=0\) and \((b_0+b_2)+(b_1+b_3)x\) for \(G=1\).
Insert the value of \(x\) into the correct group’s fitted line and show the arithmetic.
State the fitted mean in outcome units. For a group comparison at the same \(x\), subtract the fitted means and preserve the direction of subtraction.
Worked Example: Using the Indicator in the Original Equation
In a hypothetical example, \(Y\) is delivery time in minutes, \(X\) is distance in kilometres, Group A is coded \(G=0\), and Group B is coded \(G=1\). Suppose the fitted equation is
Calculate the fitted mean delivery times for both groups at a distance of 4 km.
Group A. Set \(g=0\) in the original equation. The terms \(-5g\) and \(1.1xg\) are zero:
Group B. Set \(g=1\):
At 4 km, the fitted mean for Group B is \(30.2-30.8=-0.6\) minutes relative to Group A, so the model’s fitted mean is 0.6 minutes lower for Group B at that distance. Checking the group-specific form gives the same result: Group A’s line is \(18+3.2x\), while Group B’s is \(13+4.3x\). The predictor value contributes to both the ordinary slope term and, for Group B, the interaction term.
Predictions at Several Values
A short table can make the changing fitted difference clear. The entries must still come from the appropriate group-specific lines; a table does not replace the substitution and arithmetic. The following hypothetical example uses those lines to calculate fitted conditional means at three values of the predictor.
Worked Example: Making a Table of Fitted Means
Suppose \(Y\) is a plant’s height in centimetres and \(X\) is the number of weeks since measurement began. Group 0 and Group 1 are two hypothetical growing conditions. A fitted interaction model gives
At \(x=0\), the fitted means are \(10+1.4(0)=10\) cm for Group 0 and \(12+0.9(0)=12\) cm for Group 1. At \(x=5\), they are \(10+1.4(5)=17\) cm and \(12+0.9(5)=16.5\) cm. At \(x=10\), they are \(10+1.4(10)=24\) cm and \(12+0.9(10)=21\) cm.
| Weeks, \(x\) | Group 0 fitted mean (cm) | Group 1 fitted mean (cm) | Group 1 minus Group 0 (cm) |
|---|---|---|---|
| 0 | 10 | 12 | 2 |
| 5 | 17 | 16.5 | -0.5 |
| 10 | 24 | 21 | -3 |
The difference can also be calculated directly: \(\hat{\mu}(x,1)-\hat{\mu}(x,0)=(12-10)+(0.9-1.4)x=2-0.5x\) cm. It gives \(2\) cm at week 0, \(-0.5\) cm at week 5, and \(-3\) cm at week 10, matching the table. These fitted values describe the model’s conditional means for the specified groups and weeks; they do not say that changing a plant’s condition would cause the difference shown.
Common Mistakes and Why the Details Matter
A frequent error is to interpret \(b_1\) as the slope for both groups. In this model, \(b_1\) is the reference-group slope; the slope for the group coded \(1\) is \(b_1+b_3\). Similarly, \(b_2\) alone is the group difference in fitted means only at \(x=0\), because the general difference is \(b_2+b_3x\). If zero is not a meaningful or observed predictor value, that intercept difference may have little practical relevance, even though the fitted predictions at observed values can still be useful.
Another mistake is to substitute \(g=1\) into the main-effects terms but omit \(b_3xg\). That omission forces the two groups to have the same slope and no longer represents the stated interaction model. Always include the product term in the original equation, or use the group-specific line derived from it.
Finally, a fitted conditional mean is not a guarantee about an individual outcome. For example, a fitted mean delivery time of 30.2 minutes does not say that every delivery in that group and at that distance will take 30.2 minutes. It is the model’s estimated mean outcome for observations with the specified predictor value and group. Keep the outcome units, predictor units, group coding, and context attached to every reported prediction.
Check Your Understanding
Use the model and coding in each question; show the substitution that supports your answer.
- For \(\hat{\mu}(x,g)=7+1.8x+3g-0.4xg\), write the fitted line for each group coded \(0\) and \(1\).
- Using that model, calculate both fitted means at \(x=5\). What is the fitted mean for Group 1 minus the fitted mean for Group 0?
- In a group-specific slope model, what do \(b_1\) and \(b_1+b_3\) represent?
- Why is \(b_2\) not generally the difference in fitted means between the groups at every predictor value?
- A fitted conditional mean is 42 points for one group at a specified predictor value. Does this mean every individual in that group at that value has an outcome of 42 points? Explain.