Why Plot Group Fits and Their Differences?
An interaction between a quantitative predictor and a group means that the fitted relationship between the predictor and outcome can differ across groups. A plot of the fitted line for each group makes those patterns visible. A second plot, showing the difference between the group fits over predictor values, makes it easier to see whether the gap is constant, changing, or changing direction.
Uncertainty belongs in these displays too. Fitted lines are estimates, not known population relationships. A plot can show pointwise confidence intervals for each group’s fitted mean and for the difference between fitted means. These intervals answer different questions, so they should be labelled clearly.
Model and Plotting Quantities
For two groups, let \(G=0\) identify group 0 and \(G=1\) identify group 1, and let \(x\) be a quantitative predictor. Consider the linear interaction model
The fitted group-specific lines, obtained by substituting each group’s value of \(G\), are
Here \(\widehat{Y}_g(x)\) is the estimated mean outcome for group \(g\) at predictor value \(x\). The fitted difference, defined as group 1 minus group 0, is
Thus, the difference plot is a straight line: its intercept is \(\hat{\beta}_2\), and its slope is \(\hat{\beta}_3\). A positive fitted difference means the group 1 fitted mean is higher at that \(x\); a negative one means it is lower. The signed vertical separation between the two fitted lines at any \(x\) equals the difference shown on this plot; the geometric distance is its absolute value.
For the usual linear regression interpretation, assume the conditional mean is linear within each group, observations are independent, and errors have mean zero given the predictors and group. The usual coefficient covariance estimates and standard errors also rely on an appropriate error-variance model; the familiar classical formulas assume constant error variance. Normal errors support exact small-sample \(t\) inference, while large-sample normal approximations are often used for Wald intervals. A plot does not establish these assumptions: residual and design checks are still needed.
Worked Example: Sketching the Fits and the Changing Gap
Worked Example: Sketching the Fits and the Changing Gap
Suppose hypothetical fitted lines for two groups are \(\widehat{Y}_0(x)=12+2x\) and \(\widehat{Y}_1(x)=8+3.5x\). The observed predictor values in both groups range from 0 to 6. Find and interpret the group difference at several values, and describe what the two plots should show.
Subtract the group 0 fit from the group 1 fit:
Substitution gives the following values:
| Predictor value \(x\) | Group 0 fit | Group 1 fit | Group 1 minus group 0 |
|---|---|---|---|
| 0 | 12 | 8 | -4 |
| 2 | 16 | 15 | -1 |
| 4 | 20 | 22 | 2 |
| 6 | 24 | 29 | 5 |
For example, at \(x=4\), the fitted mean for group 1 is \(8+3.5(4)=22\), while that for group 0 is \(12+2(4)=20\). The fitted group 1 mean is therefore 2 outcome units higher at \(x=4\). The difference changes by 1.5 outcome units for each one-unit increase in \(x\), because the fitted slopes differ by \(3.5-2=1.5\).
The difference is zero when \(-4+1.5x=0\), so \(x=4/1.5\approx2.667\). On the fitted-line plot, the lines cross at that predictor value. On the difference plot, the line rises from \(-4\) at \(x=0\), crosses zero at approximately \(2.667\), and reaches \(5\) at \(x=6\). These are fitted relationships, not evidence that changing \(x\) causes the outcome to change.
Calculating Uncertainty for a Plotted Difference
A difference plot should not be created by subtracting confidence-interval endpoints for the separate group fits. Instead, calculate the standard error of the difference using the covariance of the fitted quantities. If the group-specific coefficient estimates come from independent observations in disjoint groups, their cross-group covariance is zero. Within each group, however, the estimated intercept and slope can be correlated.
Write the group 0 coefficient estimates as \(\hat{a}_0,\hat{b}_0\) and group 1 estimates as \(\hat{a}_1,\hat{b}_1\). Then \(\widehat{Y}_g(x)=\hat{a}_g+\hat{b}_gx\), and
When the group fits are independent, the variance of their difference is the sum of these two fitted-mean variances. In the more general case, the covariance between the fitted means must also be included:
The standard error is the square root of the estimated variance. A large-sample pointwise 95% Wald interval for the difference is \(\widehat{\Delta}(x)\pm1.96SE\{\widehat{\Delta}(x)\}\). For an exact small-sample interval under the classical normal-error assumptions, use the appropriate \(t\) critical value and degrees of freedom instead.
Worked Example: Adding Pointwise Uncertainty
Worked Example: Adding Pointwise Uncertainty
Return to the fitted lines \(12+2x\) and \(8+3.5x\). Suppose independent group-specific fits have estimated coefficient covariance matrices, with each ordered as intercept then slope,
Assume the large-sample normal approximation is appropriate. At \(x=2\), the fitted means are \(12+2(2)=16\) and \(8+3.5(2)=15\), so the fitted difference is \(15-16=-1\). For group 0, the estimated variance of its fitted mean is
For group 1, the corresponding calculation is
Because the fits use independent groups, the estimated variance of the difference is \(0.52+0.322=0.842\), and its standard error is \(\sqrt{0.842}\approx0.9176\). The approximate pointwise 95% interval is
At \(x=2\), the data are compatible with a population difference ranging from about 2.798 outcome units lower for group 1 to about 0.798 units higher, under the model and approximation used. Since zero is in this interval, it does not indicate a nonzero difference at the 5% two-sided level using this interval procedure.
The fitted group means have their own pointwise intervals: approximately \(16\pm1.96(0.7211)=[14.59,17.41]\) for group 0 and \(15\pm1.96(0.5675)=[13.89,16.11]\) for group 1. These intervals are not a substitute for the interval for their difference. The latter uses the standard error of the contrast directly.
How the Same Uncertainty Appears in Interaction Coefficients
The covariance calculation must remain coherent when a model is expressed using an overall intercept and slope plus interaction terms. In the model above, group 0 has coefficients \((\beta_0,\beta_1)\), while group 1 has \((\beta_0+\beta_2,\beta_1+\beta_3)\). For independent group fits, these two pairs of estimated group-specific coefficients have zero cross-group covariance. It does not follow that every covariance involving the interaction coefficients is zero.
Worked Example: Checking a Coefficient Covariance Calculation
Suppose the group-specific covariance matrices are those in the preceding example. In the overall interaction parameterization, the coefficient estimates are ordered as \((\hat{\beta}_0,\hat{\beta}_1,\hat{\beta}_2,\hat{\beta}_3)\). Since \(\hat{\beta}_0=\hat{a}_0\), \(\hat{\beta}_1=\hat{b}_0\), \(\hat{\beta}_2=\hat{a}_1-\hat{a}_0\), and \(\hat{\beta}_3=\hat{b}_1-\hat{b}_0\), their estimated covariance matrix is
For example, \(\widehat{\mathrm{Cov}}(\hat{\beta}_0,\hat{\beta}_2)=\widehat{\mathrm{Cov}}(\hat{a}_0,\hat{a}_1-\hat{a}_0)=0-0.64=-0.64\). The zero here is the covariance between the group-specific estimates \(\hat{a}_0\) and \(\hat{a}_1\); it is not the covariance between \(\hat{\beta}_0\) and \(\hat{\beta}_2\). Likewise, \(\widehat{\mathrm{Cov}}(\hat{\beta}_2,\hat{\beta}_3)=-0.012-0.04=-0.052\), because the group-specific intercept-slope covariances are \(-0.012\) and \(-0.04\).
At \(x=2\), the estimated difference is \(\hat{\beta}_2+2\hat{\beta}_3=-4+2(1.5)=-1\). Its variance from the interaction coefficients is
This matches the variance obtained by adding the two independent group-specific fitted-mean variances. The matching results check that the covariance matrix and the plotted difference use the same model and uncertainty assumptions.
Designing and Reading the Plots
A clear display usually includes a fitted-line plot and a difference plot, with predictor and outcome units stated. Draw the group-specific fitted lines over the predictor values represented by the observations, and identify each group in a legend. If the purpose is to show uncertainty, add pointwise intervals around each fitted mean or use a shaded pointwise band. Label these as intervals for the mean response, not as ranges expected to contain individual observations.
The difference plot should label its vertical axis with the direction of subtraction, such as “group 1 minus group 0,” and its horizontal reference line at zero. Add pointwise intervals for the difference if uncertainty is relevant. A line above zero indicates a higher fitted mean for group 1; a line below zero indicates a lower fitted mean. Where a pointwise interval contains zero, that interval does not rule out a zero population difference at that particular \(x\) using the stated procedure.
A confidence interval for a fitted mean describes uncertainty in the estimated conditional mean. A prediction interval instead concerns a future individual outcome and includes individual-level residual variation, so it is wider under the usual model. The two should not be labelled interchangeably. Also, a set of pointwise 95% intervals should not be described as a 95% simultaneous confidence band for the whole line: simultaneous coverage requires a procedure designed for that purpose.
Common Mistakes
- Subtracting interval endpoints. The difference interval is not generally obtained by subtracting the lower endpoints and upper endpoints of the two group intervals. Calculate the contrast’s standard error, including covariance where needed.
- Assuming all interaction-parameter covariances are zero. Independent group-specific fits imply zero covariance between estimates from different groups. When those estimates are rewritten as an overall coefficient and differences, covariances with interaction coefficients are generally not zero.
- Hiding the direction of the difference. “A gap of 2” is incomplete unless the subtraction order is stated. If the plotted quantity is group 1 minus group 0, a value of 2 means group 1’s fitted mean is 2 outcome units higher.
- Calling a mean-response interval a prediction interval. The first concerns uncertainty in a conditional mean; the second concerns a future individual outcome and includes residual variation.
- Reading a fitted crossing as proof of a population crossing. The estimated lines may cross even when their uncertainty is substantial. Interpret the crossing alongside uncertainty and the observed data, not as a certain feature of the population.
Check Your Understanding
Use the definitions and calculations above to answer these questions.
- If \(\widehat{Y}_0(x)=5+1.2x\) and \(\widehat{Y}_1(x)=3+2x\), write the group 1 minus group 0 difference line and find the fitted difference at \(x=4\).
- In the usual interaction model, which coefficient determines how quickly the fitted group difference changes with \(x\)?
- Why is the variance of the difference the sum of the fitted-mean variances for independent group-specific fits?
- What does a pointwise confidence interval for a group difference describe, and what does it not guarantee about the whole plotted curve?
- Explain why the covariance between an overall intercept estimate and an interaction intercept estimate need not be zero, even when the group-specific fits use independent observations.