1
$\begingroup$

I have a model with one particular variable giving me trouble. It is a factor variable with 2 levels, 'ADT' and 'CHD'

Using the predict(model,data, predict.all=TRUE,nodes=TRUE), I traced things as needed.

The row in question of the model (obtained from getTree(model,1)) shows as seen in pic.

According to documentation, on a factor variable, the splitpoint is the decimal represenation of the binary represenation of the included factors. In case of a 2 factor variable, and the value of 2, the Binary would be '10' My factor levels, confirmed in both the data and the model itself (under xlevels) are 'ADT' and 'CHD'

So the first level would be ADT, second level would be CHD.

However, in the testdata I am predicting, this splits on the right side instead of the left, but since the SplitVar (11) is equal to 'ADT' (level #1) in the test data, it should split to the left.

Is there something I am missing?

TreeFile

$\endgroup$
0
$\begingroup$

In case anyone needs to solve this problem in the future, I found out 2 things:

  1. In the case of a factor with 2 levels, the split point will just refer to the 1st or 2nd level and not the binary representation

  2. The split point binary representation is actually the reverse of the binary representation. So the binary represenation of 102 is 1100110, but it should be interpreted as 0110011

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