Computes the orthogonal-triangular (QR) decomposition of a matrix x, such that: \(X = Q_1R\)
x (NxP matrix) – data
r (KxP matrix) – upper triangular matrix, \(K = min(N,P)\).
Given \(X\), there is an orthogonal matrix \(Q\) such that \(Q'X\) is zero below its diagonal, i.e.,
where \(R\) is upper triangular. If we partition
where \(Q_1\) has \(P\) columns, then
is the QR decomposition of \(X\). If \(X\) has linearly independent columns, \(R\) is also the Cholesky factorization of the moment matrix of \(X\), i.e., of \(X'X\).
qr() does not return the \(Q_1\) matrix because in most cases it is not
required and can be very large. If you need the \(Q_1\) matrix, see the
qqr(). If you need the entire \(Q\) matrix, call
qyr() with \(Y\) set to a
conformable identity matrix.
For linear equation or least squares problems, which require \(Q_2\) for
computing residuals and residual sums of squares, see
If \(N < P\), the factorization assumes the form:
where \(R_1\) is a PxP upper triangular matrix and \(R_2\) is \(P \times (N-P)\). Thus \(Q\)
is a PxP matrix and \(R\) is a PxN matrix containing \(R_1\) and \(R_2\). This
type of factorization is useful for the solution of underdetermined
systems. However, unless the linearly independent columns happen to be
the initial rows, such an analysis also requires pivoting (see