I understand that the common practice to select CP value is by choosing the lowest level with the minimum xerror
value. However, in my following case, using cp <- fit$cptable[which.min(fit$cptable[,"xerror"]),"CP"]
will give me 0.17647059
which will result in no split or just root after pruning with this value.
> myFormula <- Kyphosis~Age+Number+Start
> set.seed(1)
> fit <- rpart(myFormula,data=data,method="class",control=rpart.control(minsplit=20,xval=10,cp=0.01))
> fit$cptable
CP nsplit rel error xerror xstd
1 0.17647059 0 1.0000000 1.000000 0.2155872
2 0.01960784 1 0.8235294 1.000000 0.2155872
3 0.01000000 4 0.7647059 1.058824 0.2200975
Is there any other alternative/ good practice to select the CP value?