Use a QR Matrix Decomposition

DESCRIPTION:

Returns functions of a QR decomposition with a vector or matrix representing the response.

USAGE:

qr.coef(qr, y) 
qr.fitted(qr, y) 
qr.resid(qr, y) 
qr.qty(qr, y) 
qr.qy(qr, y) 
qr.solve(a, b, tol=1e-7)

REQUIRED ARGUMENTS:

qr
object representing a QR decomposition. This will typically have come from a previous call to qr or lsfit.
y
vector or matrix of numeric (or complex) data (the "dependent" or "response" data). The length of the vector or the number of rows of the matrix must correspond to the number of rows in the x matrix from which the decomposition was computed.
a
an object representing a QR decomposition or a matrix ( qr.solve only).

OPTIONAL ARGUMENTS:

b
a vector or matrix containing the right-hand sides of the equation ( qr.solve only).
tol
tolerance for detecting linear dependencies among columns of a when a is a matrix ( qr.solve only).

VALUE:

qr.coef, qr.fitted and qr.resid return the coefficients, the fitted values and the residuals that would be obtained by a least squares fit of y to the x matrix from which qr was obtained.

qr.qy and qr.qty return the results of the matrix multiplications: Q %*% y t(Q) %*% y Conj(t(Q)) %*% y (in the complex case) where Q is the order- nrow(x) orthogonal (or unitary) transformation represented by qr.

qr.solve returns the results of solve.qr(a, b) if a is a QR decomposition. This is the least squares solution of x h = b where a is the QR decomposition of x. If a is a matrix, the QR decomposition is computed first, then solve.qr is called.

NOTE:

The results of qr.coef, etc., will reflect an intercept term, if included, for example, in a call to lm.fit.qr.

The QR decomposition used does not return an explicit orthogonal (or unitary) matrix. For reasons of accuracy and efficiency, an indirect representation of the decomposition is used.

REFERENCES:

Dongarra, J. J., Bunch, J. R., Moler, C. B. and Stewart, G. W. (1979). LINPACK Users' Guide. SIAM, Philadelphia.

Thisted, R. A. (1988). Elements of Statistical Computing. Chapman and Hall, New York.

SEE ALSO:

, , ,

EXAMPLES:

x <- cbind(1, runif(20), runif(20, 1, 10))  # X matrix with constant
y <- x %*% c(2, 13.5, -0.7) + rnorm(20, 0, 0.2)
reg0 <- lm.fit.qr(x, y, qr=TRUE)
coef(reg0)
qr.coef(reg0$qr, y)  # same values as coef(reg0)
qr.solve(x, y)  # also same values as coef(reg0)