Library: | stats |
See also: | linregstep linregbs linregopt gls linregfs linregres doglm |
Quantlet: | linregfs2 | |
Description: | computes a forward selection for a multiple linear regression model. |
Usage: | {b,bse,bstan,bpval,Vin,MSSRin} = linregfs2(x, y, colname{, opt}) | |
Input: | ||
x | n x p x d1 x ... x dk array, independent variables | |
y | n x 1 x d1 x ... x dk array, dependent variable(s) | |
colname | n x 1 string vector, names of explanatory variables | |
opt | list of optional parameters, set by linregopt | |
Output: | ||
b | p x 1 x d1 x ... x dk array, estimates of regression coefficients | |
bse | p x 1 x d1 x ... x dk array, standard errors of estimates | |
bstan | p x 1 x d1 x ... x dk array, standardized estimates | |
bpval | p x 1 x d1 x ... x dk array, p-values of estimates | |
Vin | m x 1 vector (m <= p) of indices of significant explanatory variables | |
MSSRin | scalar, mean residual sum of squares |
The forward selection routine fits first a simple linear regression for each of the p potential x variables. For each simple linear regression model, F-statistic for testing whether or not the slope is zero is obtained. After entering a significant variable x_k (in the sense that this variable contributes significantly to the SSM), all regression models with two x variables are fitted where x_k is one of the pair. The partial F-test statistics examines whether another x variable is significant for inclusion. The procedure stops if no further x variable can be added. If there is no variable significant to enter in the first step, the estimation contains only the intercept.
library("stats") setenv("outputstringformat", "%s") x1 = #(7,1,11,11,7,11,3,1,2,21,1,11,10) x2 = #(26,29,56,31,52,55,71,31,54,47,40,66,68) x3 = #(6,15,8,8,6,9,17,22,18,4,23,9,8) x4 = #(60,52,20,47,33,22,6,44,22,26,34,12,12) x = x1~x2~x3~x4 y = #(78.5,74.3,104.3,87.6,95.9,109.2,102.7,72.5) y = y|#(93.1,115.9,83.8,113.3,109.4) colname=string("X %.f",1:cols(x)) opt = linregopt("Fin",4.0) {b,bse,bstan,bpval} = linregfs2(x,y,colname,opt)
Contents of string [1,] In : X 1 Contents of string [1,] In : X 2 Contents of Enter [ 1,] Forward Selection [ 2,] ------------------------------ [ 3,] F-to-enter 4.00 [ 4,] probability of F-to-enter 0.95 [ 5,] [ 6,] Step Multiple R R^2 F SigF Variable(s) [ 7,] 1 0.8213 0.6745 22.799 0.001 In: X 4 [ 8,] 2 0.9861 0.9725 176.627 0.000 In: X 1 [ 9,] 3 0.9911 0.9823 166.832 0.000 In: X 2 [10,] [11,] Variable entered at Step Number 3: X 2 Contents of ANOVA [ 1,] [ 2,] A N O V A SS df MSS F-test P-value [ 3,] _________________________________________________________________________ [ 4,] Regression 2667.790 3 889.263 166.832 0.0000 [ 5,] Residuals 47.973 9 5.330 [ 6,] Total Variation 2716 12 226.314 [ 7,] [ 8,] Multiple R = 0.99113 [ 9,] R^2 = 0.98234 [10,] Adjusted R^2 = 0.97645 [11,] Standard Error = 2.30874 Contents of Summary [1,] Variables in the Equation for Y: [2,] [3,] [4,] PARAMETERS Beta SE StandB t-test P-value Variable [5,] __________________________________________________________________________________ [6,] b[ 0,]= 71.6483 14.1424 0.0000 5.0662 0.0007 Constant [7,] b[ 1,]= 1.4519 0.1170 0.5677 12.4100 0.0000 X 1 [8,] b[ 2,]= 0.4161 0.1856 0.4304 2.2418 0.0517 X 2 [9,] b[ 3,]= -0.2365 0.1733 -0.2632 -1.3650 0.2054 X 4