Computes OLS coefficients using QR decomposition.
depvar (Nx1 vector) – dependent variable
indepvars (NxP matrix) – independent variables
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.
// Random matrices x = rndn(4, 4); y = rndn(4, 1); // Solve OLS coefficient using QR decomposition b = olsqr(y, x);
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.
olsqr() procedure handles matrices that do not have full rank by returning zeros for
the coefficients that cannot be estimated.