Library: | stats |
See also: | linregstep linregfs2 linregopt gls linregbs linregres doglm |
Quantlet: | linregfs | |
Description: | linregfs computes a simple forward selection for a multiple linear regression model. |
Usage: | {xfs,bfs,pvl} = linregfs (x, y {, alpha}) | |
Input: | ||
x | n x p regressor variables | |
y | n x 1 dependent variable | |
alpha | scalar level of testing | |
Output: | ||
xfs | n x q | |
bfs | q x 1 the estimated regression coefficients | |
pvl | q x 3 the returned p-values |
The returned values are xfs, the selected (q>=1)regressors. The first regressor is always the constant term. bfs contains the regression coefficents. pvl contains the selected variable, the p-values of the significance test and the residual sum of squares divided by the number of observations minus the number of parameters.
; loads the library stats library("stats") ; reset random generator randomize(0) ; generate x x = normal(1000, 3) ; generate y y = 10*x[,3]+x[,1].*x[,2] ; do the forward selection {xfs,bfs,pvl}=linregfs(x, y, 0.05) ; print the regression coefficients and test results bfs~pvl
Contents of _tmp [1,] 0.021854 0 +NAN +NaN [2,] 9.9689 3 0 0.8867 [3,] 0.069415 2 0.017246 0.88256 The result includes the constant term (always first), the third variable and the second variable. The first column are the regression coefficients. The second column are the selected variables (0 means constant term). The third column contains the p-values whereas the last column contains the residual sum of squares divided by n-#parameters.