Tutorials › Regression Analysis (Undergraduate) › Worked Calculations for a Group-By-Continuous Interaction

Simple Slopes and Marginal Effects · Tutorial 390 of 991

Worked Calculations for a Group-By-Continuous Interaction

Use a fitted interaction model to calculate group-specific slopes and conditional group differences, then quantify the uncertainty in each calculation.

Intermediate 12 min read

What You'll Learn

  • Write a regression model using a binary group indicator and a quantitative predictor
  • Calculate and interpret the slope for each group
  • Calculate the difference between groups at a selected predictor value
  • Use coefficient variances and covariances to find standard errors for these effects
  • Construct and interpret confidence intervals for slopes and conditional differences
  • Explain why a zero point estimate does not by itself establish that groups are equal

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

$$ Y_i=\beta_0+\beta_1X_i+\beta_2G_i+\beta_3X_iG_i+\epsilon_i. $$

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\).

$$ \begin{aligned} \widehat{Y}_A(x)&=b_0+b_1x,\\ \widehat{Y}_B(x)&=(b_0+b_2)+(b_1+b_3)x,\\ \widehat{Y}_B(x)-\widehat{Y}_A(x)&=b_2+b_3x. \end{aligned} $$
Definition: With this coding, the Group A slope is \(\beta_1\), and the Group B slope is \(\beta_1+\beta_3\). The difference in fitted outcome between Group B and Group A at predictor value \(x\) is \(\beta_2+\beta_3x\). The interaction coefficient \(\beta_3\) is the difference between the two group-specific slopes.

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:

$$ b_0=70,\qquad b_1=0.90,\qquad b_2=-2.00,\qquad b_3=0.40. $$

Suppose the estimated covariance matrix for \((b_1,b_2,b_3)\), in the same coefficient order, is

$$ \begin{pmatrix} 0.22&0&0\\ 0&13&-1.60\\ 0&-1.60&0.20 \end{pmatrix}. $$

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

$$ SE(b_1)=\sqrt{0.22}=0.4690\text{ points per hour}. $$

Using \(t^*=1.983972\) for a two-sided 95% interval with \(df=100\), the Group A slope interval is

$$ 0.90\pm1.983972\sqrt{0.22} =0.90\pm0.9306 =(-0.0306,\ 1.8306)\text{ points per hour}. $$

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

$$ \operatorname{Var}(b_1+b_3) =0.22+0.20+2(0) =0.42. $$

Therefore, the Group B slope standard error is \(\sqrt{0.42}=0.6481\) points per hour, and its 95% interval is

$$ 1.30\pm1.983972\sqrt{0.42} =1.30\pm1.2858 =(0.0142,\ 2.586)\text{ points per hour}. $$

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:

$$ \operatorname{Var}(a b_j+c b_k) =a^2\operatorname{Var}(b_j)+c^2\operatorname{Var}(b_k) +2ac\operatorname{Cov}(b_j,b_k). $$

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

$$ \widehat{\operatorname{Var}}(b_2+xb_3) =\operatorname{Var}(b_2)+x^2\operatorname{Var}(b_3) +2x\operatorname{Cov}(b_2,b_3). $$

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

$$ -2.00\pm1.983972\sqrt{13} =-2.00\pm7.1533 =(-9.1533,\ 5.1533)\text{ points}. $$

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

$$ b_2+8b_3=-2.00+8(0.40)=1.20\text{ points}. $$

Its estimated variance uses the covariance term:

$$ \begin{aligned} \widehat{\operatorname{Var}}(b_2+8b_3) &=13+8^2(0.20)+2(8)(-1.60)\\ &=13+12.8-25.6\\ &=0.20. \end{aligned} $$

The standard error is \(\sqrt{0.20}=0.4472\) points. The 95% confidence interval is therefore

$$ 1.20\pm1.983972\sqrt{0.20} =1.20\pm0.8873 =(0.3127,\ 2.0873)\text{ points}. $$

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

$$ b_2+5b_3=-2.00+5(0.40)=0.00\text{ points}. $$

Its variance and standard error are

$$ \begin{aligned} \widehat{\operatorname{Var}}(b_2+5b_3) &=13+5^2(0.20)+2(5)(-1.60)\\ &=13+5-16\\ &=2,\\ SE(b_2+5b_3)&=\sqrt{2}=1.414\text{ points}. \end{aligned} $$

The 95% confidence interval is

$$ 0.00\pm1.983972\sqrt{2} =(-2.806,\ 2.806)\text{ points}. $$

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

Common mistake: “The coefficient \(b_2\) is the group difference, so Group B is always 2 points below Group A.” This is only the fitted difference at \(x=0\). The group difference at predictor value \(x\) is \(b_2+xb_3\), which varies with \(x\) when the interaction is present. Calculate that conditional contrast and its standard error at the value of interest.

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.

Key takeaway: With a binary group indicator and a quantitative predictor, calculate each group’s slope from the relevant coefficients and calculate the group difference as a function of the predictor value. For either quantity, use the full coefficient covariance information to obtain its standard error and interval.

Check Your Understanding

Use the fitted results in this tutorial unless a question asks for a general explanation.

  1. Write the fitted mean equation for each group and identify each group’s slope in points per hour.
  2. What is the estimated Group B minus Group A difference at six study hours? Show the coefficient combination and arithmetic.
  3. Why does the variance calculation for a conditional group difference include a covariance term?
  4. At five hours, the estimated difference is zero. Does that establish that the population group means are exactly equal at five hours? Explain.
  5. State the units of a group-specific slope and of a conditional group difference, and explain why they differ.