如何在R中创建边际效应表?

3

我有三个有序回归模型,其中有序的因变量范围从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

你想要什么类型的输出?Stargazer只会输出LaTeX或HTML代码,所以你可以根据自己的需要进行调整... - Cyrus Mohammadian
嗨,Cyrus!没错,我想可能有一种方法可以微调它...我基本上想要一个类似stargazer的输出,它们看起来很好,很专业(出版质量表格)。不幸的是,我没有LaTeX方面的经验。 - Boris
你需要解释你想要的输出...使用你提供的数据,Stargazer 对我来说运行良好。不确定你在寻找什么。在使用 Stack Overflow 时,你需要尽可能具体。 - Cyrus Mohammadian
请注意查看“xtable”。 - Cyrus Mohammadian
1个回答

0

这更像是一个建议而不是答案,建议您将其发布为评论! - Cyrus Mohammadian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接