Tutorials › Regression Analysis (Undergraduate) › Derive the Conditional Slope of the Other Predictor

Quantitative Predictor Interactions · Tutorial 324 of 991

Derive the Conditional Slope of the Other Predictor

Differentiate the interaction equation with respect to the second predictor and evaluate its fitted slope at specified values of the first.

Intermediate 9 min read

What You'll Learn

  • Write the fitted mean for two quantitative predictors and their product term.
  • Differentiate with respect to the second predictor while holding the first fixed.
  • Express the conditional slope as a function of the first predictor.
  • Calculate and interpret that slope at selected predictor values, with units.
  • Check the predictor range and avoid confusing a fitted slope with a causal effect.

Why the Second Predictor’s Slope Can Depend on the First

With two quantitative predictors in a regression model, the relationship between one predictor and the fitted outcome need not be the same at every value of the other predictor. An interaction model allows that conditional relationship to vary. Here the goal is to find the fitted slope for the second predictor, \(x_2\), while holding the first predictor, \(x_1\), fixed.

A slope is expressed as a change in fitted outcome per unit change in a predictor. In an interaction model, the slope for \(x_2\) is not necessarily one constant number: its value may depend on \(x_1\). We can find it by differentiating the fitted mean with respect to \(x_2\), treating \(x_1\) as fixed.

The Model and Its Assumptions

Let \(Y\) be a quantitative outcome and let \(x_1\) and \(x_2\) be values of two quantitative predictors. The linear interaction model for the conditional mean is

$$ E(Y\mid X_1=x_1,X_2=x_2) =\beta_0+\beta_1x_1+\beta_2x_2+\beta_3x_1x_2. $$

The fitted mean, using estimated coefficients, is

$$ \hat{y}=b_0+b_1x_1+b_2x_2+b_3x_1x_2. $$

The fitted equation assumes that the conditional mean is adequately represented by these terms over the predictor values being considered. In particular, it includes the two individual predictor terms and their product. To interpret a calculated slope as relevant to a particular setting, the predictor values should also be within a range for which the model has data support. These conditions concern the mean model and its use; calculating its derivative does not by itself require an assumption of normally distributed errors.

Definition: The conditional slope of the fitted mean with respect to \(x_2\) at \(x_1=a\) is the derivative of \(\hat{y}\) with respect to \(x_2\), evaluated while \(x_1\) is held fixed at \(a\). It gives the instantaneous rate of change in fitted outcome per unit of \(x_2\), at that value of \(x_1\).

This is a partial derivative: one predictor changes in the calculation, while the other predictor is held constant. The subscript \(2\) in “slope with respect to \(x_2\)” identifies which predictor is being varied.

Deriving the Conditional Slope

Start with the fitted equation. When differentiating with respect to \(x_2\), \(b_0\) and \(b_1x_1\) are constant because they do not involve \(x_2\). The derivative of \(b_2x_2\) is \(b_2\). In the product term \(b_3x_1x_2\), \(b_3x_1\) is constant with respect to \(x_2\), so the derivative is \(b_3x_1\). Therefore,

$$ \frac{\partial\hat{y}}{\partial x_2} =0+0+b_2+b_3x_1 =b_2+b_3x_1. $$

The value of this expression at \(x_1=a\) is the conditional slope at that first-predictor value. The result can also be justified directly from the definition of a derivative. Hold \(x_1=a\) fixed, increase \(x_2\) by a small amount \(h\), and calculate the difference in fitted means:

$$ \begin{aligned} \hat{y}(a,x_2+h)-\hat{y}(a,x_2) &=b_2h+b_3ah\\ &=h(b_2+b_3a). \end{aligned} $$

For \(h\ne 0\), divide by \(h\). The difference quotient is \(b_2+b_3a\), regardless of the nonzero value of \(h\). Its limit as \(h\) approaches zero is therefore the same expression, which confirms the derivative.

Result: In the fitted model \(\hat{y}=b_0+b_1x_1+b_2x_2+b_3x_1x_2\), the conditional slope with respect to \(x_2\) at \(x_1=a\) is \(b_2+b_3a\). Its units are outcome units per unit of \(x_2\).

Worked Example: Fitted Sleep Slope at Different Study Times

Suppose a hypothetical fitted model predicts a quiz score, in points, from weekly study time \(x_1\), measured in hours, and sleep \(x_2\), measured in hours per night:

$$ \hat{y}=42+1.8x_1+2.5x_2+0.30x_1x_2. $$

Find the fitted slope with respect to sleep when weekly study time is 0, 4, and 8 hours. The equation has the stated product term and both individual predictor terms, as required for the model being used. The requested study times are hypothetical values; interpretation should be limited to the range over which such values are supported by the data.

Differentiate with respect to sleep \(x_2\), holding study time \(x_1\) fixed:

$$ \frac{\partial\hat{y}}{\partial x_2}=2.5+0.30x_1. $$

At \(x_1=0\) hours per week, the conditional slope is \(2.5+0.30(0)=2.5\) quiz-score points per additional hour of sleep per night. At \(x_1=4\) hours per week, it is \(2.5+0.30(4)=2.5+1.2=3.7\) points per additional hour of sleep per night. At \(x_1=8\) hours per week, it is \(2.5+0.30(8)=2.5+2.4=4.9\) points per additional hour of sleep per night.

Each number is a fitted conditional slope at a specified study time, not a slope that applies to every student regardless of study time. These are model-based associations; the fitted equation alone does not establish that changing sleep causes a change in quiz score.

Substitute the First Predictor Before Interpreting

A reliable calculation has two separate parts. First, differentiate the fitted equation with respect to the requested predictor. Second, substitute the chosen value of the other predictor into the resulting expression. Keeping those steps distinct helps prevent using the wrong main-effect coefficient or allowing the wrong predictor to vary.

1
Identify the requested slope.
For a slope with respect to \(x_2\), \(x_2\) is the variable of differentiation and \(x_1\) is held fixed.
2
Differentiate the full fitted mean.
For the product-term model, the derivative is \(b_2+b_3x_1\).
3
Evaluate at the stated \(x_1\).
Substitute that value into \(b_2+b_3x_1\), then include the units of outcome per unit of \(x_2\).

Worked Example: A Negative Conditional Slope at High Fatigue

In a hypothetical model, an attention score \(Y\), measured in points, is fitted from fatigue \(x_1\), measured on a point scale, and sleep \(x_2\), measured in hours per night:

$$ \hat{y}=15+0.8x_1+3.0x_2-0.40x_1x_2. $$

The model form contains both predictor terms and their product. Suppose the fatigue values 2 and 5 considered below fall within the data-supported range. Find the conditional sleep slope at each value.

Differentiating with respect to \(x_2\) gives

$$ \frac{\partial\hat{y}}{\partial x_2}=3.0-0.40x_1. $$

At fatigue \(x_1=2\), the calculation is \(3.0-0.40(2)=3.0-0.80=2.2\) attention-score points per additional hour of sleep. At fatigue \(x_1=5\), it is \(3.0-0.40(5)=3.0-2.0=1.0\) point per additional hour of sleep.

In both cases the fitted slope is positive, but the values differ. This describes the fitted mean at the specified fatigue levels. It does not show that adding sleep would cause the stated score change, and it should not be extrapolated to fatigue levels outside the model’s useful range.

Check the Main-Effect Case and the Units

If the product coefficient is zero, then the formula reduces to \(\partial\hat{y}/\partial x_2=b_2\), which is constant in \(x_1\). Otherwise, evaluating the expression at different \(x_1\) values may produce different conditional slopes. The result’s units follow from the model: \(b_2\) has units of outcome per unit of \(x_2\), and \(b_3x_1\) has the same units because \(b_3\) is measured in outcome units per unit of \(x_1\) per unit of \(x_2\).

Worked Example: Evaluating a Slope at a Specified Predictor Value

A hypothetical model predicts daily energy level, measured in points, from activity \(x_1\), measured in minutes per day, and caffeine intake \(x_2\), measured in cups per day:

$$ \hat{y}=30+0.12x_1+1.6x_2+0.015x_1x_2. $$

Find the fitted slope with respect to caffeine at 40 minutes of activity per day. Assume 40 minutes lies within the relevant data range.

Differentiate the fitted mean with respect to \(x_2\):

$$ \frac{\partial\hat{y}}{\partial x_2}=1.6+0.015x_1. $$

Substitute \(x_1=40\) minutes:

$$ 1.6+0.015(40)=1.6+0.60=2.2. $$

Thus, at 40 minutes of activity per day, the fitted mean has a slope of 2.2 energy-level points per additional cup of caffeine per day. The units are points per cup because \(x_2\) is measured in cups per day and the outcome is measured in points. This is a conditional fitted slope, not a claim that caffeine has a causal effect.

Common Mistakes and Why the Calculation Matters

  • Using the wrong main-effect coefficient. For the slope with respect to \(x_2\), the derivative of \(b_2x_2\) contributes \(b_2\). The coefficient \(b_1\) is attached to \(x_1\), which is held fixed.
  • Differentiating the product incorrectly. When taking the derivative with respect to \(x_2\), \(x_1\) is treated as a constant, so the product term contributes \(b_3x_1\), not \(b_3x_2\).
  • Reporting the slope without the specified value of \(x_1\). The expression \(b_2+b_3x_1\) depends on \(x_1\) when \(b_3\ne 0\). Substitute the requested value before giving a numerical slope.
  • Confusing fitted association with cause and effect. A regression equation describes a fitted relationship in the data. A conditional slope alone does not establish what would happen under an intervention.
  • Ignoring the model’s range. The derivative can be calculated at any number mathematically, but a value far outside the observed range may not provide a useful scientific interpretation.

Finding the conditional slope for the second predictor is useful when a question asks how the fitted relationship between that predictor and the outcome behaves at a particular value of the first predictor. The derivative gives a precise answer in outcome units per unit of \(x_2\), while the substitution makes clear which conditional relationship is being described.

Check Your Understanding

Answer each question using the fitted-mean model and state units when a numerical slope is requested.

  1. For \(\hat{y}=8+2x_1+5x_2-0.2x_1x_2\), derive the conditional slope with respect to \(x_2\).
  2. Using the same model, calculate the slope with respect to \(x_2\) at \(x_1=10\).
  3. In \(\hat{y}=4+0.5x_1+3x_2+0.1x_1x_2\), which predictor is held fixed when finding the slope with respect to \(x_2\)?
  4. If the product coefficient \(b_3\) is zero, does the fitted slope with respect to \(x_2\) depend on \(x_1\)? Explain using the derivative formula.
  5. Why should a conditional slope calculated at a value far outside the data-supported range be interpreted cautiously?