if(require("mlbench") && require("vcd")) {
## synthetic diabetes data
data("SynthDiabetes", package = "mlbench")
## recursive partitioning of a logistic regression model
sd_tree2 <- glmtree(diabetes ~ glucose | pressure + triceps +
insulin + mass + age, data = SynthDiabetes, family = binomial)
## printing whole tree or individual nodes
print(sd_tree2)
print(sd_tree2, node = 1)
## visualization
plot(sd_tree2)
plot(sd_tree2, tp_args = list(cdplot = TRUE))
plot(sd_tree2, terminal_panel = NULL)
## estimated parameters
coef(sd_tree2)
coef(sd_tree2, node = 5)
summary(sd_tree2, node = 5)
## deviance, log-likelihood and information criteria
deviance(sd_tree2)
logLik(sd_tree2)
AIC(sd_tree2)
BIC(sd_tree2)
## different types of predictions
sd <- head(SynthDiabetes)
predict(sd_tree2, newdata = sd, type = "node")
predict(sd_tree2, newdata = sd, type = "response")
predict(sd_tree2, newdata = sd, type = "link")
}
Run the code above in your browser using DataLab