Computes the orthogonal-triangular (QR) decomposition of a matrix X and returns \(Q'Y\) and \(R\).


{ qty, r, e } = qtyre(y, x)
  • y (NxL matrix) – data

  • x (NxP matrix) – data

  • qty (NxL matrix) – unitary matrix

  • r (KxP matrix) – upper triangular matrix. \(K = min(N,P)\).

  • e (Px1 vector) – permutation vector


Given \(X[., E]\), where \(E\) is a permutation vector that permutes the columns of \(X\), there is an orthogonal matrix \(Q\) such that \(Q'X[., E]\) is zero below its diagonal, i.e.,

\[\begin{split}Q′X[ ., E ] = \begin{bmatrix} R \\ 0 \end{bmatrix}\end{split}\]

where \(R\) is upper triangular. If we partition

\[Q⁢ = \begin{bmatrix} Q_1 & Q_2 \end{bmatrix}\]

where \(Q_1\) has \(P\) columns, then

\[X[., E] = Q_1R\]

is the QR decomposition of \(X[., E]\).

If \(X\) has rank \(P\), then the columns of \(X\) will not be permuted. If \(X\) has rank \(M < P\), then the \(M\) linearly independent columns are permuted to the front of \(X\) by \(E\). Partition the permuted \(X\) in the following way:

\[X[ ., E ] = \begin{bmatrix} X_1 & X_2 \end{bmatrix}\]

where \(X_1\) is NxM and \(X_2\) is \(N \times (P-M)\). Further partition \(R\) in the following way:

\[\begin{split}R = \begin{bmatrix} R_{11} & R_{12} \\ 0 & 0 \end{bmatrix}\end{split}\]

where \(R_{11}\) is MxM and \(R_{12}\) is \(M \times (P-M)\). Then

\[A = R_{11}^{-1}R_{12}\]


\[X_2 = X_1A\]

that is, \(A\) is an \(M \times (P-N)\) matrix defining the linear combinations of \(X_2\) with respect to \(X_1\).

For most problems \(Q\) or \(Q_1\) is not it is required. Rather, we require \(Q'Y\) or \(Q_1'Y\) where \(Y\) is an NxL matrix. Since \(Q\) can be a very large matrix, qtyre() has been provided for the calculation of \(Q'Y\) which will be a much smaller matrix. \(Q_1'Y\) will be a submatrix of \(Q'Y\). In particular,

\[Q_1'Y = \text{qty}[1:P, .]\]

and \(Q_2'Y\) is the remaining submatrix:

\[Q_2'Y = \text{qty}[P+1:N, .]\]

Suppose that \(X\) is an NxK dataset of independent variables and \(Y\) is an Nx1 vector of dependent variables. Suppose further that \(X\) contains linearly dependent columns, i.e., \(X\) has rank \(M < P\). Then define

\[\begin{split}C = Q_1'Y[1:M, .]\\ A = R[1:M, 1:M]\end{split}\]

and the vector (or matrix of \(L > 1\)) of least squares coefficients of the reduced, linearly independent problem is the solution of

\[Ab = C\]

To solve for b use qrsol():

b = qrsol(C, A);

If \(N < P\), the factorization assumes the form:

\[Q_1'X[.⁢, E] = \begin{bmatrix} R_1 & R_2 \end{bmatrix}\]

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. For the solution of

\[X[.⁢, E]b = Y\]

it can be shown that

b = qrsol(Q'Y, R1)|zeros(N-P,1);



See also

Functions qqr(), qre(), qtyr()