gpt4 book ai didi

R Stargazer 与 pglm 模型 - 在 plm 模型中转换二项式 pglm 模型

转载 作者:行者123 更新时间:2023-12-03 23:06:17 40 4
gpt4 key购买 nike

我正在使用 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 模型的结果的解决方案,因为以下 stargazer 调用不适用于 pglm 模型。

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

除了提取每个摘要项并分别对其进行格式化之外,还有什么替代方法吗?结果的类别是:

[1] "maxLik" "maxim" "list"

最佳答案

这是一个简单的提取函数,可以让 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)
}

为了让这段代码正常工作,你还应该注册函数,以便在调用 extract 时默认处理 pglm maxLik 对象:

setMethod("extract", signature = className("maxLik", "maxLik"), 
definition = extract.pglm)

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

关于R Stargazer 与 pglm 模型 - 在 plm 模型中转换二项式 pglm 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42161129/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com