I am running a conditional logit model using mclogit function in R. The purpose of the study is to construct a choice model of how factors influence the likelihood of parents choosing a particular school for their children. There are many interactions between individual characteristic and alternative characteristics in the model, and I would like to use margins to calculate marginal effects of variables. However, the error appears as I run margins():
Error in names(classes) <- clean_terms(names(classes)) :
'names' attribute [20] must be the same length as the vector [11]
The same error appears again when running cplot() when trying to plot the marginal effect. I suspect it is some common function that cplot and margins call which yield this error. The mclogit() function yields a (S3: mclogit, lm) class which is composed of 31 lists, whereas a common lm() function yields an object composed of 12 lists.
I am wondering how to solve the problem and if there is any other function for marginal effects on conditional logit model.
Here is a reproductive code, although the error is not exactly then same, and I am using R version 3.6.0:
library(mclogit)
library(margins)
data(Transport)
mc_results <- mclogit(
cbind(resp,suburb)~distance+cost+I(distance*cost),
data=Transport
)
margins(mc_results)
Error in names(classes) <- clean_terms(names(classes)) :
'names' attribute [4] must be the same length as the vector [3]