[R] fast lm se?

Dirk Eddelbuettel edd at debian.org
Fri Jan 8 15:08:34 CET 2010


On 8 January 2010 at 08:35, ivo welch wrote:
| dear R experts---I am using the coef() function to pick off the coefficients
| from an lm() object.  alas, I also need the standard errors and I need them
| fast.  I know I can do a "summary()" on the object and pick them off this
| way, but this computes other stuff I do not need.  Or, I can compute (X'
| X)^(-1) s^2 myself.  Has someone written a fast se() function?

Pages 72 and 73 of my most recent Intro to HPC tutorial [1] use Rcpp to
access the GNU GSL to do just that: coefficients and covariance matrix of a
standard y ~ X linear model.  

Pages 75 and 76 illustrate how the speed compares to both lm() and lm.fit()
(hint: it is rather favourable).

Page 74 tells you how to compile this if you use Rcpp (but you'd have to
insert the slightly longer code from the tutorial document), this is now
easier using the newest version of the inline package as detailed on my blog
[2] but this has not yet been reflected in a new HPC tutorial.

Hth, Dirk


[1] http://dirk.eddelbuettel.com/papers/ismNov2009hpcTutorial.pdf
[2] http://dirk.eddelbuettel.com/blog/2009/12/20#rcpp_inline_example

-- 
Three out of two people have difficulties with fractions.



More information about the R-help mailing list