I have a 12-level factor variable (month) in my dataset and I wanted to fit a CART tree with rpart(). Would you split the 12-level factor variable into 12 dummy variables?

If I fit the model with one 12 level factor variable I get better predictions (in comparison to the 12 dummy-variable alternative) but then I have problems with the interpretation because the factor variable is split into (1,5,6,7,8,11) and (2,3,4,9,10,12) in the left side from the root node and in (3,6,9,10,12) and (1,2,4,5,7,8,11) in the right side from the root node.

So I am not sure if I should split the 12-level factor variable into 12 dummy variables?

  • $\begingroup$ I would, in general, leave it as a single factor. But it depends (as so many things do) on context. What is the split from the root node? Why did you include month? Is month acting as a surrogate for something like weather? If so, can you substitute something like average temperature? What is the DV? etc. $\endgroup$ – Peter Flom Aug 31 '12 at 13:31
  • $\begingroup$ got the data from: archive.ics.uci.edu/ml/datasets/Bank+Marketing In the documentation I read that usually a contract made in the last month of a quartal is more likely than in onther monts so I thought that the variable is important. The split from the root node is the variable "duration". $\endgroup$ – Giuseppe Aug 31 '12 at 13:45
  • 1
    $\begingroup$ In that case, you might want to try a variable "last month" which would be 1 if it was the last month of a quarter and 0 otherwise. Or you might want to use month as is and show that the idea in the documentation isn't true for your data, or only for one node. (3,6,9,10,12) is close to (last month). $\endgroup$ – Peter Flom Aug 31 '12 at 14:11
  • $\begingroup$ Jap that was also my idea but if i make 3 dummy variables for (first month, second month and thirt month of a quartal) i have to delete the original month variable otherwise the variable lastmonth won't be selected. And if I delete the month variable i can proove that the idea in the documentation is true (but I'll get a modell with higher missclassification error) for my data but I am not sure if this its a good idea deleting an important variable only for a good interpretation. $\endgroup$ – Giuseppe Aug 31 '12 at 14:53

Your Answer

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

Browse other questions tagged or ask your own question.