2
$\begingroup$

I am doing a regression analysis in R, in which I examine the contribution of each car attribute to its price.

Some variables can be coded as a dummy variable, or as a continuous variable. For example, I can add a dummy variable for each number of cylinder (2, 4, 6 or 8), or I can consider this as a continuous variable.

Is there a difference between the two possibilities?

$\endgroup$
3
$\begingroup$

Regressing price $y$ on a constant and the number of cylinders $x$ would make sense if the price was known to be affine in the number of cylinders: the price increase from 2 to 4 cylinders is the same as the price increase from 4 to 6 cylinders and is the same as the price increase from 6 to 8. Then you could run the regression:

$$ y_i = a + b x_i + \epsilon_i $$

On the other hand, it may not be affine in reality. If price isn't affine in number of cylinders, the above model would be misspecified.

What could one do? Let $z_2$ be a dummy variable for two cylinders, let $z_4$ be a dummy variable for 4 cylinders, etc... Since there are only four possibilities (2,4,6, or 8 cylinders), you likely have enough data to run the more complete regression:

$$ y_i = a + b_4 z_{4,i} + b_6 z_{6,i} + b_8 z_{8,i} + \epsilon_i$$

Here the coefficients would $b_4$, $b_6$ etc... would be the price increase relative to a 2 cylinder car. (the constant $a$ would pick up the mean price of a two-cylinder car.)

Or if you run the regression without a constant, you could run:

$$ y_i = b_2 z_{2,i} + b_4 z_{4,i} + b_6 z_{6,i} + b_8 z_{8,i} + \epsilon_i$$

Here the coefficients ($b_2$, $b_4$, $b_6$, $b_8$) would be the mean price of each cylinder type. Observe how the average price no longer is assumed to be affine in the number of cylinders! You could have a small difference between $b_4$ and $b_6$ but a large difference between $b_6$ and $b_8$.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ I believe it's worth mentioning that if you believe your response increase/decreases with a variable, but not linearly, then a third option is to treat a transform (log, ^(.5), ^(1/3), etc) as a continuous variable. $\endgroup$ – Eric Jun 29 '16 at 14:01
0
$\begingroup$

Yes, there is a quite a difference. You should use dummies, as you want to look at the effect of being in one type of cylinder. If you would include them as continous, you would presume, that being in type 4 is better with 2 than type 2 - but, you can't really measure it. http://www.ats.ucla.edu/stat/sas/library/nesug98/p046.pdf Read the intro of this paper, it is pretty straightforward.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ In light of the comments, this answer is no longer (necessarily) correct. Apparently "cylinder type" was supposed to mean "number of cylinders." $\endgroup$ – shadowtalker Jun 29 '16 at 12:46
  • $\begingroup$ Is there then a difference in using a dummy variables instead of a continious variable for number of cylinders? $\endgroup$ – GerritCalle Jun 29 '16 at 13:09
  • $\begingroup$ yes, after the clarification, it is not correct. $\endgroup$ – Zoltán Puha Jun 29 '16 at 14:12
0
$\begingroup$

In the case that a feature can seemingly either treated as continuous or categorical (thus using dummy coding), a trade off should be made. The latter will increase the complexity of your model, the good news is it could capture more complex trend in your data, the bad news is it will make your model "less stable", use Cross Validation to decide which way you should go.

In practical, to use a variable as continuous one, it's not necessarily required that the target value be a linear/affine function of it. (plus, it can't be KNOWN beforehand, otherwise no regression analysis is needed). A correlation check or a scatter plot is really what you have as tools to select and process variables.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ where should I take a look at when examining the correlation or scatter plot to make a decision? $\endgroup$ – GerritCalle Jun 30 '16 at 12:30
  • 1
    $\begingroup$ If the correlation coefficient is away from 0 (i.e. either towards 1 or -1), there's a good chance that this attribute can be included in your linear model. However, the correlation coefficient can be deceiving, in this case scatter plot can give you more detail visualization regarding the relation of the attribute and target value, thus give you hints in how to further transform the attribute before using it in linear model. $\endgroup$ – Ray Chen Jul 2 '16 at 14:41
-2
$\begingroup$

In general, use dummy coding when you think the numerical value of the attribute does not contribute to your target value, otherwise use it as continuous variable. In this case, if you think more cylinders means higher (or lower) price, you should use it as a continuous one. On the other hand, attributes like the number of seats would better be processed by dummy coding.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ This doesn't make sense. Why would you even include a variable you think is irrelevant at all? $\endgroup$ – gung - Reinstate Monica Jun 29 '16 at 12:52
  • $\begingroup$ @gung, sorry, but when did I say that? $\endgroup$ – Ray Chen Jun 29 '16 at 14:01
  • $\begingroup$ "use dummy coding when you think the numerical value of the attribute does not contribute to your target value". $\endgroup$ – gung - Reinstate Monica Jun 29 '16 at 14:05
  • $\begingroup$ @gung, I think I had emphasis the "numerical value" of the attribute, not the attribute itself. I think there is a difference between the two expression (not native English speaker though) $\endgroup$ – Ray Chen Jun 29 '16 at 14:11
  • $\begingroup$ It still doesn't make sense. How are you thinking that the numerical value doesn't matter, but the variable does? $\endgroup$ – gung - Reinstate Monica Jun 29 '16 at 14:14

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.