qr.coef
Use a QR Matrix Decomposition
Description
Functions of a QR decomposition with a vector or matrix representing
the response.
Usage
qr.coef(qr, y)
qr.fitted(qr, y, k = qr$rank)
qr.resid(qr, y)
qr.qty(qr, y)
qr.qy(qr, y)
qr.solve(a, b, tol = 1e-07)
Arguments
qr |
an object of class "qr" representing a QR decomposition.
Typically, this comes from a previous call to qr or lsfit.
|
y |
a 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).
|
b |
a vector or matrix containing the right-hand sides of the equation
(qr.solve only).
|
tol |
the tolerance for detecting linear dependencies among columns of a
when a is a matrix (qr.solve only).
|
k |
not supported in Spotfire Enterprise Runtime for R.
|
Value
qr.coef, qr.fitted, qr.resid | return the coefficients,
the fitted values, and the residuals obtained by a least squares
fit of y to the x matrix, from which qr was obtained.
|
qr.qy, qr.qty | return the results of the matrix multiplications:
Q %*% y and 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. |
References
Anderson, E.,
Bai, Z.,
Bischof, C.,
Blackford, S.,
Demmel, J.,
Dongarra, J.,
Du Croz, J.,
Greenbaum, A.,
Hammarling, S.,
McKenney, A.,
Sorensen D.,
(1999).
LAPACK Users' Guide.
SIAM, Philadelphia.
Thisted, R. A. (1988).
Elements of Statistical Computing.
Chapman and Hall, New York.
Differences between Spotfire Enterprise Runtime for R and Open-source R
- In Spotfire Enterprise Runtime for R, the argument k for qr.fitted is not supported and returns an error if used.
- In open-source R, qr.solve returns a vector of zeros when y contains NAs. In Spotfire Enterprise Runtime for R, an
error is returned.
- In open-source R, qr.coef computes the coefficients with the LAPACK
function qr_coef_cmplx for complex data, regardless if qr's
attribute useLAPACK is TRUE or FALSE. For non-complex data, it computes
with the LAPACK function qr_coef_real when useLAPACK is TRUE
and the LINPACK function DQRCF when useLAPACK is FALSE.
- In open-source R, qr.fitted does not support LAPACK QR. It calls the LINPACK function DQRXB.
- In open-source R, qr.resid does not support LAPACK QR. It calls the LINPACK function DQRRSD.
- In open-source R, qr.qy computes the result with LAPACK
function qr_qy_cmplx for complex data, regardless if qr's
attribute useLAPACK is TRUE or FALSE. For non-complex data, it computes
with the LAPACK function qr_qy_real when useLAPACK is TRUE
and the LINPACK function DQRQY when useLAPACK is FALSE.
- In open-source R, qr.qty computes the result with the LAPACK
function qr_qy_cmplx for complex data regardless if qr's
attribute useLAPACK is TRUE or FALSE. For non-complex data, it computes
with the LAPACK function qr_qy_real when useLAPACK is TRUE
and the LINPACK function DQRQTY when useLAPACK is FALSE.
- In open-source R, qr.solve returns the result of qr.coef(a, b), if a is not an object of class qr;
the QR decomposition is computed first, then qr.coef is called.
Note
The results of qr.coef, qr.fitted, and qr.resid
reflect an intercept term only if an intercept column is added to the matrix
(as in a call to lm.fit).
The QR decomposition used does not contain an explicit orthogonal (or unitary)
matrix.
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(x, y, method = "qr")
coef(reg0)
qr.coef(reg0$qr, y) # same values as coef(reg0)
qr.solve(x, y) # also same values as coef(reg0)
z1 <- qr.fitted(reg0$qr, y)
z2 <- qr.resid(reg0$qr, y)
z3 <- qr.qy(reg0$qr, y)
z4 <- qr.qty(reg0$qr, y)