I want to predict a categorical variable using also categorical predictors. Currently, I am looking at classification and regression trees (CART).

The prediction quality is "good enough", except for the presence of impossible combinations. In the following minimal example, the combination `a==2, b==2` is impossible, yet the estimation decides not to use `b` for splitting.

    > library(rpart)
    > d <- data.frame(a=factor(c(1,1,2)), b=factor(c(1,2,1)))
    > d
      a b
    1 1 1
    2 1 2
    3 2 1
    > xtabs(~., d)
       b
    a   1 2
      1 1 1
      2 1 0
    > rpart(a~b, d)
    n= 3 

    node), split, n, loss, yval, (yprob)
          * denotes terminal node

    1) root 3 1 1 (0.6666667 0.3333333) *

When simulating stochastically from this model (by choosing the leaf value by sampling using the annotated probability vector, here $(2/3, 1/3)$, as weights), the combination `2, 2` will occur. Is there a way to avoid this, perhaps using another method?

This is just a small example for a more general case. I have around 10 predictors, and I want to exclude all combinations of two (or perhaps three) attributes that have no observation in the sample.

I am aware of the "loss matrix" that can be specified as a parameter to `rpart`, but this is prohibitive if many predictors are used.