Stata 15 help for mf__lsfitqr


[M-5] _lsfitqr() -- Least-squares regression using QR decomposition


real matrix _lsfitqr(real matrix X, real matrix Y, real colvector wt, real scalar cons, real scalar rank, real matrix E, real matrix r, real matrix R, real rowvector p, | real scalar tol)


_lsfitqr(X, Y, wt, cons, rank, E, r, R, p, | tol) computes the least-squares regression fit of Y on X using the positive weights wt. If no weights are needed, use wt = J(0,1,0). Use cons = 1 if you want a constant term in the model and a column of ones is not in X already.


_lsfitqr() returns a matrix of regression coefficients from regressing Y on X. Weights, wt, are optional. A constant term is added to the model if cons is nonzero. The rank of the model is returned in rank, the residual covariance is returned in E, the regression mean square matrix in r. The upper triangular matrix R is from the QR decomposition and p is the pivot vector. Letting q = invorder(p) and Z = R[q,q], then X'X = Z'Z.

On return, Y contains the predicted values, X*b = Q1*Q'Y. See qrd() for a definition of Q1. X and wt are modified. When _lsfitqr() adds the constant term it is not pivoted and the regression mean squares is adjusted for the mean. The tolerance used to determine the rank of the regression, tol, is passed through to _solveupper(). _lsfitqr() uses 2^10 as a default value. See _solveupper() on how tol is used to determine the rank of the regression.


_lsfitqr(X, Y, wt, cons, rank, E, r, R, p, | tol): X: n x k Y: n x m wt: n x 1 or 0 x 1 cons: 1 x 1 rank: 1 x 1 E: m x m r: m x m R: k x k p: 1 x k tol: 1 x 1 result: k x m


The rows of Y and X must be equal unless X = J(0,0,0). If X = J(0,0,0), cons must be nonzero. The weights, wt, are ignored unless length(wt) == n.

Source code


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index