I am trying to use model-based recursive partitioning (MOB) with the mob() function (from the partykit package) to to obtain the different parameters associated to each feature depending on the optimal partition found using the logistic() regression (glm-binomial) function. I had to define my model.
Following this example on page 7: https://cran.r-project.org/web/packages/partykit/vignettes/mob.pdf I created a logit function that estimates the values and would return the estimates etc. of the logistic() function. However, the definition of the function does not seem to be the correct one.
library(partykit)
logit_func <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
glm(y ~ 0 + x, family = binomial, start = start, ...)
}
p <- mob(future~., data=sample, fit = logit_func)
... and getting the following error
Error in model.frame.default(formula = y ~ 0 + x, drop.unused.levels = TRUE) :
invalid type (NULL) for variable 'x'
The sample dataframe is the following:
sample <- structure(list(future = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L), .Label = c("0", "1"), class = "factor"), HHk = c(0.412585987717856,
1, 1, 1, 1, 1, 1, 1, 0.865684350743137, 0.685221125225357), HHd = c(0.529970735028671,
1, 1, 1, 0.611295754192343, 0.171910197073699, 0.722887386610618,
0.457585763978574, 0.517888089662373, 0.401285262785306), via_4 = structure(c(1L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("0", "1"), class = "factor"),
region_5 = structure(c(1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L), .Label = c("0", "1"), class = "factor")), row.names = c(NA,
10L), class = "data.frame")
Any clue?
Thank you :)