olsqr¶
Purpose¶
Computes OLS coefficients using QR decomposition.
Format¶
-
b =
olsqr(depvar, indepvars)¶ Parameters: - depvar (Nx1 vector) – dependent variable
- indepvars (NxP matrix) – independent variables
Returns: b (Px1 vector) – least squares estimates of regression of depvar on indepvars. If depvar does not have full rank, then the coefficients that cannot be estimated will be zero.
Examples¶
// Random matrices
x = rndn(4, 4);
y = rndn(4, 1);
// Solve OLS coefficient using QR decomposition
b = olsqr(y, x);
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 olsqr() procedure handles matrices that do not have full rank by returning zeros for
the coefficients that cannot be estimated.