Tutorials › Exam SRM - Statistics for Risk Modeling › A Residualization Example with Two Predictors

Exam SRM · Multiple Regression Estimation · Tutorial 37 of 926

A Residualization Example with Two Predictors

Work through residualization calculations to find the slope for one predictor after controlling for another.

Intermediate 12 min read

What You'll Learn

  • State the two-predictor linear regression model and the conditions needed for a unique adjusted slope.
  • Calculate residuals after separately regressing the response and target predictor on the control predictor.
  • Use the residuals to compute the target predictor’s partial slope.
  • Explain why residualization gives the same slope as the multiple regression normal equations.
  • Recognize why a simple, unadjusted slope can differ from an adjusted slope.

Why Residualize Two Variables?

In a two-predictor regression, the slope for one predictor describes its association with the response after accounting for the other predictor. Residualization makes that adjustment visible. It removes the part of the response explained linearly by the control predictor, and separately removes the part of the target predictor explained linearly by that same control predictor. The slope relating the two sets of remaining residuals is the adjusted slope.

The method is particularly useful when predictors are associated. A simple regression of the response on the target predictor does not hold the other predictor fixed; residualization isolates the variation in the target predictor that is not linearly explained by the control predictor. This tutorial focuses on calculating that adjusted slope, not on constructing the entire multiple regression fit.

Definition: For observations \(i=1,\ldots,n\), consider the two-predictor linear model $$ Y_i=\beta_0+\beta_1X_{1i}+\beta_2X_{2i}+\varepsilon_i. $$ To find the slope for target predictor \(X_1\) while controlling for \(X_2\), regress \(Y\) on an intercept and \(X_2\), and retain the residuals \(r_{Yi}\). Separately regress \(X_1\) on an intercept and \(X_2\), and retain the residuals \(r_{1i}\). If the residual variation in \(X_1\) is nonzero, the adjusted slope is $$ \hat{\beta}_1=\frac{\sum_{i=1}^n r_{1i}r_{Yi}}{\sum_{i=1}^n r_{1i}^2}. $$

Each residual is an observed value minus its fitted value in the corresponding regression. Both regressions must include an intercept when the original model includes an intercept. The residuals therefore represent departures from the fitted linear relationship with \(X_2\), not departures from a line forced through zero.

Calculation Procedure

1
Fit the control relationship for the response.
Regress \(Y\) on an intercept and \(X_2\). For each observation, calculate \(r_{Yi}=Y_i-\widehat{Y}_i\).
2
Fit the control relationship for the target predictor.
Regress \(X_1\) on an intercept and \(X_2\). Calculate \(r_{1i}=X_{1i}-\widehat{X}_{1i}\).
3
Relate the residuals.
Multiply paired residuals and add them to obtain \(\sum r_{1i}r_{Yi}\). Divide by \(\sum r_{1i}^2\).

The pairing matters: each response residual must be multiplied by the target-predictor residual from the same observation. The denominator uses only the squared target-predictor residuals. Using the response residuals in the denominator, or using the original \(X_1\) values instead of their residuals, does not calculate the adjusted slope.

Why the Residual Slope Is the Multiple Regression Slope

The equality follows directly from least squares. Let \(Z\) be the matrix whose columns are the intercept and the observed values of \(X_2\). Assume \(Z\) has full column rank. Its projection matrix is \(P_Z=Z(Z^\mathsf{T}Z)^{-1}Z^\mathsf{T}\), and define \(M_Z=I-P_Z\). Multiplying a vector by \(M_Z\) leaves its residuals after projection on the columns of \(Z\). Thus \(r_Y=M_ZY\) and \(r_1=M_ZX_1\).

For any fixed value \(b\) of the target slope, the best-fitting intercept and control-predictor coefficient remove from \(Y-bX_1\) its projection onto \(Z\). The resulting residual sum of squares is therefore \((Y-bX_1)^\mathsf{T}M_Z(Y-bX_1)\). Minimizing this quantity over \(b\) gives the residual slope:

$$ \begin{aligned} Q(b)&=(Y-bX_1)^\mathsf{T}M_Z(Y-bX_1),\\ \frac{dQ(b)}{db}&=-2X_1^\mathsf{T}M_ZY+2bX_1^\mathsf{T}M_ZX_1=0,\\ \hat{\beta}_1&=\frac{X_1^\mathsf{T}M_ZY}{X_1^\mathsf{T}M_ZX_1} =\frac{r_1^\mathsf{T}r_Y}{r_1^\mathsf{T}r_1}. \end{aligned} $$

The last equality uses the symmetry and idempotence of \(M_Z\): \(M_Z^\mathsf{T}=M_Z\) and \(M_Z^2=M_Z\). In particular, \(r_1^\mathsf{T}r_Y=X_1^\mathsf{T}M_ZY\), and \(r_1^\mathsf{T}r_1=X_1^\mathsf{T}M_ZX_1\). The denominator must be positive; if it is zero, \(X_1\) has no variation left after its linear relationship with the intercept and \(X_2\) is removed, so this adjusted slope is not uniquely determined.

This is an algebraic least-squares result. It does not require normally distributed errors. The usual regression interpretation assumes a suitable linear conditional mean, such as \(E[\varepsilon_i\mid X_1,X_2]=0\); assumptions used for standard errors and tests are additional and are not needed to calculate the slope.

Worked Example: Residualizing a Four-Observation Data Set

A hypothetical analyst models a response \(Y\) using a target predictor \(X_1\) and a control predictor \(X_2\), with an intercept. For the four observations, the data are:

Observation\(X_2\)\(X_1\)\(Y\)
10110
2110
32316
43718

Find the slope for \(X_1\) after controlling for \(X_2\). The method is to residualize \(Y\) and \(X_1\) separately on an intercept and \(X_2\), then take the residual slope.

First regression: \(Y\) on \(X_2\). The means are \(\bar{X}_2=1.5\) and \(\bar{Y}=11\). The centered cross-product sum is \(1.5+5.5+2.5+10.5=20\), and the centered sum of squares for \(X_2\) is \(2.25+0.25+0.25+2.25=5\). Thus the slope is \(20/5=4\), and the intercept is \(11-4(1.5)=5\). The fitted values are \(5,9,13,17\), so the response residuals are \(r_Y=(5,-9,3,1)\).

Second regression: \(X_1\) on \(X_2\). Here \(\bar{X}_1=3\). The centered cross-product sum is \(3+1+0+6=10\), and the centered sum of squares for \(X_2\) is \(5\), giving slope \(2\). The intercept is \(3-2(1.5)=0\). The fitted values are \(0,2,4,6\), so the target-predictor residuals are \(r_1=(1,-1,-1,1)\).

Residual slope. The numerator is \(1(5)+(-1)(-9)+(-1)(3)+1(1)=12\). The denominator is \(1^2+(-1)^2+(-1)^2+1^2=4\). Therefore \(\hat{\beta}_1=12/4=3\).

Check and trap avoided. The control-predictor residuals sum to zero and have zero cross-product with the centered \(X_2\) values, as they should. The adjusted slope is 3. Using the original \(X_1\) values in place of \(r_1\) would not perform the adjustment for \(X_2\).

Two More Numerical Applications

Worked Example: A Control Predictor with Repeated Values

For six hypothetical service units, an analyst studies a response \(Y\), a target measure \(X_1\), and a control measure \(X_2\). The observations are shown below. Find the adjusted slope of \(X_1\).

Observation\(X_2\)\(X_1\)\(Y\)
10918
201124
31619
411031
521332
621538

Regress \(Y\) on \(X_2\). The means are \(\bar{X}_2=1\) and \(\bar{Y}=27\). The centered cross-product sum is \(12+0+16=28\), while the centered sum of squares for \(X_2\) is \(2+0+2=4\). The slope is \(28/4=7\), and the intercept is \(27-7(1)=20\). The fitted values are \(20,20,27,27,34,34\), giving \(r_Y=(-2,4,-8,4,-2,4)\).

Regress \(X_1\) on \(X_2\). The means are \(\bar{X}_1=64/6=32/3\) and \(\bar{X}_2=1\). The centered cross-product sum is \(4/3+0+20/3=8\); dividing by the same \(X_2\) sum of squares, 4, gives slope 2. The intercept is \(32/3-2=26/3\). The fitted values at \(X_2=0,1,2\) are \(26/3,32/3,38/3\); subtracting these from the observed \(X_1\) values gives \(r_1=(-1,1,-2,2,-1,1)\).

Calculate the adjusted slope. The paired residual products sum to \(2+4+16+8+2+4=36\). The squared target residuals sum to \(1+1+4+4+1+1=12\). Thus \(\hat{\beta}_1=36/12=3\).

Check and trap avoided. Both residual sets sum to zero, and each has zero cross-product with \(X_2-\bar{X}_2\). Repeated \(X_2\) values do not change the procedure: use all six paired observations, not just the three group averages.

Worked Example: Detecting the Difference from a Simple Slope

A hypothetical risk team records the following five observations. Find the adjusted slope for \(X_1\), and compare it with the simple-regression slope of \(Y\) on \(X_1\).

Observation\(X_2\)\(X_1\)\(Y\)
11914
221520
331937
442130
552134

Residualize \(Y\). The means are \(\bar{X}_2=3\) and \(\bar{Y}=27\). The centered cross-product sum is \(26+7+0+3+14=50\), and the centered sum of squares for \(X_2\) is \(4+1+0+1+4=10\). The regression slope is 5 and the intercept is \(27-5(3)=12\). Fitted values are \(17,22,27,32,37\), so \(r_Y=(-3,-2,10,-2,-3)\).

Residualize \(X_1\). Its mean is \(17\). The centered cross-product sum with \(X_2\) is \(16+2+0+4+8=30\); division by 10 gives slope 3. The intercept is \(17-3(3)=8\). Fitted values are \(11,14,17,20,23\), so \(r_1=(-2,1,2,1,-2)\).

Adjusted slope. The residual cross-product sum is \(6-2+20-2+6=28\). The target residual sum of squares is \(4+1+4+1+4=14\). Therefore the adjusted slope is \(28/14=2\).

Compare with the simple slope. For the simple regression, the means are \(\bar{X}_1=17\) and \(\bar{Y}=27\). The centered cross-product sum is \(104+14+20+12+28=178\), and the centered sum of squares for \(X_1\) is \(64+4+4+16+16=104\). Thus the unadjusted slope is \(178/104=89/52\), approximately \(1.7115\). It differs from 2 because it does not remove the linear contribution of \(X_2\).

Check and trap avoided. The correct adjusted calculation uses the two sets of residuals and gives 2. Treating the simple slope \(89/52\) as the adjusted slope ignores the control predictor.

Interpretation and Common Traps

The adjusted slope is the change in the fitted response associated with a one-unit increase in \(X_1\), holding \(X_2\) fixed in the linear model. In the residual calculation, this means comparing response departures from their fitted relationship with \(X_2\) against target-predictor departures from their fitted relationship with \(X_2\). It does not mean that the residuals are the original observations, or that every observation can be changed while all other features of a real process are literally held constant.

  • Residualizing only one variable. Removing the control relationship from \(Y\) alone is insufficient. \(X_1\) must also be residualized on the same control variables.
  • Omitting the intercept. If the original model includes an intercept, include one in both residualizing regressions. Otherwise the residuals need not represent departures from the intended fitted linear relationships.
  • Using unmatched residuals. Keep each \(r_{1i}\) paired with the \(r_{Yi}\) from the same observation.
  • Reversing the denominator. The denominator is \(\sum r_{1i}^2\), not \(\sum r_{Yi}^2\).
  • Ignoring no remaining target variation. If every \(r_{1i}=0\), the target predictor is exactly explained by the control predictor and intercept. The adjusted slope cannot be identified separately.

A reliable check is that the residuals from each regression with an intercept sum to zero and are orthogonal to the control predictor: \(\sum r_i=0\) and \(\sum (X_{2i}-\bar{X}_2)r_i=0\). These checks help catch arithmetic and transcription errors before the final division.

Key takeaway: To find the partial slope for \(X_1\) controlling for \(X_2\), remove the linear contribution of the intercept and \(X_2\) from both \(Y\) and \(X_1\). Then divide the cross-product of the paired residuals by the sum of squared residuals for \(X_1\). This tutorial is aligned with the SOA Exam SRM (Statistics for Risk Modeling) syllabus.

Check Your Understanding

For each problem, identify the needed residual calculation before using the final ratio.

  1. After controlling for an intercept and one predictor, a target predictor has residuals \((-1,0,1,0)\), and the response has paired residuals \((-2,1,4,-3)\). Calculate the adjusted slope. (Answer: \(3\))
  2. For a regression with an intercept and control predictor \(X_2\), the target residuals have squared sum 20 and their paired cross-product with response residuals is 30. What is the adjusted slope, and is the denominator positive? (Answer: \(1.5\); yes)
  3. A candidate residualizes \(Y\) on \(X_2\) but uses the original \(X_1\) values in the numerator and denominator. What essential step is missing, and why does the resulting ratio not generally give the adjusted slope? (Answer: Residualize \(X_1\) on the same intercept and \(X_2\); the original \(X_1\) still contains variation explained by the control predictor.)
  4. For six observations, suppose the paired residual products sum to \(-18\), while the squared target-predictor residuals sum to 9. Calculate the partial slope and state its direction. (Answer: \(-2\); negative)
  5. In a two-predictor model with an intercept, the target-predictor residuals after regression on the intercept and control predictor are all zero. Can the residualization formula identify its partial slope? Explain. (Answer: No; its denominator is zero, so the target predictor has no variation remaining after controlling for the other predictor.)
Clinical Biostats