【发布时间】:2019-05-06 23:47:51
【问题描述】:
我正在尝试估计一个有序的 logit 模型,包括。通过遵循代码from this tutorial 在 R 中的边际效应。我使用MASS 包中的polr 来估计模型,并使用erer 包中的ocME 来尝试计算边际效应。
估计模型没问题。
logitModelSentiment90 <- polr(availability_90_ord ~ mean_sentiment, data = data, Hess = T,
method = "logistic")
但是,我遇到了ocME 的问题,它会生成以下错误消息:
ocME(logitModelSentiment90)
Error in eval(predvars, data, env) :
numeric 'envir' arg not of length one
ocME 下面的文档指出,应该使用的对象需要来自 polr 函数,这似乎正是我正在做的。
ocME(w, rev.dum = TRUE, digits = 3)
w = an ordered probit or logit model object estimated by polr from the MASS library.
那么任何人都可以帮助我了解我做错了什么吗?我已经发布了包含模型here 的两个变量的数据子集。在 R 中,我将 DV 设置为因子变量,IV 是连续的。
旁注:
我可以使用RStata 将计算从 R 传递给 Stata,以毫无问题地计算边际效应。但我不想定期这样做,所以我想了解导致 R 和 ocME 出现问题的原因。
stata("ologit availability_90_ord mean_sentiment
mfx", data.in = data)
. ologit availability_90_ord mean_sentiment
Iteration 0: log likelihood = -15379.121
Iteration 1: log likelihood = -15378.742
Iteration 2: log likelihood = -15378.742
Ordered logistic regression Number of obs = 11,901
LR chi2(1) = 0.76
Prob > chi2 = 0.3835
Log likelihood = -15378.742 Pseudo R2 = 0.0000
------------------------------------------------------------------------------
avail~90_ord | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
mean_senti~t | .0044728 .0051353 0.87 0.384 -.0055922 .0145379
-------------+----------------------------------------------------------------
/cut1 | -1.14947 .0441059 -1.235916 -1.063024
/cut2 | -.5286239 .042808 -.6125261 -.4447217
/cut3 | .3127556 .0426782 .2291079 .3964034
------------------------------------------------------------------------------
. mfx
Marginal effects after ologit
y = Pr(availability_90_ord==1) (predict)
= .23446398
------------------------------------------------------------------------------
variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X
---------+--------------------------------------------------------------------
mean_s~t | -.0008028 .00092 -0.87 0.384 -.002609 .001004 7.55768
------------------------------------------------------------------------------
【问题讨论】:
标签: r marginal-effects