首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有pglm模型的r Stargazer --在plm模型中转换二叉神经pglm模型

具有pglm模型的r Stargazer --在plm模型中转换二叉神经pglm模型
EN

Stack Overflow用户
提问于 2017-02-10 13:56:16
回答 5查看 2.7K关注 0票数 3

我正在使用stargazer创建我的plm汇总表。

代码语言:javascript
复制
library(plm)
library(pglm)
data("Unions", package = "pglm")
anb1 <- plm(wage ~ union + exper + rural, Unions, model = "random", method = "bfgs")
stargazer(anb1)

不幸的是,观星者不支持pglm模型。我正在寻找一个关于如何绘制带有二元因变量的pglm模型的结果的解决方案,因为下面的占星器调用不适用于pglm模型。

代码语言:javascript
复制
anb2 <- pglm(union ~ wage + exper + rural, Unions, family = "binomial",
            model = "random", method = "bfgs")
stargazer(anb2)

有什么替代方法只提取每个摘要项并将其分别格式化吗?结果的类别如下:

1 "maxLik“”格言“”列表“

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2017-05-19 10:33:18

下面是一个简单的提取函数,可以让texreg与pglm一起工作:

代码语言:javascript
复制
extract.pglm <- function (model, include.nobs = TRUE, include.loglik = TRUE, ...) {
   s <- summary(model, ...)
   coefficient.names <- rownames(s$estimate)
   coefficients <- s$estimate[, 1]
   standard.errors <- s$estimate[, 2]
   significance <- s$estimate[, 4]
   loglik.value <- s$loglik
   n <- nrow(model$model)
   gof <- numeric()
   gof.names <- character()
   gof.decimal <- logical()
   if (include.loglik == TRUE) {
      gof <- c(gof, loglik.value)
      gof.names <- c(gof.names, "Log-Likelihood")
      gof.decimal <- c(gof.decimal, TRUE)
   }
   if (include.nobs == TRUE) {
      gof <- c(gof, n)
      gof.names <- c(gof.names, "Num. obs.")
      gof.decimal <- c(gof.decimal, FALSE)
   }
   tr <- createTexreg(coef.names = coefficient.names, coef = coefficients, 
                 se = standard.errors, pvalues = significance, gof.names = gof.names, 
                 gof = gof, gof.decimal = gof.decimal)
   return(tr)
}

为了使此代码工作,还应该注册函数,以便在调用maxLik时默认情况下处理pglm extract对象:

代码语言:javascript
复制
setMethod("extract", signature = className("maxLik", "maxLik"), 
      definition = extract.pglm)

之后,您可以在pglm中使用texreg,就像使用plm或其他由texreg支持的模型一样。

票数 4
EN

Stack Overflow用户

发布于 2019-06-25 17:55:00

这里有一个简单得多的解决方案。截止2019年6月25日,观星者仍然不支持pglm,但coeftest只是通过coeftest将模型传递给观星者。

(还请注意自@giamcomo以来pglm中数据对象名称的更改)

代码语言:javascript
复制
library(plm)
library(pglm)
library(lmtest)
library(stargazer)
data("UnionWage", package = "pglm")

anb2 <- pglm(union ~ wage + exper + rural, UnionWage, family = "binomial",
             model = "random", method = "bfgs")

stargazer(anb2)

summary(anb2)

stargazer(coeftest(anb2), type="text")

这是输出

代码语言:javascript
复制
> stargazer(anb2)

% Error: Unrecognized object type.
> 
> summary(anb2)
--------------------------------------------
Maximum Likelihood estimation
BFGS maximization, 35 iterations
Return code 0: successful convergence 
Log-Likelihood: -1655.034 
5  free parameters
Estimates:
            Estimate Std. error t value  Pr(> t)    
(Intercept) -3.43651    0.29175 -11.779  < 2e-16 ***
wage         0.82896    0.15014   5.521 3.37e-08 ***
exper       -0.06590    0.02318  -2.843  0.00447 ** 
ruralyes     0.07558    0.24866   0.304  0.76116    
sigma        4.26050    0.22606  18.847  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
--------------------------------------------
> 
> stargazer(coeftest(anb2), type="text")

====================================
             Dependent variable:    
         ---------------------------

------------------------------------
wage               0.83***          
                   (0.15)           
exper             -0.07***          
                   (0.02)           
ruralyes            0.08            
                   (0.25)           
sigma              4.26***          
                   (0.23)           
Constant          -3.44***          
                   (0.29)           
====================================
====================================
Note:    *p<0.1; **p<0.05; ***p<0.01
> 
票数 4
EN

Stack Overflow用户

发布于 2017-05-01 17:13:49

一个可能的解决方案是执行以下操作。

代码语言:javascript
复制
anb2 <- pglm(union ~ wage + exper + rural, Unions, family = "binomial",
         model = "random", method = "bfgs")
model = summary(anb2)

加载或安装以下库

代码语言:javascript
复制
 library(dplyr)
 library(xtable)
 library('gtools')

创建一个具有协变量名称的向量。

代码语言:javascript
复制
var = c('Intercept', 'wage', 'exper', 'ruralyes', 'sigma')

那就去做

代码语言:javascript
复制
 model_summary = model$estimate %>% as.data.frame() %>% 
 mutate(term = var, Estimate = round(Estimate, 2), SE = round(`Std. error`, 2), p.value = stars.pval(`Pr(> t)`)) %>% 
 select(term, Estimate, SE, p.value)

 > model_summary
        term Estimate   SE p.value
 1 Intercept    -2.86 0.23     ***
 2      wage     0.12 0.02     ***
 3     exper    -0.06 0.02       *
 4  ruralyes     0.09 0.25        
 5     sigma     4.30 0.23     ***

然后您可以在xtable上使用data.frame。

代码语言:javascript
复制
 library(xtable)
 xtable(model_summary)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42161129

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档