我有三个有序回归模型,其中有序的因变量范围从0到2。我的目标是为每个模型的三个级别(0、1和2)创建边际效应表格(而不是图表),因此总共需要三个表格,每个表格显示在0、1和2级别上的边际效应。
## create a random data that is similar to my dataset
set.seed(100)
mydata <- data.frame(
x1 = sample(c(0, 1, 2), 100, replace = TRUE),
x2 = sample(c(0, 1, 2, 3, 4), 100, replace = TRUE),
x3 = sample(c(0, 1, 2, 3, 5), 100, replace = TRUE),
x4 = sample(c(1:100), 100, replace = TRUE),
x5 = sample(c(10:1000), 100, replace = TRUE),
Z1 = sample(c(0, 1, 2), 100, replace = TRUE)
)
## makeit factor
mydata$Z1 <- as.factor(mydata$Z1)
## My models
require(MASS)
M1<- polr(Z1 ~x1+x2+x3+x4, data=mydata, Hess = TRUE, method="logistic")
M2<- polr(Z1 ~x2+x3+x4+x5, data=mydata, Hess = TRUE, method="logistic")
M3<- polr(Z1 ~x1+x2+x3+x4+x5, data=mydata, Hess = TRUE, method="logistic")
## Calculate marginal effects using the erer package
require(erer)
M1ME<- ocME(M1)
M2ME <- ocME(M2)
M3ME <- ocME(M3)
通常我会使用
stargazer
包来创建适当的表格,例如使用:stargazer(M1,M2, M3, type = ”text”)
然而,OcME()的输出并不会生成相同类型的表格,也无法在每个层级上生成表格:
stargazer(M1ME$out,M2ME$out, M3ME$out, type = "text" )
- 您有任何建议如何生成这些类型的表格吗?手动操作非常耗时。
编辑: 因此,理想的输出是创建下面指示的三个表格(注意:数字不正确,只是说明)
边际效应 - 级别0(Z)
==========================================
Dependent variable:
-----------------------------
Z1
(1) (2) (3)
------------------------------------------
x1 0.301 0.302
(0.250) (0.250)
x2 0.143 0.174 0.142
(0.131) (0.128) (0.132)
x3 0.121 0.106 0.122
(0.117) (0.116) (0.117)
x4 -0.008 -0.008 -0.008
(0.007) (0.007) (0.007)
x5 -0.00004 -0.0001
(0.001) (0.001)
------------------------------------------
Observations 100 100 100
==========================================
Note: *p<0.1; **p<0.05; ***p<0.01
边际效应 -- 一级 (Z)
==========================================
Dependent variable:
-----------------------------
Z1
(1) (2) (3)
------------------------------------------
x1 0.301 0.302
(0.250) (0.250)
x2 0.143 0.174 0.142
(0.131) (0.128) (0.132)
x3 0.121 0.106 0.122
(0.117) (0.116) (0.117)
x4 -0.008 -0.008 -0.008
(0.007) (0.007) (0.007)
x5 -0.00004 -0.0001
(0.001) (0.001)
------------------------------------------
Observations 100 100 100
==========================================
Note: *p<0.1; **p<0.05; ***p<0.01
边际效应--第三级(Z)
==========================================
Dependent variable:
-----------------------------
Z1
(1) (2) (3)
------------------------------------------
x1 0.301 0.302
(0.250) (0.250)
x2 0.143 0.174 0.142
(0.131) (0.128) (0.132)
x3 0.121 0.106 0.122
(0.117) (0.116) (0.117)
x4 -0.008 -0.008 -0.008
(0.007) (0.007) (0.007)
x5 -0.00004 -0.0001
(0.001) (0.001)
------------------------------------------
Observations 100 100 100
==========================================
Note: *p<0.1; **p<0.05; ***p<0.01