olsqrmt#

Purpose#

Computes OLS coefficients using QR decomposition.

Format#

b = olsqrmt(depvars indepvars, tol)#
Parameters:
  • depvar (Nx1 vector) – dependent variable

  • indepvars (NxP matrix) – independent variables

  • tol (scalar) – the tolerance for testing if diagonal elements are approaching zero. The default value is 10-14.

Returns:

b (Px1 vector) – least squares estimates of regression of depvar on indepvars. If indepvars does not have full rank, then the coefficients that cannot be estimated will be zero.

Examples#

rndseed 129727134;

// Assign random matrices
x = rndn(150, 4);
y = rndn(150, 1);

// Set tolerance
tol = 1E-10;

// Solve OLS coefficient using QR decomposition
{ b, r, p } = olsqrmt(y, x, tol);

Remarks#

This provides an alternative to \(y/x\) for computing least squares coefficients.

This procedure is slower than the / operator. However, for near singular matrices it may produce better results.

The olsqrmt() procedure handles matrices that do not have full rank by returning zeros for the coefficients that cannot be estimated.

Source#

olsmt.src

See also

Functions olsmt(), olsqr2()