Matrix (version 1.2-7.1)

sparseQR-class: Sparse QR decomposition of a sparse matrix

Description

Objects class "sparseQR" represent a QR decomposition of a sparse $n x p$ rectangular matrix $X$, typically resulting from qr()

Arguments

Objects from the Class

Objects can be created by calls of the form new("sparseQR", ...) but are more commonly created by function qr applied to a sparse matrix such as a matrix of class dgCMatrix.

Slots

Methods

Details

The decomposition is of the form A[p+1,] == Q %*% R, if the q slot is of length 0 or A[p+1,q+1] == Q %*% R where A is a sparse $m by n$ matrix ($m >= n$), $R$ is an $m by n$ matrix that is zero below the main diagonal. The p slot is a 0-based permutation of 1:m applied to the rows of the original matrix. If the q slot has length n it is a 0-based permutation of 1:n applied to the columns of the original matrix to reduce the amount of “fill-in” in the matrix $R$.

The matrix $Q$ is a "virtual matrix". It is the product of $n$ Householder transformations. The information to generate these Householder transformations is stored in the V and beta slots.

The "sparseQR" methods for the qr.* functions return objects of class "dgeMatrix" (see dgeMatrix). Results from qr.coef, qr.resid and qr.fitted (when k == ncol(R)) are well-defined and should match those from the corresponding dense matrix calculations. 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.

Also, the results of qr.qy and qr.qty apply to the permuted column order when the q slot has length n.

See Also

qr, qr.Q, qr.R, qr.fitted, qr.resid, qr.coef, qr.qty, qr.qy, dgCMatrix, dgeMatrix.

Examples

Run this code
data(KNex)
mm <- KNex $ mm
 y <- KNex $  y
 y. <- as(as.matrix(y), "dgCMatrix")
str(qrm <- qr(mm))
 qc  <- qr.coef  (qrm, y); qc. <- qr.coef  (qrm, y.) # 2nd failed in Matrix <= 1.1-0
 qf  <- qr.fitted(qrm, y); qf. <- qr.fitted(qrm, y.)
 qs  <- qr.resid (qrm, y); qs. <- qr.resid (qrm, y.)
stopifnot(all.equal(qc, as.numeric(qc.),  tolerance=1e-12),
          all.equal(qf, as.numeric(qf.),  tolerance=1e-12),
          all.equal(qs, as.numeric(qs.),  tolerance=1e-12),
          all.equal(qf+qs, y, tolerance=1e-12))

Run the code above in your browser using DataCamp Workspace