qtyr#

Purpose#

Computes the orthogonal-triangular (QR) decomposition of a matrix X and returns QY and R.

Format#

{ qty, r } = qtyr(y, X)#
Parameters:
  • y (NxL matrix) – data

  • X (NxP matrix) – data

Returns:
  • qty (NxL matrix) – unitary matrix

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

Examples#

The QR algorithm is the numerically superior method for the solution of least squares problems:

loadm x, y;
{ qty, r } = qtyr(y, x);
q1ty = qty[1:rows(r), .];
q2ty = qty[rows(r)+1:rows(qty), .];

// LS coefficients
b = qrsol(q1ty, r);

// Residual sums of squares
s2 = sumc(q2ty^2);

Remarks#

Given X, there is an orthogonal matrix Q such that QX is zero below its diagonal, i.e.,

QX=[R0]

where R is upper triangular. If we partition

Q=[Q1Q2]

where Q1 has P columns, then

X=Q1R

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 XX. For most problems Q or Q1 is not what is required. Rather, we require QY or Q1Y where Y is an NxL matrix (if either QY or Q1Y are required, see qyr()). Since Q can be a very large matrix, qtyr() has been provided for the calculation of QY which will be a much smaller matrix. Q1Y will be a submatrix of QY. In particular,

G=Q1Y=qty[1:P,.]

and Q2Y is the remaining submatrix:

H=Q2Y=qty[P+1:N,.]

Suppose that X is an NxK dataset of independent variables, and Y is an Nx1 vector of dependent variables. Then it can be shown that

b=R1G

and

sj=i=1NPHi,jj=1,2,...L

where b is a PxL matrix of least squares coefficients and s is a 1xL vector of residual sums of squares. Rather than invert R directly, however, it is better to apply qrsol() to

Rb=Q1Y

For rank deficient least squares problems, see qtyre() and qtyrep().

Source#

qtyr.src

See also

Functions qqr(), qtyre(), qtyrep(), olsqr()