I need to implement a backward stepwise regression. I read the chapter from "The Elements of Statistical Learning" however the explanation is poor here:
Backward-stepwise selection starts with the full model, and
sequentially deletes the predictor that has the least impact on the
fit. The candidate for dropping is the variable with the smallest
Z-score
This is taken from chapter 3.3.2 pg:59
I need to know what is the "full model" mentioned here? What will I delete at each level acording to the Z-score? I need to know how this algorithm works step by step.
EDIT: I try to implement the code on matlab. I don't know I'm totally wrong or not :/ Comment on this function please
function [] = BackwardStepWise(X,y,N,p) % X is Nxp matrice y is Nx1 matrice
X = [ones(N,1) X];
% vector for holding column numbers
v= 1:p;
for k=p-1:-1:1
%create matrix with the selected columns
T= [ones(N,1)];
for j=1:k
%add column to the matrix
T = [T X(:,v(1,j)+1)];
endfor
%evaluate beta
beta = inv(T' * T) * T' * y;
%calculate Z-scores for each column
sigmahat_sq = (y-T*beta)'*(y-T*beta)/(N-p-1);
TT = inv(T'*T);
Zmin = 100000;
Zminindex = -1;
for i=1:size(beta,2)
z(i) = beta(i)/sqrt(sigmahat_sq*TT(i,i));
if(z(i) < Zmin)
Zmin = z(i);
Zminindex = i;
endif
endfor
%drop column which has the smallest Z score (edit v vector)
v2 = [];
for i=1:size(v,2)
if(i == Zminindex)
continue;
else
v2 = [v2 v(i)];
endif
endfor
v = v2;
endfor
endfunction
Best Answer
Here is an example using Stata:
The independent variables are
weight
,turn
,headroom
,foreign
, andprice
. The dependent variable ismpg
. The exit criterion is p > 0.2. The first got removed wasprice
(p = 0.9238), followed byheadroom
(p = 0.7047) andturn
(p = 0.2045). The remaining ones have p < 0.2, so they stay.