qr
QR Matrix Decomposition

Description

Returns a representation of an orthogonal (or unitary) matrix and a triangular matrix whose product is the input.

Usage

qr(x, ...)
## Default S3 method:
qr(x, tol = 1e-07, LAPACK = FALSE, ...) 
## S3 method for class 'lm':
qr(x, ...)

is.qr(x)

Arguments

x a matrix or data.frame of numeric or complex data in qr.default(). Missing values are not accepted. Or a "lm" object for function qr.lm(), any object for function is.qr().
tol the tolerance.
LAPACK logical value to indicate if LAPACK library is used for QR matrix decomposition.
... other optional arguments pass to or from methods.

Details

The function qr is generic. Currently, the default method and an invisible method for class "lm" are implemented.
In default method, when LAPACK = TRUE the QR decomposition is computed with the LAPACK function DGEQP3. See http://www.netlib.org/lapack/ for more details.
In qr.lm() method, the qr component of lm object is extracted if it is not null. Otherwise function is stopped with error message.
Value
qrreturns an object of class "qr" representing the QR numerical decomposition of the matrix x. The components of qr are as follows:
  • qr: a matrix the same size as x. The upper triangle (including the diagonal) is the R matrix. The lower part contains most of a compact representation of the Q matrix.
  • qraux is a vector of length ncol(x) containing part of the compact representation of the Q matrix.
  • rank is the rank of x as computed during the decomposition. For the default case when pivoting is done suitable for linear modeling, the rank is computed as number of columns minus the number of pivot columns found.

    (To get a true estimate of the matrix numerical rank, use the function svd instead.)

  • pivot is the pivoting of columns of x used to produce the decomposition. This value is used to adjust the dimnames attribute.
is.qrreturns TRUE if its argument x is of class qr; otherwise, FALSE.
Background
A QR decomposition of an m by n matrix X is a n by n permutation matrix P, an m by m orthogonal (or unitary) matrix Q, and an m by n upper triangular matrix R such that: A restatement of this equation is: The QR decomposition is an efficient and numerically stable method for computing least squares.
Differences between TIBCO Enterprise Runtime for R and Open-source R
Note
This is QR decomposition with pivoting: x[, qr$pivot] == Q %*% R.
Unlike regression functions, qr does not add an intercept term. Bind on a column of 1s if you want an intercept. The results of qr.coef, and so on, reflect an intercept term if a column of 1s is added.
The default pivoting used is trying to preserve the column order and the pivoting condition is computed in a scale independent way, i.e. all columns are scaled to length one inside the pivoting code. A column is pivoted (moved last) if the length of what is left after subtracting the components in the previous columns is small compared to the given tolerance tol.
References
Anderson. E., et al. 1999. http://www.netlib.org/lapack/lug/lapack_lug.html. LAPACK Users' Guide. Third Edition. Philadelphia, PA: SIAM Publications.
Thisted, R. A. 1988. Elements of Statistical Computing. New York, NY: Chapman and Hall.
Anderson, E., et al. 1999. LAPACK Users' Guide. Philadelphia, PA: SIAM Publications.
Golub, G. H. and Van Loan, C. F. 1983. Matrix Computations. Baltimore, MD: Johns Hopkins University Press.
See Also
qr.coef, qr.Q, qr.R, qr.X, eigen, svd, chol, backsolve, solve,
Examples
x <- matrix(runif(10), 5, 2)
q <- qr(x)
is.qr(x)   #  FALSE
is.qr(q)   #  TRUE

x <- runif(10) y <- rnorm(10) qr(lm( y~x , qr = TRUE) ) # OK qr(lm( y~x , qr = FALSE) ) # Error: lm object does not have a proper 'qr' component.

Package base version 6.0.0-69
Package Index