zeroinfl report in irr and or: trouble with stargazer

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

zeroinfl report in irr and or: trouble with stargazer

问题

我遇到了一些报告零膨胀泊松回归系列结果的困难。我尝试使用stargazer输出结果。我从UCLA的虚拟数据开始,以及一些虚拟回归:

  1. # 这个例子直接来自http://statistics.ats.ucla.edu/stat/r/dae/zipoisson.html
  2. library('stargazer')
  3. library('pscl')
  4. library('boot')
  5. zinb <- read.csv("https://stats.idre.ucla.edu/stat/data/fish.csv")
  6. zinb <- within(zinb, {
  7. nofish <- factor(nofish)
  8. livebait <- factor(livebait)
  9. camper <- factor(camper)
  10. })
  11. m1 <- zeroinfl(count ~ child + camper | persons, data = zinb)
  12. m2 <- zeroinfl(count ~ child + camper + livebait | persons, data = zinb)
  13. m3 <- zeroinfl(count ~ child + camper + livebait + persons | persons, data = zinb)

我的问题有两个。首先,我通常使用stargazer包来输出结果,因为我熟悉它。但是,它会将输出拆分为零组件/逻辑回归输出和泊松输出。有没有办法将它们合并到一个输出中?

  1. #stargazer for output
  2. stargazer(m1, m2, m3,
  3. title = "zero inflated poisson",
  4. align = TRUE, type = "text",
  5. column.labels = c("model1", "model2", "model3"),
  6. star.cutoffs = c(0.05, 0.01, 0.001)
  7. )
  1. #stargazer for output
  2. stargazer(m1, m2, m3,
  3. title = "zero inflated poisson",
  4. align = TRUE, type = "text",
  5. column.labels = c("model1", "model2", "model3"),
  6. star.cutoffs = c(0.05, 0.01, 0.001),
  7. zero.component = TRUE
  8. )

其次,我真的想以IRR报告非零组件的结果,并以OR报告零组件的结果。我无法弄清楚如何在stargazer中实现这一点。我尝试了以下方法,但无法使其正常工作:

  1. irrs <- lapply(list(m1, m2, m3), function(model) {
  2. exp(coef(model))
  3. })
  4. #stargazer for output
  5. stargazer(m1, m2, m3,
  6. title = "zero inflated poisson",
  7. align = TRUE, type = "text",
  8. column.labels = c("model1", "model2", "model3"),
  9. star.cutoffs = c(0.05, 0.01, 0.001),
  10. coef = lapply(irrs, function(x) paste(round(x, 2), "IRR", sep = " x "))
  11. )
英文:

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:

  1. # This example comes directly from http://statistics.ats.ucla.edu/stat/r/dae/zipoisson.html
  2. library(&#39;stargazer&#39;)
  3. library(&#39;pscl&#39;)
  4. library(&#39;boot&#39;)
  5. zinb &lt;- read.csv(&quot;https://stats.idre.ucla.edu/stat/data/fish.csv&quot;)
  6. zinb &lt;- within(zinb, {
  7. nofish &lt;- factor(nofish)
  8. livebait &lt;- factor(livebait)
  9. camper &lt;- factor(camper)
  10. })
  11. m1 &lt;- zeroinfl(count ~ child + camper | persons, data = zinb)
  12. m2 &lt;- zeroinfl(count ~ child + camper + livebait | persons, data = zinb)
  13. 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?

  1. #stargazer for output
  2. stargazer(m1, m2, m3,
  3. title = &quot;zero inflated poisson&quot;,
  4. align = TRUE, type = &quot;text&quot;,
  5. column.labels = c(&quot;model1&quot;, &quot;model2&quot;, &quot;model3&quot;),
  6. star.cutoffs = c(0.05, 0.01, 0.001)
  7. )
  8. #stargazer for output
  9. stargazer(m1, m2, m3,
  10. title = &quot;zero inflated poisson&quot;,
  11. align = TRUE, type = &quot;text&quot;,
  12. column.labels = c(&quot;model1&quot;, &quot;model2&quot;, &quot;model3&quot;),
  13. star.cutoffs = c(0.05, 0.01, 0.001),
  14. zero.component = TRUE
  15. )

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:

  1. irrs &lt;- lapply(list(m1, m2, m3), function(model) {
  2. exp(coef(model))
  3. })
  4. #stargazer for output
  5. stargazer(m1, m2, m3,
  6. title = &quot;zero inflated poisson&quot;,
  7. align = TRUE, type = &quot;text&quot;,
  8. column.labels = c(&quot;model1&quot;, &quot;model2&quot;, &quot;model3&quot;),
  9. star.cutoffs = c(0.05, 0.01, 0.001),
  10. coef = lapply(irrs, function(x) paste(round(x, 2), &quot;IRR&quot;, sep = &quot; x &quot;))
  11. )
  12. % Error: Argument &#39;coef&#39; must be NULL (default), or a list of numeric vectors.

答案1

得分: 1

尝试使用modelsummary这个解决方案

  1. library('pscl')
  2. library('boot')
  3. library(modelsummary)
  4. zinb <- read.csv("https://stats.idre.ucla.edu/stat/data/fish.csv")
  5. zinb <- within(zinb, {
  6. nofish <- factor(nofish)
  7. livebait <- factor(livebait)
  8. camper <- factor(camper)
  9. })
  10. m1 <- zeroinfl(count ~ child + camper | persons, data = zinb)
  11. m2 <- zeroinfl(count ~ child + camper + livebait | persons, data = zinb)
  12. m3 <- zeroinfl(count ~ child + camper + livebait + persons | persons, data = zinb)
  13. modelsummary(models = list(model1= m1,model2 = m2,model3 =m3), exponentiate = TRUE,
  14. stars = TRUE, title = "zero inflated poisson")
英文:

try this solution with modelsummary

  1. library(&#39;pscl&#39;)
  2. library(&#39;boot&#39;)
  3. library(modelsummary)
  4. zinb &lt;- read.csv(&quot;https://stats.idre.ucla.edu/stat/data/fish.csv&quot;)
  5. zinb &lt;- within(zinb, {
  6. nofish &lt;- factor(nofish)
  7. livebait &lt;- factor(livebait)
  8. camper &lt;- factor(camper)
  9. })
  10. m1 &lt;- zeroinfl(count ~ child + camper | persons, data = zinb)
  11. m2 &lt;- zeroinfl(count ~ child + camper + livebait | persons, data = zinb)
  12. m3 &lt;- zeroinfl(count ~ child + camper + livebait + persons | persons, data = zinb)
  13. modelsummary(models = list(model1= m1,model2 = m2,model3 =m3), exponentiate = TRUE,
  14. 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:

确定