Why Calculate Slopes Within Categories?
A quantitative predictor can have a different relationship with an outcome in different groups. For example, the association between a training dose and a test score might differ by program type. A model with an interaction between dose and program type represents those group-specific slopes directly. To interpret it, we need to identify which coefficients combine to give the slope in each category.
A conditional slope is the change in the model’s expected outcome associated with a one-unit increase in a quantitative predictor, holding the moderator category fixed. It is a model-based association, not by itself evidence that changing the predictor causes the outcome to change.
Model and Interpretation Conditions
Begin with a binary moderator, represented by an indicator \(D\), where \(D=0\) denotes the reference category and \(D=1\) denotes the other category. The interaction model is
Here \(Y_i\) is the outcome for observation \(i\), \(X_i\) is the quantitative predictor, and \(\varepsilon_i\) is the error. The model’s conditional mean is
For the algebraic interpretation, assume the conditional mean is linear in \(X\) within each category and that the indicator correctly identifies the category. The slope applies to changes in \(X\) within the range where the model and data support interpretation; it should not automatically be extrapolated beyond that range. In the usual linear regression framework, observations are also assumed independent with errors having conditional mean zero and constant variance; normal errors are additionally used for exact small-sample inference. This tutorial calculates slopes, not their standard errors or tests.
Binary Moderators: Combine the Relevant Coefficients
When \(D=0\), both terms containing \(D\) vanish. The expected outcome is \(\beta_0+\beta_1X\), so its slope with respect to \(X\) is \(\beta_1\). When \(D=1\), the expected outcome is \((\beta_0+\beta_2)+(\beta_1+\beta_3)X\), so the slope is \(\beta_1+\beta_3\).
The coefficient \(\beta_2\) changes the intercept between categories, while \(\beta_3\) changes the slope from the reference category’s slope. Thus \(\beta_1\) alone is the slope only for the reference category under this coding. The interaction coefficient is the difference between the two category-specific slopes: \((\beta_1+\beta_3)-\beta_1=\beta_3\).
Worked Example: Training Dose by Program Type
Suppose a hypothetical fitted model predicts assessment score \(Y\), in points, from training dose \(X\), in hours. Let \(D=0\) identify the standard program and \(D=1\) the enhanced program. The fitted coefficients are \(\hat{\beta}_0=62\), \(\hat{\beta}_1=1.4\), \(\hat{\beta}_2=3.0\), and \(\hat{\beta}_3=0.8\). Calculate and interpret each dose slope.
For the standard program, \(D=0\), so the terms involving \(D\) drop out. Its fitted slope is
For the enhanced program, \(D=1\), so the slope combines the dose coefficient and the dose-by-program interaction coefficient:
According to this fitted model, within the observed range of training hours, one additional hour of dose is associated with an estimated 1.4-point higher assessment score in the standard program and a 2.2-point higher score in the enhanced program. These are associations, not causal effects. The interaction estimate says the fitted slope is \(0.8\) points per hour greater in the enhanced program than in the standard program; it does not establish whether that difference is statistically distinguishable from zero.
More Than Two Categories
For a moderator with \(K\) categories, choose one category as the reference. Create an indicator \(G_j\) for each non-reference category \(j\), with \(G_j=1\) for observations in that category and \(0\) otherwise. A model including the interaction of each indicator with \(X\) is
In the reference category, every \(G_j=0\), so the slope is \(\beta_1\). In a non-reference category \(j\), its indicator is 1 and the others are 0, so the slope is \(\beta_1+\delta_j\). Each \(\delta_j\) is the difference in slope between category \(j\) and the reference category. There is no \(\delta_1\) in this coding because the reference-category slope is already represented by \(\beta_1\).
Worked Example: A Three-Level Treatment Setting
Consider a hypothetical model for change in symptom score \(Y\), measured in points, as a function of weekly exercise time \(X\), in hours. The categorical moderator is setting, with home as the reference category, clinic as category 2, and group class as category 3. Suppose the fitted coefficient for \(X\) is \(\hat{\beta}_1=-0.6\), the exercise-by-clinic coefficient is \(\hat{\delta}_2=-0.3\), and the exercise-by-group-class coefficient is \(\hat{\delta}_3=0.5\). Find the slope in all three settings.
For home, the reference category, the slope is the coefficient of exercise:
For clinic, add the clinic interaction coefficient to the reference slope:
For group class, add its interaction coefficient:
The model therefore estimates a decrease of 0.6 points per additional weekly exercise hour in the home setting, 0.9 points in the clinic setting, and 0.1 points in the group-class setting. Since lower symptom scores represent improvement in this hypothetical example, all three estimated slopes point toward lower scores, but the size of the estimated association varies by setting. No conclusion about uncertainty follows from these point estimates alone.
A Short Derivation: Why the Coefficients Add
The addition rule follows by fixing the category and collecting the terms that multiply \(X\). For a non-reference category \(j\), set \(G_j=1\) and all other indicators to 0. The part of the conditional mean involving \(X\) becomes \(\beta_1X+\delta_jX\). Factoring out \(X\) gives \((\beta_1+\delta_j)X\). Thus the coefficient multiplying \(X\), and therefore the conditional slope, is \(\beta_1+\delta_j\). In the reference category all interaction indicators are zero, leaving \(\beta_1X\) and slope \(\beta_1\).
The same result can be seen as a rate of change: increasing \(X\) by \(\Delta X\) in category \(j\) changes the model’s expected outcome by \((\beta_1+\delta_j)\Delta X\). Dividing that expected change by \(\Delta X\), when \(\Delta X\ne0\), gives the conditional slope \(\beta_1+\delta_j\).
Worked Example: Reading the Slope After Changing the Reference Category
Use the training example’s fitted slopes: 1.4 points per hour for the standard program and 2.2 points per hour for the enhanced program. If the enhanced program is recoded as the reference category, determine the slope coefficient for the new reference and the interaction coefficient for the standard program.
With the enhanced program as the reference, its slope coefficient must be its existing fitted slope, \(2.2\) points per hour. The standard program’s interaction coefficient is its slope minus the new reference slope:
The standard-program conditional slope is then \(2.2+(-0.8)=1.4\) points per hour, as before. Changing the reference category changes how the model coefficients are expressed, but it does not change the fitted category-specific slopes. This is a useful check when reading a model with a different indicator-coding choice.
Common Mistakes and Practical Checks
- Using only the main-effect coefficient for every category. The coefficient of \(X\) gives the slope in the reference category. For another category, include its \(X\)-by-indicator coefficient.
- Confusing the group indicator coefficient with an interaction coefficient. In the binary model, \(\beta_2\) is the indicator’s main effect; \(\beta_3\) is the difference in slopes. The main effect does not enter the slope calculation.
- Leaving out a main effect while including an interaction. A model containing \(XG_j\) should ordinarily also include the corresponding \(X\) and \(G_j\) main effects. Otherwise the model imposes restrictions that can distort the intended interpretation.
- Ignoring units or context. A slope measured in score points per hour describes the estimated change in score associated with one additional hour, not a change in hours or a percentage change.
- Claiming evidence of a slope difference from point estimates alone. Different estimated slopes do not, by themselves, show that the underlying slopes differ beyond sampling variability. That requires an appropriate uncertainty analysis.
A reliable calculation has three checks: identify the reference category, list the interaction term or terms active in the category of interest, and add those terms to the \(X\) coefficient. Then interpret the result in outcome-units per predictor-unit and in the context of the model’s supported range.
Check Your Understanding
For each question, state the relevant coefficient combination before giving the interpretation.
- In a binary-moderator model, \(\hat{\beta}_1=2.1\) and \(\hat{\beta}_3=-0.7\). What are the fitted slopes for \(D=0\) and \(D=1\)?
- A three-category moderator uses category A as the reference. The predictor coefficient is \(-1.2\), and the interaction coefficients for B and C are \(0.4\) and \(1.0\). Find the slope in each category.
- In the binary model, what does the indicator main-effect coefficient represent, and why is it not added to the predictor slope?
- If the reference category changes, should the fitted conditional slopes change? Explain using the training-program example.
- A model estimates slopes of 0.5 and 1.3 outcome-units per predictor-unit in two groups. Can these estimates alone establish a statistically significant slope difference? Explain.