Tutorials › Econometrics (Graduate) › Interactions and Conditional Slopes

Linear Projection and OLS · Tutorial 96 of 952

Interactions and Conditional Slopes

See how an interaction lets a regression slope depend on another regressor, and learn to interpret and calculate the resulting conditional predictions.

Beginner 9 min read

What You'll Learn

  • Write a regression model with an interaction term and identify its conditional-mean interpretation.
  • Derive the conditional slope and intercept for a continuous-by-continuous interaction.
  • Interpret group-specific slopes and intercepts in a binary-by-continuous interaction.
  • Calculate fitted values and conditional contrasts from interaction models.
  • Recognize how centering changes coefficient reference points without changing fitted values.
  • Avoid treating an interaction coefficient as a causal effect or a slope that applies everywhere.

Why Include an Interaction?

A regression with separate terms for two regressors allows each to contribute to the fitted outcome, but it assumes that the slope for one regressor does not vary with the value of the other. An interaction relaxes that restriction: the association between one regressor and the outcome can depend on another regressor. For example, the fitted change in an outcome for one more hour of training might differ according to a person’s experience level.

An interaction is represented by a product of regressors. The product makes the fitted value nonlinear in the regressors, but the regression remains linear in its coefficients, so it can be estimated by OLS using the regressors and their product as columns of the design matrix. The central interpretive task is to derive the slope at a stated value of the other regressor.

Definition: In a regression containing regressors \(X\), \(Z\), and their product \(XZ\), an interaction is the product term \(XZ\). In the model \(Y=\beta_0+\beta_1X+\beta_2Z+\beta_3XZ+u\), the slope with respect to \(X\) depends on \(Z\), and the slope with respect to \(Z\) depends on \(X\). Here \(\beta_0,\beta_1,\beta_2,\beta_3\) are coefficients and \(u\) is the unobserved error.

If \(E[u\mid X,Z]=0\), the displayed regression equation specifies the conditional mean of \(Y\) given \(X\) and \(Z\). Without that condition, the equation can still describe a linear projection or fitted regression, but its fitted values should not automatically be called the true conditional mean. In either case, the algebra for interpreting the specified fitted function is the same. An interaction alone does not establish a causal effect.

Deriving Conditional Slopes and Intercepts

Treat \(Z=z\) as fixed in the interaction model. Collect the terms involving \(X\). The result is a straight-line expression in \(X\), whose slope and intercept depend on \(z\).

$$ \begin{aligned} Y &= \beta_0+\beta_1X+\beta_2Z+\beta_3XZ+u,\\ E[Y\mid X,Z=z] &= (\beta_0+\beta_2z)+(\beta_1+\beta_3z)X. \end{aligned} $$

Thus the conditional intercept, meaning the fitted value at \(X=0\) for a given \(Z=z\), is \(\beta_0+\beta_2z\). The conditional slope with respect to \(X\) is \(\beta_1+\beta_3z\). Reversing the roles of the regressors gives the conditional intercept and slope when \(X=x\) is held fixed.

$$ \begin{aligned} E[Y\mid X=x,Z] &= (\beta_0+\beta_1x)+(\beta_2+\beta_3x)Z,\\ \frac{\partial E[Y\mid X,Z]}{\partial X} &= \beta_1+\beta_3Z,\\ \frac{\partial E[Y\mid X,Z]}{\partial Z} &= \beta_2+\beta_3X. \end{aligned} $$

The coefficient \(\beta_3\) measures how much the slope with respect to \(X\) changes when \(Z\) increases by one unit; equivalently, it measures the change in the slope with respect to \(Z\) when \(X\) increases by one unit. Its units are outcome units per unit of \(X\) per unit of \(Z\). It is not, by itself, the slope of \(Y\) with respect to either regressor at every value.

1
Write the fitted function.
Include the main effects and the product term, then substitute the coefficient estimates when calculating a prediction.
2
Fix the other regressor.
For the slope in \(X\), hold \(Z=z\) and collect the constant and \(X\) terms.
3
State the result in context.
Report the conditional slope, the value of the variable it is conditional on, and the relevant units.

Worked Example: A Binary-by-Continuous Interaction

Suppose a hypothetical analysis relates a training outcome score \(Y\), measured in points, to training hours \(X\) and a binary indicator \(D\) for prior experience. Let \(D=1\) indicate prior experience and \(D=0\) indicate no prior experience. The fitted model is

$$ \widehat{Y}=20+2X+5D+1.5XD. $$

Group-specific lines. For the no-experience group, set \(D=0\). The product and \(D\) terms are zero, giving \(\widehat{Y}=20+2X\): the intercept is 20 points and the slope is 2 points per training hour. For the experienced group, set \(D=1\), giving \(\widehat{Y}=25+3.5X\). Its intercept is 25 points and its slope is 3.5 points per training hour.

Fitted values at four training hours. For \(X=4,D=0\), the fitted value is \(20+2(4)+5(0)+1.5(4)(0)=28\) points. For \(X=4,D=1\), it is \(20+2(4)+5(1)+1.5(4)(1)=39\) points.

At four hours, the fitted difference between the experienced and no-experience groups is \(39-28=11\) points. In general, the group difference at \(X=x\) is \(5+1.5x\), not simply 5 points: the coefficient on \(D\) is the group difference when training hours equal zero. These are fitted associations, not evidence that experience or training hours caused score differences.

Continuous-by-Continuous Interactions

When both regressors are continuous, the same algebra applies, but neither variable merely labels a group. Each conditional slope can vary smoothly with the value of the other. The fitted value at a particular pair \((x,z)\) is obtained by substituting both values into the complete equation, including their product.

Worked Example: Slopes That Vary With Both Regressors

Consider a hypothetical model for crop yield \(Y\), measured in kilograms per hectare. Let \(X\) be rainfall measured in units of 10 centimeters, and \(Z\) be fertilizer measured in units of 10 kilograms per hectare. Suppose the fitted equation is

$$ \widehat{Y}=40+3X+2Z+0.5XZ. $$

At \(Z=6\), the fitted slope with respect to rainfall is \(3+0.5(6)=6\) kilograms per hectare per 10 centimeters of rainfall. At \(X=4\), the fitted slope with respect to fertilizer is \(2+0.5(4)=4\) kilograms per hectare per 10 kilograms of fertilizer. These are slopes of the fitted function at the stated values, not universal slopes.

For \(X=4\) and \(Z=6\), the fitted yield is

$$ 40+3(4)+2(6)+0.5(4)(6)=40+12+12+12=76 $$

kilograms per hectare. Holding \(Z=6\) fixed, rewrite the fitted function as \(\widehat{Y}=(40+2(6))+(3+0.5(6))X=52+6X\). This shows directly that the conditional intercept at \(X=0\) is 52 kilograms per hectare and the conditional rainfall slope is 6. If \(X=0\) or \(Z=0\) is outside the range of observed data, the corresponding intercept is still a mathematical feature of the fitted line, but may be an extrapolation with limited practical meaning.

Reference Values, Centering, and Group Differences

The main-effect coefficients in an interaction model refer to a particular reference value. In the equation with \(X\), \(D\), and \(XD\), the coefficient on \(D\) is the fitted group difference when \(X=0\); the coefficient on \(X\) is the slope for the group with \(D=0\). If zero is an inconvenient reference, replacing \(X\) by a centered variable can make the coefficients easier to interpret. Centering changes the reference point, not the fitted values.

Worked Example: Centering Changes the Reference Point

Use the fitted training model \(\widehat{Y}=20+2X+5D+1.5XD\), and define \(C=X-5\). Thus \(C=0\) represents five training hours, and \(X=C+5\). Substituting gives

$$ \begin{aligned} \widehat{Y} &=20+2(C+5)+5D+1.5(C+5)D\\ &=30+2C+12.5D+1.5CD. \end{aligned} $$

In this centered model, the coefficient 12.5 on \(D\) is the fitted group difference at five hours, since \(C=0\) there. The group difference at \(X=5\) can also be computed from the original model as \(5+1.5(5)=12.5\) points. The interaction coefficient remains 1.5, because shifting the reference point changes the main-effect coefficients but not the difference in slopes.

For an experienced participant with seven training hours, \(C=7-5=2\), so the centered equation gives \(30+2(2)+12.5(1)+1.5(2)(1)=49.5\) fitted points. Substitution in the original equation gives \(20+2(7)+5(1)+1.5(7)(1)=49.5\) points as well. The two equations therefore give the same fitted value.

Modeling takeaway: When a product term is included, retain the corresponding main-effect terms unless the model deliberately imposes restrictions. The main effects make the conditional relationships explicit and give the interaction a clear reference-point interpretation.

Common Mistakes and Interpretation Checks

  • Calling the interaction coefficient the slope. In a continuous-by-continuous model, the slope in \(X\) is \(\beta_1+\beta_3Z\), not just \(\beta_3\). Substitute the stated value of \(Z\) before interpreting the slope.
  • Reading a binary main effect as the group difference everywhere. With a binary-by-continuous interaction, the group difference at \(X=x\) is \(\beta_2+\beta_3x\). The main-effect coefficient \(\beta_2\) gives that difference only at \(X=0\).
  • Forgetting the product when predicting. Calculate \(XZ\) from the specified regressor values and include \(\beta_3XZ\). Leaving out the product does not evaluate the fitted interaction model.
  • Interpreting a fitted interaction causally. A conditional slope describes a feature of the fitted regression (or, under the stated conditional-mean assumption, the specified conditional mean). Causal interpretation requires additional assumptions beyond the presence of a product term.

Before reporting a result, check the reference value, the units, and whether the relevant regressor values are within the data’s support. A mathematically defined slope or intercept can be difficult to interpret in practice if it refers to an implausible or unobserved combination of regressors.

Check Your Understanding

For each question, state the relevant conditional value or calculation rather than interpreting an interaction coefficient in isolation.

  1. In \(\widehat{Y}=8+2X+3Z+0.4XZ\), what is the fitted slope with respect to \(X\) when \(Z=5\)?
  2. For \(\widehat{Y}=10+X+4D+2XD\), where \(D\) is binary, what is the fitted group difference when \(X=3\)?
  3. Using the model in question 2, calculate the fitted value when \(X=3\) and \(D=1\).
  4. In a continuous-by-continuous interaction, what does the interaction coefficient measure in terms of conditional slopes?
  5. Why might the coefficient on a binary regressor not equal the fitted group difference at a practically relevant value of the continuous regressor?
Clinical Biostats