# default plot for mob object (glm tree) not returned; using party package [closed]

I'm trying to plot a glm tree using the package party. Per the reference guide, the default plot of the terminal node should be a spinogram as in this image but I am only getting scatterplots at the final node. Dataset is here.

tree.mob <- mob(regen_pipo ~ YEAR.DIFF
| YEAR.DIFF + BALive_pipo + BALiveTot
+ def59_z_03 + def68_z_03
+ CMD_1995 + MAP_1995
+ FIRE.SEV,
data = data.pipo,
model = glinearModel, family = binomial(link = "logit"),
control = mob_control(minsplit = 50))
plot(tree.mob)


Even this doesn't generate the spinogram -- which I think should explicitly enforce it.

plot(tree.mob, terminal_panel=node_bivplot(tree.mob, cdplot = FALSE))


I'd appreciate any guidance!

## closed as off-topic by mkt, Michael Chernick, mdewey, Peter Flom♦Jan 31 at 10:50

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – mkt, Michael Chernick, mdewey, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

• Hello! I understand that this question may be more appropriate for Stack Overflow (as @AchimZeileis helped me to understand in his exceptionally helpful response). Is there a way for me to transfer the question to that forum? Or is it destined to languish, closed, here on Cross Validated? Thanks for your patience with a new user! – ltlf653 Feb 3 at 15:38

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.