Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

qr: The QR Decomposition of a Matrix

qrR Documentation

The QR Decomposition of a Matrix

Description

qr computes the QR decomposition of a matrix.

Usage

qr(x, ...)## Default S3 method:qr(x, tol = 1e-07 , LAPACK = FALSE, ...)qr.coef(qr, y)qr.qy(qr, y)qr.qty(qr, y)qr.resid(qr, y)qr.fitted(qr, y, k = qr$rank)qr.solve(a, b, tol = 1e-7)## S3 method for class 'qr'solve(a, b, ...)is.qr(x)as.qr(x)

Arguments

x

a numeric or complex matrix whose QR decomposition is to becomputed. Logical matrices are coerced to numeric.

tol

the tolerance for detecting linear dependencies in thecolumns ofx. Only used ifLAPACK is false andx is real.

qr

a QR decomposition of the type computed byqr.

y, b

a vector or matrix of right-hand sides of equations.

a

a QR decomposition or (qr.solve only) a rectangular matrix.

k

effective rank.

LAPACK

logical. For realx, if true use LAPACKotherwise use LINPACK (the default).

...

further arguments passed to or from other methods

Details

The QR decomposition plays an important role in manystatistical techniques. In particular it can be used to solve theequation\bold{Ax} = \bold{b} for given matrix\bold{A},and vector\bold{b}. It is useful for computing regressioncoefficients and in applying the Newton-Raphson algorithm.

The functionsqr.coef,qr.resid, andqr.fittedreturn the coefficients, residuals and fitted values obtained whenfittingy to the matrix with QR decompositionqr.(If pivoting is used, some of the coefficients will beNA.)qr.qy andqr.qty returnQ %*% y andt(Q) %*% y, whereQ is the (complete)\bold{Q} matrix.

All the above functions keepdimnames (andnames) ofx andy if there are any.

solve.qr is the method forsolve forqr objects.qr.solve solves systems of equations via the QR decomposition:ifa is a QR decomposition it is the same assolve.qr,but ifa is a rectangular matrix the QR decomposition iscomputed first. Either will handle over- and under-determinedsystems, providing a least-squares fit if appropriate.

is.qr returnsTRUE ifx is alistandinherits from"qr".

It is not possible to coerce objects to mode"qr". Objectseither are QR decompositions or they are not.

The LINPACK interface is restricted to matricesx with lessthan2^31 elements.

qr.fitted andqr.resid only support the LINPACK interface.

Unsuccessful results from the underlying LAPACK code will result in anerror giving a positive error code: these can only be interpreted bydetailed study of the FORTRAN code.

Value

The QR decomposition of the matrix as computed by LINPACK(*) or LAPACK.The components in the returned value correspond directlyto the values returned by DQRDC(2)/DGEQP3/ZGEQP3.

qr

a matrix with the same dimensions asx.The upper triangle contains the\bold{R} of the decompositionand the lower triangle contains information on the\bold{Q} ofthe decomposition (stored in compact form). Note that the storageused by DQRDC and DGEQP3 differs.

qraux

a vector of lengthncol(x) which containsadditional information on\bold{Q}.

rank

the rank ofx as computed by the decomposition(*):always full rank in the LAPACK case.

pivot

information on the pivoting strategy used duringthe decomposition.

Non-complex QR objects computed by LAPACK have the attribute"useLAPACK" with valueTRUE.

*)dqrdc2 instead of LINPACK's DQRDC

In the (default) LINPACK case (LAPACK = FALSE),qr()uses amodified version of LINPACK's DQRDC, called‘dqrdc2’. It differs by using the tolerancetolfor a pivoting strategy which moves columns with near-zero 2-norm tothe right-hand edge of the x matrix. This strategy means thatsequential one degree-of-freedom effects can be computed in a naturalway.

Note

To compute the determinant of a matrix (do youreally need it?),the QR decomposition is much more efficient than using Eigen values(eigen). Seedet.

Using LAPACK (including in the complex case) uses column pivoting anddoes not attempt to detect rank-deficient matrices.

Source

Forqr, the LINPACK routineDQRDC (but modified todqrdc2(*)) and the LAPACKroutinesDGEQP3 andZGEQP3. Further LINPACK and LAPACKroutines are used forqr.coef,qr.qy andqr.aty.

LAPACK and LINPACK are fromhttps://www.netlib.org/lapack/ andhttps://www.netlib.org/linpack/ and their guides are listedin the references.

References

Anderson. E. and ten others (1999)LAPACK Users' Guide. Third Edition. SIAM.
Available on-line athttps://www.netlib.org/lapack/lug/lapack_lug.html.

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language.Wadsworth & Brooks/Cole.

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

See Also

qr.Q,qr.R,qr.X forreconstruction of the matrices.lm.fit,lsfit,eigen,svd.

det (usingqr) to compute the determinant of a matrix.

Examples

hilbert <- function(n) { i <- 1:n; 1 / outer(i - 1, i, "+") }h9 <- hilbert(9); h9qr(h9)$rank           #--> only 7qrh9 <- qr(h9, tol = 1e-10)qrh9$rank             #--> 9##-- Solve linear equation system  H %*% x = y :y <- 1:9/10x <- qr.solve(h9, y, tol = 1e-10) # or equivalently :x <- qr.coef(qrh9, y) #-- is == but much better than                      #-- solve(h9) %*% yh9 %*% x              # = y## overdetermined systemA <- matrix(runif(12), 4)b <- 1:4qr.solve(A, b) # or solve(qr(A), b)solve(qr(A, LAPACK = TRUE), b)# this is a least-squares solution, cf. lm(b ~ 0 + A)## underdetermined systemA <- matrix(runif(12), 3)b <- 1:3qr.solve(A, b)solve(qr(A, LAPACK = TRUE), b)# solutions will have one zero, not necessarily the same one

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp