0
$\begingroup$

I am working with a dataset and am attempting to predict "gross" for a movie. All of the predictors that I have are continuous except for one: color. This categorical variable has two levels: "Black and White" and "Color". Does it make sense to include this categorical variable with all continuous variables such as "budget", "imdb score" and "duration". Would it make sense to code "Black and White"=1 and "Color"=2? If so, what is the easiest way to do this in R. Should I include this variable at all?

$\endgroup$
  • $\begingroup$ R's lm() function converts this categorial value for you into a 2 new bivariate dummy variables/columns "is_white" and "is_black" (or similar name). You see these new columns reported when you call summary(lm()). $\endgroup$ – knb Apr 12 '17 at 8:34
0
$\begingroup$

In short, yes there is no issue with including a categorical predictor alongside all your continuous ones. You are building a general linear model, and while introductory statistics courses often teach a sharp distinction between ANOVA and regression, in reality they all come under the heading of general linear model. In the model output you will get a beta coefficient for the effect of 'color. The coefficient will tell you the average increase in 'gross' of color movies over black and white movies when all other variables are held constant. So it is still useful and interpretable.

You say "Does it make sense to include it". While it certainly makes sense to include it in your initial model, still make sure to assess the diagnostics of your model. It might be that it is not helpful in predicting 'gross'. In that case, you may want to consider removing it.

Questions about how to use R are off topic here, so I will just give you some general advice. No, don't code it as 1 and 2. It makes no difference between the names, and I'd argue that keeping the names makes it easier interpret your model. What is important is that your design matrix is dummy coded (i.e. categorical factors represented as 1s and 0s). If you're in R don't worry - it handles dummy coding for you.

This is not difficult in R. I'd just google 'fitting linear models in R'. The essence of what you want is a model of the form y ~ x1 + x2 + x3.

$\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.