The constparty
objects in partykit
currently do not have a deviance()
method because they don't assume a formal model. The method is completely nonparametric. (The model-based glmtree()
objects do provide a deviance()
method.) However, it might be useful in some cases...I'll discuss with Torsten whether we should add it for constparty
as well.
In any case, it is not very difficult to set up the binomial deviance for your example "by hand". The fitted()
method provides the predicted node ID and the observed response. The predict(..., type = "prob")
method yields the predicted probabilities. With these two pieces of information you can directly compute the deviance as:
obs <- fitted(rp.party)[, "(response)"]
pred <- predict(rp.party, type = "prob")
-2 * sum(log(pred[cbind(1:nrow(pred), as.numeric(obs))]))
## [1] 46.90789
Or you can re-fit a constant in every terminal node using glm()
and extract the deviance()
from that:
deviance(glm(`(response)` ~ factor(`(fitted)`),
data = fitted(rp.party), family = binomial))
## [1] 46.90789