zeroinfl report in irr and or: trouble with stargazer

huangapple go评论68阅读模式
英文:

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(&#39;stargazer&#39;)
library(&#39;pscl&#39;)
library(&#39;boot&#39;)

zinb &lt;- read.csv(&quot;https://stats.idre.ucla.edu/stat/data/fish.csv&quot;)
zinb &lt;- within(zinb, {
  nofish &lt;- factor(nofish)
  livebait &lt;- factor(livebait)
  camper &lt;- factor(camper)
})


m1 &lt;- zeroinfl(count ~ child + camper | persons, data = zinb)
m2 &lt;- zeroinfl(count ~ child + camper + livebait | persons, data = zinb)
m3 &lt;- 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 = &quot;zero inflated poisson&quot;,
          align = TRUE, type = &quot;text&quot;,
          column.labels = c(&quot;model1&quot;, &quot;model2&quot;, &quot;model3&quot;),
          star.cutoffs = c(0.05, 0.01, 0.001)
          
)


#stargazer for output
stargazer(m1, m2, m3,
          title = &quot;zero inflated poisson&quot;,
          align = TRUE, type = &quot;text&quot;,
          column.labels = c(&quot;model1&quot;, &quot;model2&quot;, &quot;model3&quot;),
          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 &lt;- lapply(list(m1, m2, m3), function(model) {
  exp(coef(model))
})


#stargazer for output
stargazer(m1, m2, m3,
          title = &quot;zero inflated poisson&quot;,
          align = TRUE, type = &quot;text&quot;,
          column.labels = c(&quot;model1&quot;, &quot;model2&quot;, &quot;model3&quot;),
          star.cutoffs = c(0.05, 0.01, 0.001),
          coef = lapply(irrs, function(x) paste(round(x, 2), &quot;IRR&quot;, sep = &quot; x &quot;))
)

% Error: Argument &#39;coef&#39; 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(&#39;pscl&#39;)
library(&#39;boot&#39;)
library(modelsummary)
zinb &lt;- read.csv(&quot;https://stats.idre.ucla.edu/stat/data/fish.csv&quot;)
zinb &lt;- within(zinb, {
  nofish &lt;- factor(nofish)
  livebait &lt;- factor(livebait)
  camper &lt;- factor(camper)
})


m1 &lt;- zeroinfl(count ~ child + camper | persons, data = zinb)
m2 &lt;- zeroinfl(count ~ child + camper + livebait | persons, data = zinb)
m3 &lt;- zeroinfl(count ~ child + camper + livebait + persons | persons, data = zinb)


modelsummary(models = list(model1= m1,model2 = m2,model3 =m3), exponentiate = TRUE,
             stars = TRUE, title = &quot;zero inflated poisson&quot;)

huangapple
  • 本文由 发表于 2023年5月25日 22:46:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76333576.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定