0

I have constructed a glmtree and I want to have err displayed in both my tree summary and plot.

I have managed to have the err displayed in the plot by plot(output_tree, type="simple")

but how to have err displayed in my tree summary: my tree only has intercept but no err

output

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tilly Tan
  • 1
  • 1

1 Answers1

0

If the glmtree is fitted with just an intercept then it can be coerced to a constant-fit tree (class constparty). By default, the coefficients are shown to emphasize that a model is built in each leaf. But if there is just an intercept then it also makes sense to summarize the tree with a constant fitted proportion of the response.

Prepare the Titanic data:

data("Titanic", package = "datasets")
ttnc <- as.data.frame(Titanic)
ttnc <- ttnc[rep(1:nrow(ttnc), ttnc$Freq), 1:4]

Fit a binomial GLM tree with just an intercept:

library("partykit")
tr <- glmtree(Survived ~ ., data = ttnc, family = binomial, alpha = 0.01)

Coercion to constparty:

tr <- as.constparty(tr)
tr
## Model formula:
## Survived ~ 1 + (Class + Sex + Age)
## 
## Fitted party:
## [1] root
## |   [2] Sex in Male
## |   |   [3] Class in 1st: No (n = 180, err = 34.4%)
## |   |   [4] Class in 2nd, 3rd, Crew
## |   |   |   [5] Age in Child
## |   |   |   |   [6] Class in 2nd: Yes (n = 11, err = 0.0%)
## |   |   |   |   [7] Class in 3rd: No (n = 48, err = 27.1%)
## |   |   |   [8] Age in Adult
## |   |   |   |   [9] Class in 2nd, 3rd: No (n = 630, err = 14.1%)
## |   |   |   |   [10] Class in Crew: No (n = 862, err = 22.3%)
## |   [11] Sex in Female
## |   |   [12] Class in 3rd: No (n = 196, err = 45.9%)
## |   |   [13] Class in 1st, 2nd, Crew: Yes (n = 274, err = 7.3%)
## 
## Number of inner nodes:    6
## Number of terminal nodes: 7
Achim Zeileis
  • 15,710
  • 1
  • 39
  • 49