英文:
zeroinfl report in irr and or: trouble with stargazer
问题
我遇到了一些报告零膨胀泊松回归系列结果的困难。我尝试使用stargazer输出结果。我从UCLA的虚拟数据开始,以及一些虚拟回归:
# 这个例子直接来自http://statistics.ats.ucla.edu/stat/r/dae/zipoisson.html
library('stargazer')
library('pscl')
library('boot')
zinb <- read.csv("https://stats.idre.ucla.edu/stat/data/fish.csv")
zinb <- within(zinb, {
nofish <- factor(nofish)
livebait <- factor(livebait)
camper <- factor(camper)
})
m1 <- zeroinfl(count ~ child + camper | persons, data = zinb)
m2 <- zeroinfl(count ~ child + camper + livebait | persons, data = zinb)
m3 <- zeroinfl(count ~ child + camper + livebait + persons | persons, data = zinb)
我的问题有两个。首先,我通常使用stargazer包来输出结果,因为我熟悉它。但是,它会将输出拆分为零组件/逻辑回归输出和泊松输出。有没有办法将它们合并到一个输出中?
#stargazer for output
stargazer(m1, m2, m3,
title = "zero inflated poisson",
align = TRUE, type = "text",
column.labels = c("model1", "model2", "model3"),
star.cutoffs = c(0.05, 0.01, 0.001)
)
#stargazer for output
stargazer(m1, m2, m3,
title = "zero inflated poisson",
align = TRUE, type = "text",
column.labels = c("model1", "model2", "model3"),
star.cutoffs = c(0.05, 0.01, 0.001),
zero.component = TRUE
)
其次,我真的想以IRR报告非零组件的结果,并以OR报告零组件的结果。我无法弄清楚如何在stargazer中实现这一点。我尝试了以下方法,但无法使其正常工作:
irrs <- lapply(list(m1, m2, m3), function(model) {
exp(coef(model))
})
#stargazer for output
stargazer(m1, m2, m3,
title = "zero inflated poisson",
align = TRUE, type = "text",
column.labels = c("model1", "model2", "model3"),
star.cutoffs = c(0.05, 0.01, 0.001),
coef = lapply(irrs, function(x) paste(round(x, 2), "IRR", sep = " x "))
)
英文:
I am having some trouble reporting results from a series of zero inflated poisson regressions. I am trying to use stargazer to output the results. I'm starting with the dummy data from UCLA, and some dummy regressions:
# This example comes directly from http://statistics.ats.ucla.edu/stat/r/dae/zipoisson.html
library('stargazer')
library('pscl')
library('boot')
zinb <- read.csv("https://stats.idre.ucla.edu/stat/data/fish.csv")
zinb <- within(zinb, {
nofish <- factor(nofish)
livebait <- factor(livebait)
camper <- factor(camper)
})
m1 <- zeroinfl(count ~ child + camper | persons, data = zinb)
m2 <- zeroinfl(count ~ child + camper + livebait | persons, data = zinb)
m3 <- zeroinfl(count ~ child + camper + livebait + persons | persons, data = zinb)
My problem is twofold. First, I generally use the stargazer package for output because I'm familiar with it. However, it splits the output into the zero component/logistic regression output and the poisson output. Is there a way to combine these in one output?
#stargazer for output
stargazer(m1, m2, m3,
title = "zero inflated poisson",
align = TRUE, type = "text",
column.labels = c("model1", "model2", "model3"),
star.cutoffs = c(0.05, 0.01, 0.001)
)
#stargazer for output
stargazer(m1, m2, m3,
title = "zero inflated poisson",
align = TRUE, type = "text",
column.labels = c("model1", "model2", "model3"),
star.cutoffs = c(0.05, 0.01, 0.001),
zero.component = TRUE
)
Second, I would really like to report the results for the non-zero component in IRR and the zero component in OR. I cannot figure out how to do this in stargazer. I tried the following, but can't get it work:
irrs <- lapply(list(m1, m2, m3), function(model) {
exp(coef(model))
})
#stargazer for output
stargazer(m1, m2, m3,
title = "zero inflated poisson",
align = TRUE, type = "text",
column.labels = c("model1", "model2", "model3"),
star.cutoffs = c(0.05, 0.01, 0.001),
coef = lapply(irrs, function(x) paste(round(x, 2), "IRR", sep = " x "))
)
% Error: Argument 'coef' must be NULL (default), or a list of numeric vectors.
答案1
得分: 1
尝试使用modelsummary
这个解决方案
library('pscl')
library('boot')
library(modelsummary)
zinb <- read.csv("https://stats.idre.ucla.edu/stat/data/fish.csv")
zinb <- within(zinb, {
nofish <- factor(nofish)
livebait <- factor(livebait)
camper <- factor(camper)
})
m1 <- zeroinfl(count ~ child + camper | persons, data = zinb)
m2 <- zeroinfl(count ~ child + camper + livebait | persons, data = zinb)
m3 <- zeroinfl(count ~ child + camper + livebait + persons | persons, data = zinb)
modelsummary(models = list(model1= m1,model2 = m2,model3 =m3), exponentiate = TRUE,
stars = TRUE, title = "zero inflated poisson")
英文:
try this solution with modelsummary
library('pscl')
library('boot')
library(modelsummary)
zinb <- read.csv("https://stats.idre.ucla.edu/stat/data/fish.csv")
zinb <- within(zinb, {
nofish <- factor(nofish)
livebait <- factor(livebait)
camper <- factor(camper)
})
m1 <- zeroinfl(count ~ child + camper | persons, data = zinb)
m2 <- zeroinfl(count ~ child + camper + livebait | persons, data = zinb)
m3 <- zeroinfl(count ~ child + camper + livebait + persons | persons, data = zinb)
modelsummary(models = list(model1= m1,model2 = m2,model3 =m3), exponentiate = TRUE,
stars = TRUE, title = "zero inflated poisson")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论