在R中成功运行mlogit模型后,我在尝试获得边际效果时遇到错误,如下所示:
"Error in predict.mlogit(object, data) : the number of rows of the data.frame should be a multiple of the number of alternatives"我甚至尝试过更改源代码中的第16行,就像另一篇文章中所解释的那样,但仍然得到相同的错误。任何帮助都将不胜感激。我的所有变量都不是特定于替代的。我有4种选择。
#**model:**(ran successfully)
m<-summary(mlogit(TypOfCr~1|OneOrTwoVeh|1,data=mnldata,reflevel="PDO"))
#**means:**(ran successfully)
z <- with(mnldata, data.frame(OneOrTwoVeh=mean(OneOrTwoVeh)))
#**effects**: effects(m,covariate="OneOrTwoVeh",data=z)
effects(m,covariate="OneOrTwoVeh",data=z)
Error in predict.mlogit(object, data) :
the number of rows of the data.frame should be a multiple of the number of alternatives下面是一个发布在网上的类似问题的链接,但我很难找到发布在那里的解决方案。marginal effects of mlogit in R提前道谢
发布于 2015-03-23 12:21:26
effects()期望模型对象作为其第一个参数。但是m不是一个模型对象。相反,它是在模型对象上运行summary()函数的输出。而不是尝试
m <- mlogit(TypOfCr~1|OneOrTwoVeh|1,data=mnldata,reflevel="PDO") (即,创建一个模型对象,而不是模型对象的摘要),并将其提供给effects()。
发布于 2016-06-12 02:03:35
试试这个:
z <- with(mnldata, data.frame(OneOrTwoVeh = tapply(OneOrTwoVeh, index(m)$alt, mean)))https://stackoverflow.com/questions/29203057
复制相似问题