0
$\begingroup$

I want to build regression model (linear and logit) but one of my independent variables is categorical variable with levels "Gym", "School", "Hospital", "Others". How to incorporate this variables in my model (in R)? Should I convert this variable to dummy variables ("School_dummy", "Hospital_dummy" and "Gym_dummy", without "Others_dummy") or there is another solution? And what if I omit "Gym_dummy" instead of "Others_dummy"? Is it okay or the model is harder to interpret? Because then I want to use step procedure based on AIC criterion in order to choose the most important variables, so it is possible that I end for example only with "Hospital_dummy" in my final model.

$\endgroup$
1
  • $\begingroup$ We have many posts on here explaining the issues with stepwise regression. $\endgroup$ – Dave Jun 1 at 18:28
0
$\begingroup$

If the package you are using accepts categorical factors you should use them as such.

If not, then the option (one-hot-encoding) you mentioned is indeed suitable. If you leave a minimally reproducible example of your code I might be able to help further.

$\endgroup$
0
$\begingroup$

Assuming you're using the base R lm/glm functions:

If you createthe dummy variables yourself, the step process will treat them as separate variables, so you may get some of them removed while the others remain in the model.

You can also feed them into the model as categorical and R will do the dummification for you. When executing step, either the variable stays or is removed altogether, but you won't run into the problem of having only some of the dummy variables in the final model.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.