2
$\begingroup$

I'm doing some work in R using the gbm package. I'm curious about the repercussions of treating categorical variables as factors or using 1/0 flags for each individually. Is there any literature on how the 2 are handled either in gbm or in R in general?

$\endgroup$
1
  • 1
    $\begingroup$ Have you read the help page for contrasts? $\endgroup$
    – whuber
    Commented Jan 23, 2013 at 15:15

1 Answer 1

2
$\begingroup$

In most cases, it will not make any difference if you create dummys yourself (I guess that is what flags means) or use a factor variable and let the software make the dummys. In both cases, a complete set of dummys will be linearly dependent, so you will need to use a reduced set. How you do the reduction changes the parameterization of the model, but not the predictions it produces.

If your software can do this for you, there should be little reason to do it "by hand".

If you have data, say, from a questionnaire of the type "mark any that applies", that could be represented by flags, but not by a factor variable. If you estimate a model using regularization (lasso/ridge/elastic net), then you should use the complete set of dummys, the regularization takes care of the problems caused by linear dependence, and which dummy you omitted could actually change the predictions! But good lasso software (like glmnet) should take care of that.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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