Introduction
When a quantitative predictor has different relationships with an outcome in two groups, one regression line cannot describe both relationships with the same slope. A group-by-continuous interaction represents that difference directly. It also means that the group difference is not necessarily constant: it can depend on the value of the quantitative predictor.
This tutorial works through the calculations for both parts of that interaction. We will find each group’s slope, compare the groups at specified predictor values, and use the estimated coefficient covariances to quantify uncertainty. All data and numerical results below are hypothetical.
The Model and the Quantities of Interest
Let \(Y_i\) be an outcome measured in points, \(X_i\) a quantitative predictor measured in hours, and \(G_i\) a group indicator coded \(0\) for Group A and \(1\) for Group B. A linear regression model with a group-by-continuous interaction is
The fitted conditional mean for Group A follows by setting \(G_i=0\). For Group B, set \(G_i=1\). Subtracting the two fitted means gives the group difference at a particular value of \(X\).
The calculations below use the model-based \(t\) procedures for least-squares regression. For these procedures, assume the conditional mean has the stated linear form; observations are independent; the errors have mean zero conditional on \(X\) and \(G\), with constant variance; and the errors are normally distributed for exact \(t\)-based intervals. The design must also have enough variation to estimate all four coefficients (no perfect collinearity). If the model or assumptions are not appropriate, the reported standard errors and intervals may not be reliable.
Hypothetical Fitted Results
Suppose a hypothetical study records quiz scores for 104 students, with study hours ranging from 0 to 10 in each group. The fitted model has four coefficients, so the residual degrees of freedom are \(104-4=100\). The fitted coefficients are:
Suppose the estimated covariance matrix for \((b_1,b_2,b_3)\), in the same coefficient order, is
Thus, for example, \(\operatorname{Var}(b_2)=13\), \(\operatorname{Var}(b_3)=0.20\), and \(\operatorname{Cov}(b_2,b_3)=-1.60\). These covariance values are essential: a standard error for a sum of coefficients cannot generally be found by adding their standard errors. The specified covariance matrix is positive definite, so its variances and covariances are internally compatible.
Worked Example: Calculating and Comparing the Group Slopes
The Group A slope is \(b_1=0.90\) points per hour. For Group B, add the interaction coefficient: \(b_1+b_3=0.90+0.40=1.30\) points per hour. Thus, in this fitted model, each additional study hour is associated with an increase of 0.90 predicted quiz points for Group A and 1.30 predicted quiz points for Group B.
The estimated variance of the Group A slope is \(\operatorname{Var}(b_1)=0.22\), so its standard error is
Using \(t^*=1.983972\) for a two-sided 95% interval with \(df=100\), the Group A slope interval is
For Group B, the slope estimate is \(b_1+b_3\). Because \(\operatorname{Cov}(b_1,b_3)=0\) in these hypothetical results, its variance is
Therefore, the Group B slope standard error is \(\sqrt{0.42}=0.6481\) points per hour, and its 95% interval is
Each interval describes uncertainty about its group’s slope under the stated model and assumptions. Their overlap or lack of overlap is not, by itself, a formal test of whether the slopes differ; the slope difference is the interaction coefficient \(b_3\).
Uncertainty for a Linear Combination
Both a group-specific slope and a conditional group difference are linear combinations of fitted coefficients. For any two coefficient estimates \(b_j\) and \(b_k\), the variance of their weighted sum includes their covariance:
The final term can increase or decrease the variance. The same principle applies to combinations involving more coefficients: multiply the coefficient covariance matrix on the left and right by the vector of weights. For example, the conditional group difference at \(x\) is \(b_2+xb_3\), so its estimated variance is
A two-sided 95% confidence interval for such an estimated effect is its estimate plus or minus \(t^*\) times its standard error, using the residual degrees of freedom. The interval concerns the corresponding population effect, not an individual outcome.
Worked Example: The Group Difference at Zero Study Hours
At \(x=0\), the estimated difference between Group B and Group A is \(b_2+0b_3=b_2=-2.00\) points. Its standard error is \(\sqrt{\operatorname{Var}(b_2)}=\sqrt{13}=3.606\) points. The 95% confidence interval is
At zero study hours, the model estimates Group B’s mean score to be 2 points lower than Group A’s. However, this interval includes zero and ranges from a substantial negative difference to a positive one. The data, under this model, do not determine the direction of the difference precisely. Because zero hours lies within the stated observed range for both groups, this calculation does not require extrapolation beyond the example’s support.
Worked Example: The Group Difference at Eight Study Hours
At \(x=8\), the estimated Group B minus Group A difference is
Its estimated variance uses the covariance term:
The standard error is \(\sqrt{0.20}=0.4472\) points. The 95% confidence interval is therefore
At eight study hours, the fitted mean score for Group B is 1.20 points higher than the fitted mean for Group A. The interval is entirely above zero, indicating a positive conditional difference at this predictor value at the 5% two-sided level, given the model and assumptions. It does not establish that group membership causes a score difference.
A Crossover in the Fitted Differences
The fitted group difference changes with \(x\) because the slope difference is positive. In this example, the point at which the fitted lines are equal solves \(-2.00+0.40x=0\), giving \(x=5\) hours. A zero fitted difference at that one point does not mean the groups have equal fitted means at all study-hour values.
Worked Example: Difference at the Fitted Crossover
At \(x=5\), the estimated Group B minus Group A difference is
Its variance and standard error are
The 95% confidence interval is
The fitted lines meet at five hours, but the interval shows uncertainty about the population difference there. Its inclusion of zero is consistent with the fitted equality, while also allowing nonzero differences. The point estimate alone should not be treated as proof of exact equality.
Why the Covariance Term Matters
In the eight-hour calculation, the separate variance contributions are 13 and 12.8, while the covariance contribution is \(-25.6\). Because the coefficient estimates are negatively correlated, their weighted sum is much less variable than it would be if the covariance were ignored. The variance is \(0.20\), not \(13+12.8=25.8\). In other settings, a positive covariance can instead increase the variance.
This calculation illustrates why it is unsafe to combine coefficient standard errors by simply adding them, or to omit the covariance term because it is inconvenient. Use the estimated covariance matrix for the particular fitted model. Also keep the effect’s context clear: a slope has units of points per hour, whereas a difference between group means at a fixed number of hours has units of points.
Common Mistake
A related error is to calculate the standard error of \(b_2+xb_3\) from the two coefficient standard errors alone. The correct variance includes \(2x\operatorname{Cov}(b_2,b_3)\); omitting it can produce a seriously inaccurate interval, as the eight-hour example demonstrates.
Check Your Understanding
Use the fitted results in this tutorial unless a question asks for a general explanation.
- Write the fitted mean equation for each group and identify each group’s slope in points per hour.
- What is the estimated Group B minus Group A difference at six study hours? Show the coefficient combination and arithmetic.
- Why does the variance calculation for a conditional group difference include a covariance term?
- At five hours, the estimated difference is zero. Does that establish that the population group means are exactly equal at five hours? Explain.
- State the units of a group-specific slope and of a conditional group difference, and explain why they differ.