[R] adding observations to lm for fast recursive residuals?
roger koenker
rkoenker at uiuc.edu
Wed Sep 15 17:07:17 CEST 2004
In my quantreg package there is a function called lm.fit.recursive()
that, as the .Rd file
says:
Description:
This function fits a linear model by recursive least squares. It
is a utility routine for the 'khmaladzize' function of the
quantile regression package.
Usage:
lm.fit.recursive(X, y, int=TRUE)
Arguments:
X: Design Matrix
y: Response Variable
int: if TRUE then append intercept to X
Value:
return p by n matrix of fitted parameters, where p. The ith column
gives the solution up to "time" i.
It is written in fortran so it should be reasonably quick.
HTH
url: www.econ.uiuc.edu/~roger Roger Koenker
email rkoenker at uiuc.edu Department of Economics
vox: 217-333-4558 University of Illinois
fax: 217-244-6678 Champaign, IL 61820
On Sep 15, 2004, at 9:53 AM, <ivo_welch-rstat8783 at mailblocks.com> wrote:
>
> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list