Why Average Conditional Slopes?
In an interaction model, the slope relating a predictor to an outcome can vary with another predictor. A slope reported at one moderator value describes the model at that value, but it may not summarize the range of moderator values found among the observations. An average marginal effect (also called an average conditional slope here) summarizes those fitted slopes by calculating an effect for each observation and then taking their arithmetic mean.
This average is tied to the observed covariate values: observations with common moderator values contribute repeatedly, and uncommon values contribute less often. It is not automatically the same as averaging slopes at a chosen set of moderator values, nor is it always the same as calculating a slope at the mean covariate profile. The distinction depends on the model’s form.
Definition and Model
Begin with a continuous predictor \(X\), a continuous moderator \(Z\), and an outcome \(Y\). Suppose the conditional mean is described by a regression model with a linear interaction:
Here \(i=1,\ldots,n\) indexes observations, and the \(\beta\) terms are model coefficients. For this model to describe the conditional mean, assume the regression errors have conditional mean zero given \(X_i\) and \(Z_i\), and that the stated functional form is appropriate for the setting. The conditional slope for \(X\) is obtained by differentiating the conditional mean with respect to \(X\). It is \(\beta_1+\beta_3Z_i\) at moderator value \(Z_i\). This is a model-based association; it does not by itself establish a causal effect.
In the linear interaction model above, the derivative does not depend on the observation’s \(X_i\); it depends on \(Z_i\). The calculation therefore evaluates \(\hat{\beta}_1+\hat{\beta}_3Z_i\) for every observed moderator value and averages the results. The fitted coefficients describe the model, while the observed \(Z_i\) values determine which parts of the moderator range contribute to this particular sample average.
A Useful Identity for a Linear Interaction
For a bilinear interaction, averaging the observation-specific slopes has a simple algebraic form. The sample mean of the observed moderator values is \(\bar{Z}=\frac{1}{n}\sum_{i=1}^n Z_i\). Substituting the conditional slope into the definition gives:
This derivation shows an important special case: in a model with only the linear interaction \(XZ\), the average conditional slope over observations equals the conditional slope evaluated at the sample mean of \(Z\). That equality follows from the linear form of the slope as a function of \(Z\). It does not mean that averaging individual slopes and evaluating a slope at a mean profile are interchangeable in every regression model.
Worked Example: Averaging Slopes in a Linear Interaction
Suppose a hypothetical fitted model predicts a test score \(Y\) from study time \(X\), in hours, and a continuous preparation measure \(Z\):
The coefficients are estimated from a model assumed to represent the conditional mean adequately. The fitted slope for study time at moderator value \(Z=z\) is:
Suppose the observed moderator values are \(0,1,2,\) and \(3\). Evaluate the slope at each one:
The average over the four observations is:
The sample mean moderator value is \(\bar{Z}=(0+1+2+3)/4=1.5\). Evaluating the slope there gives \(2+0.8(1.5)=3.2\), the same average. In this fitted model, the average conditional slope is 3.2 test-score points per additional study hour across these observed moderator values. This describes the fitted relationship, not a guaranteed change caused by studying an additional hour.
When the Average Differs from the Effect at the Mean Profile
If the conditional slope is curved as a function of the moderator, evaluating that slope at the mean moderator value can give a different answer from averaging it over observations. For example, consider a model that includes an interaction between \(X\) and \(Z^2\):
Assume the conditional mean has this stated form and the regression errors have conditional mean zero given the predictors. Differentiating with respect to \(X_i\) gives the observation-specific slope \(\beta_1+\beta_3Z_i+\beta_4Z_i^2\). Averaging the fitted slopes yields:
At the mean profile, however, the fitted slope is \(\hat{\beta}_1+\hat{\beta}_3\bar{Z}+\hat{\beta}_4\bar{Z}^2\). These expressions differ whenever the quadratic term matters and the mean of the squared moderator values differs from the square of the mean. Specifically, their difference is \(\hat{\beta}_4\left(\frac{1}{n}\sum_i Z_i^2-\bar{Z}^2\right)\), which equals \(\hat{\beta}_4\) times the sample variance of \(Z\) when that variance is calculated with divisor \(n\).
Worked Example: A Curved Conditional Slope
Consider a hypothetical fitted model for a health score \(Y\), with activity \(X\) and a continuous baseline measure \(Z\):
Assume this model is an adequate description of the conditional mean over the covariate values being considered. The conditional slope for \(X\) at \(Z=z\) is \(1.2+0.4z+0.10z^2\). Suppose the four observed moderator values are \(0,1,3,\) and \(4\). The observation-specific slopes are:
Thus the average conditional slope over the observations is:
To compare this with the slope at the mean profile, first calculate \(\bar{Z}=(0+1+3+4)/4=2\). The slope evaluated at \(Z=2\) is:
The two summaries differ: the average over observations is 2.65 score points per unit of \(X\), while the slope at the mean moderator value is 2.4. The difference arises because the curved term uses the average of \(Z_i^2\) for the first summary but \(\bar{Z}^2\) for the second. Here, \((0^2+1^2+3^2+4^2)/4=6.5\), whereas \(2^2=4\).
Each Observation Gets One Contribution
An average over observations gives each observation equal weight. It does not give each distinct moderator value equal weight. If multiple observations share a value, that value’s conditional slope appears multiple times in the average. This reflects the covariate distribution in the sample rather than a deliberately balanced grid of moderator values.
Worked Example: Repeated Moderator Values
Suppose a hypothetical fitted model has conditional slope \(-0.5+0.6Z\) for \(X\), measured in hours, on an outcome \(Y\), measured in points. Five observations have moderator values \(-1,0,0,2,\) and \(3\). The fitted slopes are:
Average all five observation-specific slopes:
If instead one gave equal weight to the four distinct values \(-1,0,2,3\), the result would be \((-1.1-0.5+0.7+1.3)/4=0.10\). That is a different summary because it counts each distinct value once and ignores that \(Z=0\) occurs twice. The average over the five observations is \(-0.02\) outcome points per additional hour of \(X\), according to this fitted model and this observed moderator distribution.
Practical Interpretation and a Common Mistake
An average marginal effect compresses a collection of observation-specific slopes into one number. It is useful when a single summary of the fitted relationship is needed for the covariate distribution represented by the observations. But the average does not imply that every observation has that slope: conditional slopes may be smaller, larger, or even have the opposite sign. The summary also depends on which observations are included. A different sample, or a different target distribution of moderator values, can give a different average even when the fitted coefficients are unchanged.
A common mistake is to claim that the effect at the mean moderator value is always the average effect. In the bilinear model, this happens to be true because the conditional slope is a linear function of \(Z\). With a curved conditional slope, the two calculations can differ. Another mistake is to average across a short list of distinct moderator values without accounting for how often each occurs. To calculate an average over observations, evaluate the slope at every observation and average those results.
Check Your Understanding
Try these questions using the definitions and calculations above.
- For the fitted model \(\widehat{E}(Y\mid X,Z)=5+3X+2Z-0.5XZ\), write the conditional slope for \(X\) at \(Z=z\).
- If the observed moderator values are \(0,2,\) and \(4\), calculate the average conditional slope for the model in question 1. Verify it using the sample mean of \(Z\).
- Explain why an interaction involving \(XZ^2\) can make the average slope differ from the slope at the mean moderator value.
- Suppose five observations have moderator values \(1,1,1,3,\) and \(5\). Why is averaging the slopes at the three distinct values not generally an average over observations?
- What does an average marginal effect describe, and why does it not imply that every observation has that same conditional slope?