gpt4 book ai didi

r - 如何解决mlogit边际效应错误?

转载 作者:行者123 更新时间:2023-12-02 04:50:33 24 4
gpt4 key购买 nike

在 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提前致谢

最佳答案

effects() 需要一个模型对象作为它的第一个参数。但是 m 不是模型对象。相反,它是在模型对象上运行 summary() 函数的输出。而是尝试

m <- mlogit(TypOfCr~1|OneOrTwoVeh|1,data=mnldata,reflevel="PDO") 

(即创建模型对象,而不是模型对象的摘要)并将其提供给 effects()

关于r - 如何解决mlogit边际效应错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29203057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com