0

I have a linear regression model:

$Y~X_1+X_2+X_3+X_4+X_5+X_6+X_7+X_8+X_9$ and I need to create a function that find all possible models (e.g.

  • $Y = X_1+X_2+X_3+X_4$

  • $Y = X_2+X_3+X_4$

  • $Y = X_1+X_3+X_4+X_5+X_6$ etc) and then calculates each model's DIC values.

Can someone help me since I'm not experienced at programming?

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467
j.erm
  • 3
  • 1

1 Answers1

-2

Just use a backward or forward method to do so.

Forward: Just add and remove all your independent variables and see how each variable affect the model. Then keep adding and subtracting variables until you got a good model.

Backward: Add all variables and then remove them one by one and readd them to evaluate your model.

arezaie
  • 157
  • 9
  • 2
    On could argue that "just use" should rather be replaced with "don't use": http://stats.stackexchange.com/questions/20836/algorithms-for-automatic-model-selection/20856#20856 – Tim Apr 04 '17 at 08:17
  • Fitting every model and using a criterion (AIC, BIC, BICc) is a valid way to do model selection for a small number of predictors. Backwards and forward variable selection have fallen out of favor because they produce highly variable results. – Eli Sep 21 '18 at 15:41
  • This algorithm does not explore the "all possible subsets" of models requested in the question. – whuber Sep 21 '18 at 15:42