I notice a strange behavior of the lmtree function from the partykit package when I use it with factors. If some levels are not included in the dataset (here "c" and "e"), the predictions change randomly ...
I guess this means that lmtree builds the model only with factors existing in the dataset ("a" and "b" in this example) while the predict function takes into account all factors ("a","b","c","e").
So how can I use safely factors with lmtree models ?
library(partykit)
df<-data.frame(x=runif(100),y=runif(100),v=sample(c("a","b"),100,replace=T))
df$z<-with(df,ifelse(v=="a",2*y+x,3*x-y))
df$v<-factor(df$v,levels=c("c","e","a","b"))
lmt<-lmtree(z~x+y|v,df)
for (i in 1:10) print(predict(lmt,df,type="node")[1])
A similar problem occurs if the order of factor is reversed between the lmtree function and the predict function (changing from levels=c("a","b") to levels=c("b","a") )
lmtree
in? (please include this info in your question ...)