Skip to content
Prev 170976 / 398503 Next

partial residuals & the output of residuals.lm(..., type="partial")

Dear list,

After thinking about it a little more I solved my question of why I was 
calculating different residuals when using 
residuals.lm(...,type="partial") and when dropping a single term and 
recalculating the residuals.  This is because the two variables are in a 
sense competing with one another in the full model if they are not 
completely orthogonal to one another.  For example, with my hypothetical 
example from before if you make x1 and x2 and more correlated then the 
discrepancy between the two sets of residuals increases, but the problem 
can be solved if you make sure to use the same coefficients from the 
full model when computing the raw residuals without the other variable. 

Dan

Here is the example that shows that more correlated x-variables make the 
problem even worse and a solution to my original question.

set.seed(12)
x1<-runif(100)
x2<-x1+runif(100) ##this will make x1 and x2 more strongly correlated 
than in the first example (see original message)
y<-.13+.25*x1+.70*x2+runif(100)
mod<-lm(y~x1+x2)
plot(residuals(mod,type="partial")[,2],residuals(update(mod,.~.-x2),type='response'))
abline(0,1)
##note how the degree of scatter increases around the 1:1 line
##here is the solution to the problem
##calculate the residuals by hand and make sure to use the estimated 
coefficients from the full model
calc.resids<-y-cbind(rep(1,100),x1)%*%coef(mod)[-3] ##as before I will 
drop the influence of x2 from the model prediction
##center the calculated residuals
calc.resids<- calc.resids-mean(calc.resids)

plot(residuals(mod,type="partial")[,2],calc.resids)
abline(0,1)##now all the points fall right on the line


-------- Original Message --------
Subject: partial residuals & the output of residuals.lm(...,type="partial")
From: Daniel McGlinn <daniel.mcglinn at okstate.edu>
To: r-help at r-project.org <r-help at r-project.org>
Date: 2/18/2009 7:52 PM