[R] suggestion for example for base:naresid

Markus Jantti markus.jantti at uta.fi
Wed Aug 29 13:10:03 CEST 2001


Dear list:

since it took me a little while to figure out how to make use of naresid, I thought that 
the below R code might be useful as an example on the help page. 

Regards,

Markus

 # generate some data
x1 <- runif(20)
y <- 10 + 5*x1 + rnorm(20)
summary(lm.0 <- lm(y ~ x1))
# append some NA's to y
y <- c(y, rep(NA, 5))
# generate some further x1s
x1 <- c(x1, runif(5))
# this fills the residuals vector with NA's to the end
summary(lm.1 <- lm(y ~ x1, na.action = na.exclude))
residuals(lm.1) # is equal to
naresid(na.exclude(lm.1), lm.1$residuals)
tmp.omit <- lm.1$na.action # modify the na.action to omit
class(tmp.omit) <- "omit"
naresid(tmp.omit, lm.1$residuals)
# same as residuals(lm.0)
summary(lm.2 <- lm(y ~ x1)) 
residuals(lm.2) 
tmp.omit <- lm.2$na.action # modify the na.action to be "exclude"
class(tmp.omit) <- "exclude"
naresid(tmp.omit, lm.2$residuals)

--
Markus Jantti
markus.jantti at uta.fi ** http://www.abo.fi/~mjantti
Dept of Economics ** University of Tampere ** FIN 33014 University of Tampere
PGP public key: http://www.abo.fi/~mjantti/pubring.asc




More information about the R-help mailing list