Extract final model from stepwiseglm?

1 vue (au cours des 30 derniers jours)
Jim
Jim le 9 Fév 2017
I'm using stepwiseglm to choose predictors from a large predictor suite (as expected/intended). I run the code;
X = [x1 x2 x3 x4 x5 x6 x7 x8]; mdl = stepwiseglm(X,y,'linear','upper','linear', ... 'Distribution','binomial','Criterion','sse');
and the predictors x1, x4, and x7 are selected by stepwiseglm. At this point though, "mdl" is a model with 8 predictors, not 3. So if I try to use mdl in another program that applies the model to a new set of predictors x1, x4, x7, an error occurs that the model "mdl" expects 8 predictors. That is,
X_new=[x1_new,x4_new,x7_new]; y_predicted=predict(mdl,X_new);
doesn't work. My work around is to manually handle it with:
X_selected = [x1 x4 x7]; mdl2=fitglm(X_selected,y,'distribution','binomial'); y_predicted=predict(mdl2,X_new);
My question is whether I can extract the 3-predictor model from mdl directly as a Class GeneralizedLinearModel so that I don't need to manually enter the selected predictors? There is a lot of information available about mdl, but I don't see anything obvious about where to find the "selected model" as a standalone GeneralizedLinearModel class.
Thanks in advance, Jim

Réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by