You've missed the complete=TRUE argument (and also crossprod) as in
crossprod(qr.Q(qr(m), TRUE),
matrix(c(1,2,3,4,2,3,4,5,1,1,1,1,2,2,2,2),nrow=4))
On Tue, 15 May 2007, Sebastian Bauer 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
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
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
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 > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
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