Re: [R] refitting lm() with same x, different y

From: William Valdar <>
Date: Tue 19 Apr 2005 - 20:00:08 EST

> From: Brian Ripley
> As a first shot, use lm with a matrix response. That fits them all at once
> with one QR-decomposition. No analogue for glm or lmer, though, since for
> those the iterative fits run do depend on the response.

Thanks Brian, that's very helpful. Also thanks to Kevin Wright who suggested using lsfit(x,Y) as being faster than lm for a Y matrix.

I've since worked out that I can bypass even more lm machinery by basing my permutation test significance thresholds on the RSS from qr.resid(). Since,

     y = QRb + e
   Q'y = Rb + Q'e
   RSS = || Q'y - Rb ||

then I can do

   X.qr <- qr(X)

once, and for every instance of y calculate

   e <- qr.resid(X.qr, y)
   rss <- e %*% e

recording them in

   rss.for.all.fits[i] <- rss

which gives me an empirical distribution of RSS scores. The degrees of freedom in my X matrix are constant throughout (I should have said that before), so all RSS's are on a level footing and map trivially to the p-value. I can therefore take the RSS at, say, the 5th percentile, turn it into a p-value and report that as my 5% threshold.

Thanks again,



Dr William Valdar               ++44 (0)1865 287 717
Wellcome Trust Centre 
for Human Genetics, Oxford

______________________________________________ mailing list PLEASE do read the posting guide! Received on Tue Apr 19 21:24:09 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:16 EST