From an Interaction Equation to a Plot
An interaction between two quantitative predictors means that the fitted relationship between the outcome and one predictor changes with the value of the other. A plot can make that pattern easier to see: put one predictor on the horizontal axis, calculate a fitted line at each of several selected values of the other predictor, and compare the lines’ slopes.
The lines are calculated from one fitted model. They are not separate fits to different groups of observations. Their positions and slopes come from substituting the selected predictor values into the same interaction equation.
The model describes a conditional mean that is linear in \(x\), \(z\), and their product. For the usual regression interpretation, the errors have mean zero conditional on the predictors; observations are independent, and the errors have constant variance. These assumptions concern the model and its errors, not the arithmetic of drawing its fitted lines. A plot of fitted values can be constructed from the equation, but the plot alone does not verify the assumptions.
Why the Lines Have Different Slopes
To plot fitted outcome against \(x\), hold \(z\) at some chosen value \(z_0\). Substitute \(z_0\) into the fitted equation and gather the constant terms and the terms involving \(x\):
This is a straight line. Its vertical intercept is \(b_0+b_2z_0\), and its slope with respect to \(x\) is \(b_1+b_3z_0\). The derivation also shows why the lines can differ: changing \(z_0\) changes the slope by way of the product coefficient \(b_3\). For two selected values \(z_L\) and \(z_H\), the difference between the slopes is
Thus, if \(b_3\) is positive, the fitted slope for \(x\) increases as \(z\) increases; if \(b_3\) is negative, it decreases. If \(b_3=0\), all these fitted lines have the same slope, though their intercepts can still differ. Reversing the axes gives the corresponding result for plotting against \(z\) at selected values of \(x\).
Worked Example: Plotting Study-Time Lines
Suppose a hypothetical fitted model predicts an exam score from study time \(x\), in hours, and a preparation measure \(z\), in points:
Assume the observed values of \(z\) range from 1 to 5 points, and consider lines at \(z=1\), \(z=3\), and \(z=5\). For each selected value, substitute into the equation and collect the terms involving \(x\).
At \(z=1\), the intercept is \(50+1=51\), and the slope is \(2+0.4(1)=2.4\). The line is \(\hat{y}=51+2.4x\). At \(z=3\), the intercept is \(50+3=53\), and the slope is \(2+0.4(3)=3.2\), giving \(\hat{y}=53+3.2x\). At \(z=5\), the intercept is \(50+5=55\), and the slope is \(2+0.4(5)=4.0\), giving \(\hat{y}=55+4.0x\).
For example, at \(x=2\) hours, the fitted scores are \(51+2.4(2)=55.8\), \(53+3.2(2)=59.4\), and \(55+4.0(2)=63.0\) points. At \(x=4\) hours, they are \(51+2.4(4)=60.6\), \(53+3.2(4)=65.8\), and \(55+4.0(4)=71.0\) points.
| Preparation value \(z\) | Line plotted against \(x\) | Fitted score at \(x=2\) | Fitted score at \(x=4\) |
|---|---|---|---|
| 1 point | \(\hat{y}=51+2.4x\) | 55.8 points | 60.6 points |
| 3 points | \(\hat{y}=53+3.2x\) | 59.4 points | 65.8 points |
| 5 points | \(\hat{y}=55+4.0x\) | 63.0 points | 71.0 points |
On a plot, use study time in hours on the horizontal axis and fitted exam score in points on the vertical axis. Plot each line using its fitted coordinates, label it with its preparation value, and connect the coordinates with a straight line. The slopes increase with \(z\) because \(b_3=0.4\) is positive: the model’s fitted increase in score per additional hour of study is 2.4, 3.2, or 4.0 points per hour at the respective preparation values. This is a statement about fitted associations, not evidence that changing study time or preparation causes a score change.
Reading the Shape of the Lines
An interaction plot can show several patterns. Lines with the same slope are parallel, so the fitted association between the horizontal-axis predictor and the outcome does not vary across the selected values of the other predictor. Lines that fan apart or draw closer have differing slopes. Lines with slopes of opposite signs show that the fitted association changes direction across the selected values. The equation, rather than the visual angle alone, determines the exact slope.
The vertical separation of two lines at a particular horizontal-axis value is a difference in fitted outcomes at that value. It need not be constant across the plot when the slopes differ. The plot’s line labels and axis units therefore matter: a slope is measured in outcome units per unit of the horizontal predictor, conditional on the specified value of the other predictor.
Worked Example: Lines That Change Direction
Suppose a hypothetical model predicts daily heating energy use \(y\), in kilowatt-hours, from outdoor temperature \(x\), in degrees Celsius, and an insulation rating \(z\):
Consider temperatures from \(0\) to \(6\) degrees Celsius and insulation ratings \(z=1\), \(z=3\), and \(z=5\). At each rating, the intercept is \(30+3z\) and the slope with respect to temperature is \(2-0.6z\), in kilowatt-hours per degree Celsius.
For \(z=1\), the intercept is \(33\) kilowatt-hours and the slope is \(2-0.6(1)=1.4\), so \(\hat{y}=33+1.4x\). At \(x=3\), this gives \(33+1.4(3)=37.2\) kilowatt-hours; at \(x=6\), it gives \(41.4\) kilowatt-hours.
For \(z=3\), the intercept is \(39\) kilowatt-hours and the slope is \(2-0.6(3)=0.2\), so \(\hat{y}=39+0.2x\). The fitted values at \(x=3\) and \(x=6\) are \(39.6\) and \(40.2\) kilowatt-hours. For \(z=5\), the intercept is \(45\) kilowatt-hours and the slope is \(2-0.6(5)=-1.0\), so \(\hat{y}=45-1.0x\). The fitted values at \(x=3\) and \(x=6\) are \(42.0\) and \(39.0\) kilowatt-hours.
| Insulation rating \(z\) | Fitted line | At \(x=0\) | At \(x=3\) | At \(x=6\) |
|---|---|---|---|---|
| 1 | \(\hat{y}=33+1.4x\) | 33 kWh | 37.2 kWh | 41.4 kWh |
| 3 | \(\hat{y}=39+0.2x\) | 39 kWh | 39.6 kWh | 40.2 kWh |
| 5 | \(\hat{y}=45-1.0x\) | 45 kWh | 42.0 kWh | 39.0 kWh |
The three slopes are positive, slightly positive, and negative. The lines therefore rise, rise only gently, and fall, respectively. This pattern follows from the negative product coefficient: each one-point increase in \(z\) lowers the fitted temperature slope by \(0.6\) kilowatt-hours per degree Celsius. The equation gives the exact changes; the plot makes their differing directions visible.
A Plotting Procedure
A useful interaction plot is straightforward to construct once the model and the selected values are clear. Use the same horizontal-axis scale for all lines, and calculate fitted outcomes at several \(x\) values for each selected \(z\). A table of coordinates helps prevent mistakes in drawing and labeling the lines.
Decide which predictor will vary along the horizontal axis. In this tutorial’s examples, that predictor is \(x\), and the other predictor \(z\) is held fixed for each line.
For every chosen \(z_0\), replace \(z\) by \(z_0\) in the fitted equation. Collect terms to identify the line’s intercept and slope.
Evaluate each line at common horizontal-axis values. Show the arithmetic and retain the units of the outcome.
Plot the coordinates, draw the fitted straight lines, and identify each line by its fixed predictor value. Label both axes with predictor or outcome names and units.
Worked Example: Building Coordinates for an Interaction Plot
A hypothetical model predicts visit delay \(y\), in minutes, from appointment load \(x\), measured in additional appointments, and staff experience \(z\), in years:
Suppose the plotted horizontal values are \(x=0\), \(x=5\), and \(x=10\), and the selected experience values are \(z=10\), \(z=20\), and \(z=30\) years. At \(z=10\), the intercept is \(8+0.2(10)=10\) minutes and the slope is \(0.5+0.03(10)=0.8\) minutes per additional appointment. Its fitted line is \(\hat{y}=10+0.8x\), giving \(10\), \(14\), and \(18\) minutes at the three horizontal values.
At \(z=20\), the intercept is \(8+0.2(20)=12\) minutes and the slope is \(0.5+0.03(20)=1.1\) minutes per additional appointment. The line is \(\hat{y}=12+1.1x\), giving \(12\), \(17.5\), and \(23\) minutes. At \(z=30\), the intercept is \(8+0.2(30)=14\) minutes and the slope is \(0.5+0.03(30)=1.4\) minutes per additional appointment. The line is \(\hat{y}=14+1.4x\), giving \(14\), \(21\), and \(28\) minutes.
| Experience \(z\) | \(x=0\) | \(x=5\) | \(x=10\) |
|---|---|---|---|
| 10 years | 10 min | 14 min | 18 min |
| 20 years | 12 min | 17.5 min | 23 min |
| 30 years | 14 min | 21 min | 28 min |
Plot the three coordinate sets on the same axes and label them by experience. Since the interaction coefficient is \(0.03\), the fitted slope increases by \(0.03\) minutes per additional appointment for each one-year increase in experience. For example, the slope at 30 years is \(1.4-0.8=0.6\) minutes per appointment greater than the slope at 10 years, matching \(0.03(30-10)=0.6\). This calculation links the visible difference in line steepness to the model coefficient.
What the Plot Does—and Does Not—Show
An interaction plot summarizes fitted outcomes from the specified model. It helps readers compare the conditional slopes and see how fitted lines are positioned relative to one another. The lines do not display individual observations unless observed data are added separately, and they do not show uncertainty around the fitted predictions.
In particular, an apparent crossing or separation in the plot is a feature of the fitted equations at the displayed values. It is not, by itself, a test of whether the interaction is statistically distinguishable from zero. Nor does a steeper fitted line establish a causal effect. Interpret the plot as a visual presentation of the model’s fitted relationships, with predictor values and units clearly stated.
Common Mistake
Wrong reasoning: “The product coefficient is the slope of the line for the highest value of \(z\), so I will use it as that line’s slope.”
Correction: The product coefficient describes how the slope changes with \(z\); it is not usually the conditional slope itself. For a plot of \(\hat{y}\) against \(x\) at \(z=z_0\), calculate the slope as \(b_1+b_3z_0\). For example, with \(b_1=2\), \(b_3=0.4\), and \(z_0=5\), the slope is \(2+0.4(5)=4.0\), not \(0.4\). The product coefficient also determines how much that slope changes for a one-unit increase in \(z\).
Check Your Understanding
Use the interaction equation and the plotting principles in this tutorial to answer the following questions.
- For \(\hat{y}=4+3x+2z-0.5xz\), write the fitted line against \(x\) when \(z=2\). State its intercept and slope.
- For the same equation, how much does the slope against \(x\) change when \(z\) increases by 1? Which coefficient determines this change?
- At \(z=0\), what is the fitted slope against \(x\)? Explain why it is not generally the slope at other values of \(z\).
- What information should be included in the labels for an interaction plot of fitted outcomes?
- Does a plot of fitted lines alone establish that an interaction is statistically significant or causal? Explain briefly.