[R] adding observations to lm for fast recursive residuals?

ivo_welch-rstat8783@mailblocks.com ivo_welch-rstat8783 at mailblocks.com
Wed Sep 15 16:53:56 CEST 2004

dear R community:  i have been looking but failed to find the 
following:  is there a function in R that updates a plain OLS lm() 
model with one additional observation, so that I can write a function 
that computes recursive residuals *quickly*?

PS: (I looked at package strucchange, but if I am not mistaken, the 
recresid function there takes longer than iterating over the models 
fresh from start to end.)  I know the two functions do not do the same 
thing, but the main part (OLS) is the same:
   > handrecurse.test <- function( y, x ) { z<- rep(NA, T); for (i in 
2:T)  { z[i] <- coef(lm(y[1:i] ~ x[1:i]))[2]; }; return(z); }
  > system.time(handrecurse.test(y,x))
    [1] 0.69 0.00 0.70 0.00 0.00
  > system.time(length(recresid( y~x )))
     [1] 1.44 0.07 1.59 0.00 0.00

pointers appreciated.  regards, /iaw

ivo welch

More information about the R-help mailing list