我使用 mlgit() 包在 R 中运行了嵌套 Logit 模型。我现在正在尝试测量边际效应/弹性并继续遇到错误。在这里,我通过修改包作者的小插图重新创建了错误:
data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")
m <- mlogit(mode ~ price | income | catch, data = Fish,
nests=list(water=c("boat","charter"),
land=c("beach","pier")))
# compute a data.frame containing the mean value of the covariates in the sample
z <- with(Fish, data.frame(price = tapply(price, index(m)$alt, mean),
catch = tapply(catch, index(m)$alt, mean),
income = mean(income)))
# compute the marginal effects (the second one is an elasticity
effects(m, covariate = "income", data = z)
我收到以下错误:
Error in `colnames<-`(`*tmp*`, value = c("beach", "boat", "charter", "pier" :
attempt to set 'colnames' on an object with less than two dimensions
In addition: Warning message:
In cbind(Gb, Gl) :
number of rows of result is not a multiple of vector length (arg 2)
当我没有嵌套模型(如常规多项式 Logit)时,这可以正常工作,并且在之前的一些 stackoverflow 问题中已经涵盖了这一点,但是在重新预测更改的数据帧的步骤中特别发生了一些奇怪的事情(在这种情况下意味着框架z)。
我会注意到这里的解决方案:mlogit 在 R 中的边际效应对我没有帮助。