[R] refitting lm() with same x, different y
William Valdar
valdar at well.ox.ac.uk
Tue Apr 19 12:00:08 CEST 2005
> 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,
William
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Dr William Valdar ++44 (0)1865 287 717
Wellcome Trust Centre valdar at well.ox.ac.uk
for Human Genetics, Oxford www.well.ox.ac.uk/~valdar
More information about the R-help
mailing list