[R] partial residuals & the output of residuals.lm(..., type="partial")
Daniel McGlinn
daniel.mcglinn at okstate.edu
Thu Feb 19 02:52:33 CET 2009
Dear list,
I would like to know how the function residuals.lm calculates the
partial residuals from an lm object with more than one predictor
variable. In other words what is residuals.lm(...,type="partial") doing
behind the scenes? According to the help file for residuals.lm
(?residuals.lm), "The partial residuals are a matrix with each column
formed by omitting a term from the model". Unfortunately, I cannot seem
to recreate the results of the function "residuals.lm" by simply
dropping a variable from a model and then calculating the raw residuals
of the updated model. Can anyone see what I am overlooking? It may be
helpful to others if I mention that the usage of
residuals.lm(...,type='partial') by the function termplot is what
motivated me to look at this function more closely. Below is a simple
example to illustrate my question:
set.seed(12)
x1 <- runif(100)
x2 <- runif(100)
y <- .13+.25*x1+.70*x2+runif(100)
mod <- lm(y~x1+x2)
##let's only consider the partial residuals when x2 is dropped from the
model
plot(residuals(mod,type="partial")[,2],residuals(update(mod,.~.-x2),type='response'))
abline(0,1) ##1:1 line
##why do the points not all fall on the 1:1 line?
Thanks,
Dan
--
Daniel J. McGlinn
Department of Botany, Oklahoma State University
http://ecology.okstate.edu/Libra/
More information about the R-help
mailing list