DATA Step, Macro, Functions and more

how to perform model selection

Reply
Contributor
Posts: 48

how to perform model selection

[ Edited ]

 

Dear all,

 

I am not very clear on how to apply  forward stepwise procedure by using AIC in SAS to select a model, and of which is highly recommended by my professor, so I want to try to apply it. 

 

 

e.g.performing forward stepwise procedure in model selection.

 

                  model (1):  y=x1

                  model (2): y=x1+x2

 

My reasoning for the codes: (1) performing forward stepwise selection and getting AIC value of model (1)

                                             (2) performing forward stepwise selection and getting AIC value of model (2)

                                             (3) comparing the AIC value output form model (1) and (2), and choosing the model corresponding to a lower AIC value

 

 

Could anybody check whether my thingking path is correct or not?

If it is correct, I think the codes are also not well-formulated, because actually I have five  more predictor variables. If checking the AIC value one by one, there will be too much repeated work. In this case, I will consider writting a macro, but I don't know how to do currently, could anyone offer me a similiar example on writting a macro for a model selection? 

If my thingking path is wrong, could anyone tell me the correct solution of using stepwise procedure to make a model selection by checking the AIC?

 

Another question is that, in my dataset, there are both categorical variables and continuous variables and I want to make a model selection containing both cases of variables. My initial idea is to convert categorical variables to numeric, for example,  male=0; female=1, but after convertion, the log came up with:

 

WARNING: No variables specified for an SSCP matrix. Execution terminating.

I suspect my solution is wrong, so could anyone offer me some information on how to deal with categorical variable in a multiple regression model?
 

 

 

 

*performing forward stepwise selection and getting AIC value of model (1)
proc reg data=have_1  outest=want_1;
model y = x1 /selection=forward aic;
run;
*print AIC value;
proc print data=want_1;
run;     

*performing forward stepwise selection and getting AIC value of model (2)
proc reg data=have_2  outest=want_2;
model y = x1, x2 /selection=forward aic;
run;
*print AIC value;
proc print data=want_2;
run;     

 

 

Super User
Posts: 17,879

Re: how to perform model selection

If you're testing multiple models and capturing the AIC, which I think you're missing the TABLEOUT option for from a previous question, you may want to use a macro method.

Here's a basic intro on how to do that.

If you're dealing with categorical variables you need to convert them to binary variables or use PROC GLM with them specified as a class variable. If you have time, though you should make the time, the SAS Statistical course is free and will walk you through how to perform a regression and what to look for and how to deal with categorical variables. There are entire courses on this subject so I'm not going to bother trying to explain it here.
Contributor
Posts: 48

Re: how to perform model selection

Thank you for your response, dear Reeza, but one more thing I want to confirm is that whether my reasoning of the codes is correct for model selection?
Respected Advisor
Posts: 4,654

Re: how to perform model selection

You can do forward model selection based on AIC with proc glmselect. Name your categorical variables in the class statement, as in this outline:

 

proc glmselect data=have;

class gender;

model y = x1 x2 gender / selection=forward(choose=aicc);

run;

 

Check the documentation for many more options.

PG
Ask a Question
Discussion stats
  • 3 replies
  • 196 views
  • 0 likes
  • 3 in conversation