# [R] QR Decompositon and qr.qty

Gabor Grothendieck ggrothendieck at gmail.com
Tue May 15 15:33:07 CEST 2007

```You need complete = TRUE.  See ?qr.Q

> m <- matrix(c(1,0,0,0,1,0,0,0,1,0,0,1), ncol = 3)
> y <- matrix(c(1,2,3,4,2,3,4,5,1,1,1,1,2,2,2,2), nrow = 4)
> t(qr.Q(qr(m), complete = TRUE)) %*% y
[,1] [,2] [,3] [,4]
[1,]   -1   -2   -1   -2
[2,]   -4   -5   -1   -2
[3,]    3    4    1    2
[4,]   -2   -3   -1   -2
> qr.qty(qr(m), y)
[,1] [,2] [,3] [,4]
[1,]   -1   -2   -1   -2
[2,]   -4   -5   -1   -2
[3,]    3    4    1    2
[4,]   -2   -3   -1   -2

On 5/15/07, Sebastian Bauer <Sebastian.Bauer at charite.de> wrote:
> Dear R people,
>
> I do not have much knowledge about linear algebra but currently I need
> to understand what the function qr.qty is actually doing. The
> documentation states that it calculates t(Q) %*% y via a previously
> performed QR matrix decomposition.
>
> In order to do that, I tried following basic example:
>
> m<-matrix(c(1,0,0,0,1,0,0,0,1,0,0,1),ncol=3) # 4x3 matrix
> qr.qty(qr(m),matrix(c(1,2,3,4,2,3,4,5,1,1,1,1,2,2,2,2),nrow=4))
>
>      [,1] [,2] [,3] [,4]
> [1,]   -1   -2   -1   -2
> [2,]   -4   -5   -1   -2
> [3,]    3    4    1    2
> [4,]   -2   -3   -1   -2
>
> As far as I understood the documentation a call such as
>
> t(qr.Q(qr(m)))%*%matrix(c(1,2,3,4,2,3,4,5,1,1,1,1,2,2,2,2),nrow=4)
>
> should produce the same result, but this produces a 3 by 4 rather than a
> four by four matrix as t(qr.Q(qr(m))) has only three rows.
>
>      [,1] [,2] [,3] [,4]
> [1,]   -1   -2   -1   -2
> [2,]   -4   -5   -1   -2
> [3,]    3    4    1    2
>
>
> So the last line is missing. Any hints how R adds the last line would be
> appreciated.
>
> Regards,
> Sebastian
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help