I can't find documentation as to the exact operation of this function. I have a QR factorization of a matrix X
:
X = matrix(c(1,1,1,1,-1.5,-0.5,0.5,1.5,2.25,0.25,0.25, 2.25,-3.275,-0.125,0.125,3.375),
nrow=4, byrow=F)
[,1] [,2] [,3] [,4]
[1,] 1 -1.5 2.25 -3.375
[2,] 1 -0.5 0.25 -0.125
[3,] 1 0.5 0.25 0.125
[4,] 1 1.5 2.25 3.375
The function qr(X)
yields a list:
$qr (rounding output)
[,1] [,2] [,3] [,4]
[1,] -2.0 0 -2.5 0
[2,] 0.5 -2.236 0 -4.583
[3,] 0.5 0.447 2 0
[4,] 0.5 0.894 -0.929 -1.341
$rank
[1] 4
$qraux
[1] 1.500000 1.000000 1.368524 1.341641
$pivot
[1] 1 2 3 4
attr(,"class")
[1] "qr"
I select the diagonal elements of qr(X)$qr
, which I name z
:
z = qr(X)$qr
z = Q * (row(Q) == col(Q))
[,1] [,2] [,3] [,4]
[1,] -2 0.000000 0 0.000000
[2,] 0 -2.236068 0 0.000000
[3,] 0 0.000000 2 0.000000
[4,] 0 0.000000 0 -1.341641
So far, so good. Now the next call I don't understand:
(raw = qr.qy(qr(X), z))
[,1] [,2] [,3] [,4]
[1,] 1 -1.5 1 -0.3
[2,] 1 -0.5 -1 0.9
[3,] 1 0.5 -1 -0.9
[4,] 1 1.5 1 0.3
MAKING SOME PROGRESS:
So, thanks to the answer and some reading, I think that the object qr(X)$qr
contains R completely in the upper triangle:
[,1] [,2] [,3] [,4]
[1,] -2.0 0 -2.5 0
[2,] -2.236 0 -4.583
[3,] 2 0
[4,] -1.341
The lower triangle of qr(X)$qr
contains information about Q:
[,1] [,2] [,3] [,4]
[1,]
[2,] 0.5
[3,] 0.5 0.447
[4,] 0.5 0.894 -0.929
Somehow calling qr.Q(qr(X))
returns Q using internally the function qr.qy()
with qr() and a diagonal matrix of 1's as inputs.
But how is this operation carried out? How is the rest of the right upper corner of Q get filled? I think it makes use of $qraux
, but how does it get to:
[,1] [,2] [,3] [,4]
[1,] -0.5 0.6708204 0.5 0.2236068
[2,] -0.5 0.2236068 -0.5 -0.6708204
[3,] -0.5 -0.2236068 -0.5 0.6708204
[4,] -0.5 -0.6708204 0.5 -0.2236068
In short, How does qr.qy() work specifically?
I just found this: "qy.qr(): return the results of the matrix multiplications: Q %*% y, where Q is the order-nrow(x) orthogonal (or unitary) transformation represented by qr."