我正在使用stargazer
来创建我的plm汇总表。
library(plm)
library(pglm)
data("Unions", package = "pglm")
anb1 <- plm(wage ~ union + exper + rural, Unions, model = "random", method = "bfgs")
stargazer(anb1)
不幸的是,stargazer不支持pglm模型。我正在寻找一个关于如何使用二进制因变量绘制pglm模型结果的解决方案,因为以下的观星者调用不适用于pglm模型。
anb2 <- pglm(union ~ wage + exper + rural, Unions, family = "binomial",
model = "random", method = "bfgs")
stargazer(anb2)
除了提取每个摘要项目而不是分别格式化之外的任何替代方法? 结果的类别是:
[1]&#34; maxLik&#34; &#34;格言&#34; &#34;列表&#34;
答案 0 :(得分:1)
一种可能的解决方案是执行以下操作。
anb2 <- pglm(union ~ wage + exper + rural, Unions, family = "binomial",
model = "random", method = "bfgs")
model = summary(anb2)
加载或安装以下库
library(dplyr)
library(xtable)
library('gtools')
创建一个名为co-variates
的向量var = c('Intercept', 'wage', 'exper', 'ruralyes', 'sigma')
然后做
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 ***
然后您可以在data.frame
上使用xtable
library(xtable)
xtable(model_summary)
答案 1 :(得分:1)
另一种可能的(但并非完全令人满意的)解决方案。
library(plm)
library(pglm)
library(stargazer)
data("Unions", package = "pglm")
anb2 <- pglm(union ~ wage + exper + rural, Unions, family = "binomial",
model = "random", method = "bfgs")
# A "fake" model
anb0 <- plm(union ~ wage + exper + rural, Unions, family = "binomial",
model = "random", method = "bfgs")
tstats <- summary(anb2)$estimate[,3][-5]
pvs <- summary(anb2)$estimate[,4][-5]
SEs <- summary(anb2)$estimate[,2][-5]
coefs <- summary(anb2)$estimate[,1][-5]
stargazer(anb0, type="text", coef=list(coefs), se=list(SEs),
p = list(pvs), omit.stat="all")
以下是stargazer
:
====================================
Dependent variable:
---------------------------
union
------------------------------------
wage 0.122***
(0.024)
exper -0.058**
(0.023)
ruralyes 0.092
(0.249)
Constant -2.857***
(0.235)
====================================
====================================
Note: *p<0.1; **p<0.05; ***p<0.01
答案 2 :(得分:1)
这是一个简单的提取函数,可以让texreg与pglm一起使用:
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
对象:
setMethod("extract", signature = className("maxLik", "maxLik"),
definition = extract.pglm)
之后,您可以将texreg与pglm一起使用,就像使用plm或texreg支持的其他模型一样。
答案 3 :(得分:1)
Exam.find().or(subscriptions).then(docs => {
/*logic here*/
})
.catch(error => {
/*error logic here*/
})
(1.36.24)的新版本在GitHub上可用(很快在CRAN上提供),并添加了pglm类。
答案 4 :(得分:0)
这是一个简单得多的解决方案。截至2019年6月25日,Stargazer仍不支持pglm,但coeftest确实支持,只是通过coeftest将模型传递给stargazer。
(还要注意自@giamcomo以来pglm中数据对象名称的更改)
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")
这是输出
> 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
>