user1539634
user1539634

Reputation:

sparse-QR more rows than original matrix

I did a sparse qr decomposition with "Matrix" package in R like

a <- Matrix(runif(20), nrow = 5, sparse = T)
a[3:5,] <- 0 #now **a** is a 5X4 matrix
b <- qr.R(qr(a), complete = T) #but now **b** is a 7X4 matrix!

anyone knows why? Note that if I keep a dense, then the bug(?) does not appear.

Upvotes: 0

Views: 371

Answers (1)

flodel
flodel

Reputation: 89097

I'll assume you did not see the warning, otherwise you would have mentioned it, right?

Warning message: In qr.R(qr(a), complete = T) : qr.R(< sparse >) may differ from qr.R(< dense >) because of permutations

Now if you are asking what those permutations mean, it's a different story...

The help("sparseQR-class") page may have more info on the issue:

However, because the matrix Q is not uniquely defined, the results of qr.qy and qr.qty do not necessarily match those from the corresponding dense matrix calculations.

Maybe it is the same with qr.R?

Finally, further down on the same help page:

qr.R --- signature(qr = "sparseQR"): compute the upper triangular R matrix of the QR decomposition. Note that this currently warns because of possible permutation mismatch with the classical qr.R() result, and you can suppress these warnings by setting options() either "Matrix.quiet.qr.R" or (the more general) either "Matrix.quiet" to TRUE.

Upvotes: 1

Related Questions