qr.X
Reconstruct the Q, R, or X Matrices from a QR Object

Description

Returns the original matrix from which the object was constructed.

Usage

qr.X(qr, complete = FALSE, 
    ncol = if (complete) nrow(R) else min(dim(R))
qr.Q(qr, complete = FALSE, Dvec = <<see below>>)
qr.R(qr, complete = FALSE)

Arguments

qr an object representing a QR decomposition. Typically, this argument results from a previous call to qr or lsfit.
complete a logical expression. If TRUE:
  • For Q or X matrices, specifies an arbitrary orthogonal completion with the matrix columns.
  • For an R matrix, binds zero-value rows beneath the square upper triangle.
The default is FALSE.
ncol an integer in the range 1:max(dim(qr\$qr)). Specifies the number of columns to be in the reconstructed matrix.
  • If complete == FALSE, the default is the minimum of the dimension of the matrix from which the qr object was constructed.
  • If complete == TRUE, the default is a square matrix with its size equal to the number of rows in the original matrix.
If ncol is larger than the original number of columns, but less than or equal to the original number of rows, the first ncol(qr$qr) columns are the original columns. The additional columns are an arbitrary orthogonal completion (a unitary completion in the complex case) of the original matrix.
Dvec a vector (not a matrix) of diagonal values. Each column of the returned Q is multiplied by the corresponding diagonal value. The default value is a vector that replicates 1 or 1+0i(for complex) n times, where n is the minimum of the dimension (if complete == FALSE) or the number of rows (if complete == TRUE) of the matrix from which the qr object was constructed.
Value
qr.X returns:
  • X, the original matrix from which the qr object was constructed.
  • a column subset of X.
  • an orthogonal column completion of X.
If complete == TRUE and/or the argument ncol is greater than ncol(X) and less than or equal to nrow(X), additional columns from an arbitrary orthogonal (unitary) completion of X are returned. If X has more columns than rows, ncol has to be given to get the complete matrix.
qr.Q returns Q, the order-nrow(X) orthogonal (unitary) transformation represented by qr.
  • If complete == TRUE, Q has nrow(X) columns.
  • If complete == FALSE, Q has min(dim(X)) columns.
When Dvec is specified, each column of Q is multiplied by the corresponding value in Dvec.
qr.R returns R, the c(ncol(X),ncol(X)) upper triangular matrix such that X == Q %*% R.
  • If complete == TRUE, R has nrow(X) rows.
  • If complete == FALSE, R has min(dim(X)) rows.
See Also
qr, qr.qy.
Examples
n <- 4
p <- 3
x <- matrix(rnorm(n * p), n, p) 
qrstr <- qr(x)	 # dim(x) == c(n,p), n >= p
Q <- qr.Q(qrstr) # dim(Q) == c(n, p)
R <- qr.R(qrstr) # dim(R) == c(p, p)
X <- qr.X(qrstr) # X == x
# X == Q %*% R
Qc <- qr.Q(qrstr, complete = TRUE) # dim(Qc) == c(n, n)
QD <- qr.Q(qrstr, Dvec = seq(p))   # QD == Q %*% diag(D)
Rc <- qr.R(qrstr, complete = TRUE) # dim(Rc) == c(n, p)
Xc <- qr.X(qrstr, complete = TRUE) # Xc[, seq(p)] == x ; 
    dim(Xc) == c(n, n)
# x == Qc %*% Rc
Package base version 6.1.4-13
Package Index