I am trying to figure out the inner workings of the mob function in the party package. I can't figure out how the splitting variable is selected when it is a categorical variable.
In the publications by the authors, they say that it is done by a chisquare test of association between the residual deviances and the categorical variable. I can't see how this works.
In the toy example below, the mob function works fine. The variable X is the splitting variable.
b <- (1:1000) / 100 - 5
a <- c(b,-b)
b <- c(b, b)
X <- as.factor(c(rep(FALSE, 1000), rep(TRUE, 1000)))
mob(a ~ b | X)
However, if I fit a linear model without splitting, there is (by construction) no association between the residuals and the values of the splitting variable:
res <- sign(residuals(lm(a ~ b)))
table(res, X)
The resulting table is:
X
res FALSE TRUE
-1 499 500
1 501 500
This table does not show that the X variable is important, still the algorithm can figure it out. How is that done?