welcome to the site! A couple of comments first:
- Your question is a bit borderline for CrossValidated because it is not so much about the statistics but more about the software. Hence, StackOverflow (with [r] and [party] tags) would probably have been more appropriate.
- The question does have a statistical background, though, namely that the distinction between categorical variables (coded as factors in R) and numerical variables plays an important role for the
ctree()
and mob()
algorithms in party
/partykit
. (In other tree algorithms such as CART/rpart
it does not as much.)
- The
partykit
package is now preferred over the older party
package. The problem you describe occurs equally in both versions, though. However, glmtree()
has a nicer interface than the old mob()
.
Now for the answer itself. The decision which plot to choose in a visualization is made based on the classes of the dependent variable and the regressor variable(s). In this case regen_pipo
and YEAR.DIFF
are both numeric, hence a scatter plot is employed. But, of course, regen_pipo
is conceptually a binary categorical variable and would thus be better coded as a factor. Similarly, FIRE.SEV
should probably be an ordered factor. Then mob()
would have taken a different (and more appropriate) parameter stability test to assess whether the model should be split in FIRE.SEV
.
Combining all comments above, I would have used the following code. (I wasn't sure what 0/1 stand for in regen_pipo
, better factor labels would be nice in the spinograms.) Data:
data.pipo <- read.csv("https://raw.githubusercontent.com/CaitLittlef/fia-regen/master/data.pipo.short.csv")
data.pipo <- transform(data.pipo,
regen_pipo = factor(regen_pipo),
FIRE.SEV = factor(FIRE.SEV, ordered = TRUE)
)
Model-based tree:
library("partykit")
tree.mob <- glmtree(regen_pipo ~ YEAR.DIFF | I(YEAR.DIFF) + BALive_pipo + BALiveTot + CMD_1995 + MAP_1995 + FIRE.SEV,
data = data.pipo, family = binomial(link = "logit"), minsplit = 50)
plot(tree.mob)
Notes:
- The variables
def59_z_03
and def68_z_03
from your question were not part of the CSV and are hence omitted in my example.
- It is fine to use
YEAR.DIFF
as both regressor and partitioning variable. However, some defaults (such as the right plot) have an easier time if there are two separate columns in the model frame. Hence, I used I(YEAR.DIFF)
as the partitioning variable. Yields the same tree but different default plot.