首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >面板模型(plm)对象上的texreg;附加gof信息

面板模型(plm)对象上的texreg;附加gof信息
EN

Stack Overflow用户
提问于 2018-05-24 19:00:13
回答 2查看 478关注 0票数 6

如何自定义texreg调用中的拟合优度(gof)?

我有一些想要显示的plm模型,但我只得到了"Num. obs.", "Adj. R^2",, "R^2" (参见下面的工作示例)。我想显示所有的小nTF-statisticp-value,我在默认的summary()调用中得到的所有东西。

我得到的一个例子。首先是一些数据和所需的包,

# install.packages(c("wooldridge", "plm", "texreg"), dependencies = TRUE)
library(wooldridge) 
data(wagepan)
library(plm) 

第二,一些模型,

POLS <- plm(lwage ~ educ + black + hisp + exper+I(exper^2)+ married + union +
            factor(year), data = wagepan, index=c("nr","year") , model="pooling")

RE <- plm(lwage ~ educ + black + hisp + exper + I(exper^2) + married + union +
          factor(year), data = wagepan, index = c("nr","year") , model = "random") 

FE <- plm(lwage ~ I(exper^2) + married + union + factor(year), 
          data = wagepan, index = c("nr","year"), model="within")

第三,我当前的texreg调用及其输出,

# library(texreg)                      
texreg::screenreg(list(POLS, RE, FE), custom.coef.map = list('married' = 'Marrtied', 'union' = 'Union'))
#> ================================================
#>            Model 1      Model 2      Model 3    
#> ------------------------------------------------
#> Marrtied      0.11 ***     0.06 ***     0.05 *  
#>              (0.02)       (0.02)       (0.02)   
#> Union         0.18 ***     0.11 ***     0.08 ***
#>              (0.02)       (0.02)       (0.02)   
#> ------------------------------------------------
#> R^2           0.19         0.18         0.18    
#> Adj. R^2      0.19         0.18         0.06    
#> Num. obs.  4360         4360         4360       
#> ================================================
#> *** p < 0.001, ** p < 0.01, * p < 0.05

我确实尝试过添加, include.fstatistic = TRUE,但似乎我不能这样做。这是因为我需要一些额外的定制。

我的目标是像这样的东西,

#> ------------------------------------------------
#> Obs.  (N)   4360         4360         4360       
#> Indiv.(n)    545          545          545       
#> Time  (T)      8            8            8       
#> R^2           0.19         0.18         0.18    
#> Adj. R^2      0.19         0.18         0.06    
#> F-stat       72.458       68.4124      83.8515  
#> P-value        (2.22e-16)   (2.22e-16)   (2.22e-16) 
#> ================================================
#> *** p < 0.001, ** p < 0.01, * p < 0.05
EN

回答 2

Stack Overflow用户

发布于 2018-05-30 09:14:48

在@jaySF answer之后,创建您自己的提取函数,该函数封装了默认值,并注册它:

custom_extract_plm <- function(model, ...) {
  s <- summary(model)
  ex.1 <- texreg:::extract.plm(model, ...)

  fv.1 <- s$fstatistic$statistic
  pv.1 <- s$fstatistic$p.value

  ex.1@gof.names <- c(ex.1@gof.names, "F-stat", "P-value")
  ex.1@gof <- c(ex.1@gof, fv.1, pv.1)
  ex.1@gof.decimal <- c(ex.1@gof.decimal, TRUE, TRUE)

  ex.1
}

setMethod(texreg:::extract, signature = className("plm", "plm"), custom_extract_plm)

现在你得到一个F统计量:

> texreg::screenreg(list(POLS, RE, FE), custom.coef.map = list('married' = 'Marrtied', 'union' = 'Union'))

================================================
           Model 1      Model 2      Model 3    
------------------------------------------------
Marrtied      0.11 ***     0.06 ***     0.05 *  
             (0.02)       (0.02)       (0.02)   
Union         0.18 ***     0.11 ***     0.08 ***
             (0.02)       (0.02)       (0.02)   
------------------------------------------------
R^2           0.19         0.18         0.18    
Adj. R^2      0.19         0.18         0.06    
Num. obs.  4360         4360         4360       
F-stat       72.46        68.41        83.85    
P-value       0.00         0.00         0.00    
================================================
*** p < 0.001, ** p < 0.01, * p < 0.05
票数 3
EN

Stack Overflow用户

发布于 2018-05-24 20:27:50

以下是使用我的huxtable包中的huxreg的一种可能性。您还需要安装broom包。

library(huxtable)

ht <- huxreg(POLS, RE, FE, 
      coefs = c("Married" = "married", "Union" = "union"), 
      statistics = c("Obs. (N)" = "nobs", "Adj. R^2" = "adj.r.squared", 
        "F statistic" = "statistic", "P value" = "p.value"))

时间单位的数量不在broom::glance中,所以我们手动添加它-这里有一个简单的方法:

Ts <- purrr::map_int(list(POLS, RE, FE), list(pdim, "nT", "T"))
ns <- purrr::map_int(list(POLS, RE, FE), list(pdim, "nT", "n"))
ht <- insert_row(ht, c("Time (T)", Ts), after = 6)
ht <- insert_row(ht, c("Indiv. (n)", ns), after = 6)
ht

───────────────────────────────────────────────────────────────
                     (1)             (2)             (3)       
              ─────────────────────────────────────────────────
  Married          0.108 ***       0.064 ***       0.047 *     
                  (0.016)         (0.017)         (0.018)      
  Union            0.182 ***       0.106 ***       0.080 ***   
                  (0.017)         (0.018)         (0.019)      
              ─────────────────────────────────────────────────
  Obs. (N)      4360            4360            4360           
  Indiv. (n)     545             545             545           
  Time (T)         8               8               8           
  Adj. R^2         0.187           0.178           0.061       
  F statistic     72.459          68.412          83.851       
  P value          7.250e-186      5.813e-176      1.655e-156  
───────────────────────────────────────────────────────────────
  *** p < 0.001; ** p < 0.01; * p < 0.05. 

Column names: names, model1, model2, model3

这将在Rmarkdown文档中自动打印为TeX/HTML。您可以对其进行编辑,以添加行、列和进一步的格式。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50507650

复制
相关文章

相似问题

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