[R] question about how summary.lm works
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Mon Jan 12 18:53:27 CET 2004
Dominic Barraclough <dominicb at cvs.rochester.edu> writes:
> Hi,
>
> While exploring how summary.lm generated its output I came across a
> section that left me puzzled.
>
>
>
> at around line 57
> R <- chol2inv(Qr$qr[p1, p1, drop = FALSE])
> se <- sqrt(diag(R) * resvar)
>
>
> I'm hoping somebody could explain the logic of these to steps or
> alternatively point me in the direction of a text that will explain
> these steps.
>
> In particular I'm puzzled what is the relationship between QR
> factorization and the cholesky factorization such that one can give a
> (sort of ) R matrix as a parameter of chol2inv(). I say sort of R
> matrix as the matrix generated by Qr$qr[p1, p1, drop = FALSE] has a
> lower triangle with non zero entries although the upper triangle
> corresponds to the values in the R matrix.
It's fairly easy, at least if we ignore the pivoting. We want
inv(X'X) where X is the design matrix, and we have X=QR where Q has
orthogonal columns. So Q'Q is the identity and X'X = R'R, i.e. R is a
Choleski factor of X'X, and we can use chol2inv to get to the inverse
of X'X. The rest is storage issues.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list