0
$\begingroup$

I want to build a prediction model where one predictor variable is a score of roman numeral I, II, III, and IV. I am using R and I currently store this feature as factor.

This, however, is not fully representing the available information. In reality, there is a grading of "I" being "best" to "IV" being worst.

One possibility would be to represent these as ordinals using integer 1,2,3,4. Another way I just read about would be using an ordered factor.

I have questions about these approaches:

1) Are prediction models (rpart, randomforest or similar) considering the ordered characteristic of a factor feature or do they treat them just as a regular unordered factor?

EDIT: To put it differently: Does the random forest or rpart see a difference between a factor that has been produced by factor() vs one that has been produced by ordered() or is it the same to these algorithms? Does it affect the prediction?

2) What is the difference between using an integer representation vs using an ordered factor? Which one is desired in which use cases? (I can imagine that ordered factor is useful when the scaling between the ordinal steps is not clear - I for myself do not know if a change from I to II means "double as bad" or "four times as bad").

$\endgroup$
1
$\begingroup$

What is the difference between using an integer representation vs using an ordered factor?

Depends on the model. In GLMs for instance, coding as integers makes the assumption that the difference between 1 and 2 is the same as the difference between 3 and 4. If that is true of your data, then using integers is best as you don't need to estimate 5 coefficients. If however that assumption about the differences between levels is not the case, then using the factor representation is best.

Are prediction models (rpart, randomforest or similar) considering the ordered characteristic of a factor feature or do they treat them just as a regular unordered factor?

Again, depends on the model. Random forests seem to do better for some models when the data are integers. This is completely anecdotal however, and I can't comment on how this generalizes.

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