[R] Problems understanding qr. family of functions

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Oct 13 20:26:57 CEST 2004


On Wed, 13 Oct 2004, Kjetil Brinchmann Halvorsen wrote:

> Hola!
> 
> By my understanding of reading   ?qr
> the following shold result a 3 x 3 matrix:  (rw2000)
> 
>  x <- matrix( rnorm(12), 4,3)
>  y <- matrix( rnorm(12), 4,3)
>  xqr <- qr(x)
>  yqr <- qr(y)
> 
>  qr.qty( xqr, qr.Q(yqr) ) # dim (3,3)
>             [,1]       [,2]      [,3]
> [1,]  0.16815466 -0.1970936 0.2351670
> [2,]  0.15667444  0.4939800 0.8443340
> [3,] -0.97096971  0.1029652 0.1456355
> [4,] -0.06629443 -0.8405570 0.4588976
> 
>  # The following should be equal:
>  t( qr.Q(xqr) ) %*% qr.Q(yqr)
>            [,1]       [,2]      [,3]
> [1,]  0.1681547 -0.1970936 0.2351670
> [2,]  0.1566744  0.4939800 0.8443340
> [3,] -0.9709697  0.1029652 0.1456355
> 
> but evidently is not.
> 
> There is at least one bug:
> 1) in R
> 2) in the help page
> 3) in my reading of the help page

Probably 3).  The Q matrix for a 4x3 matrix is 4x4, but qr.Q only returns 
3 cols of it.  That is stated on ?qr.Q, a separate help page, and you 
needed complete=TRUE.


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list