We use the pscl package in to run the zero-inflated Poisson model.
library(pscl)
## Loading required package: MASS
## Loading required package: mvtnorm
## Loading required package: coda
## Loading required package: lattice
## Loading required package: gam
## Loading required package: splines
## Loaded gam 1.06.2
## Loading required package: vcd
## Loading required package: grid
## Loading required package: colorspace
## Classes and Methods for R developed in the
## Political Science Computational Laboratory
## Department of Political Science
## Stanford University
## Simon Jackman
## hurdle and zeroinfl functions by Achim Zeileis
options(width = 55)
data("bioChemists", package = "pscl")
summary(bioChemists)
## art fem mar
## Min. : 0.00 Men :494 Single :309
## 1st Qu.: 0.00 Women:421 Married:606
## Median : 1.00
## Mean : 1.69
## 3rd Qu.: 2.00
## Max. :19.00
## kid5 phd ment
## Min. :0.000 Min. :0.755 Min. : 0.00
## 1st Qu.:0.000 1st Qu.:2.260 1st Qu.: 3.00
## Median :0.000 Median :3.150 Median : 6.00
## Mean :0.495 Mean :3.103 Mean : 8.77
## 3rd Qu.:1.000 3rd Qu.:3.920 3rd Qu.:12.00
## Max. :3.000 Max. :4.620 Max. :77.00
## inflation with regressors
fm.zip2 <- zeroinfl(art ~ fem + mar + kid5 + phd + ment | fem + mar + kid5 +
phd + ment, data = bioChemists)
summary(fm.zip2)
##
## Call:
## zeroinfl(formula = art ~ fem + mar + kid5 + phd +
## ment | fem + mar + kid5 + phd + ment, data = bioChemists)
##
## Pearson residuals:
## Min 1Q Median 3Q Max
## -2.325 -0.865 -0.283 0.540 7.298
##
## Count model coefficients (poisson with log link):
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.64084 0.12131 5.28 1.3e-07 ***
## femWomen -0.20914 0.06340 -3.30 0.00097 ***
## marMarried 0.10375 0.07111 1.46 0.14456
## kid5 -0.14332 0.04743 -3.02 0.00251 **
## phd -0.00617 0.03101 -0.20 0.84238
## ment 0.01810 0.00229 7.89 3.1e-15 ***
##
## Zero-inflation model coefficients (binomial with logit link):
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.57706 0.50939 -1.13 0.257
## femWomen 0.10975 0.28008 0.39 0.695
## marMarried -0.35401 0.31761 -1.11 0.265
## kid5 0.21710 0.19648 1.10 0.269
## phd 0.00127 0.14526 0.01 0.993
## ment -0.13411 0.04524 -2.96 0.003 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Number of iterations in BFGS optimization: 21
## Log-likelihood: -1.6e+03 on 12 Df
# Odds ratios with 95% CI for zero
exp(cbind(coefficients(fm.zip2), confint(fm.zip2)))[8:12, ]
## 2.5 % 97.5 %
## zero_femWomen 1.1160 0.6445 1.9323
## zero_marMarried 0.7019 0.3766 1.3080
## zero_kid5 1.2425 0.8454 1.8261
## zero_phd 1.0013 0.7532 1.3311
## zero_ment 0.8745 0.8003 0.9556
# Effect with 95% CI for count
exp(cbind(coefficients(fm.zip2), confint(fm.zip2)))[2:6, ]
## 2.5 % 97.5 %
## count_femWomen 0.8113 0.7165 0.9186
## count_marMarried 1.1093 0.9650 1.2752
## count_kid5 0.8665 0.7896 0.9509
## count_phd 0.9939 0.9353 1.0561
## count_ment 1.0183 1.0137 1.0229
fm.zip3 <- zeroinfl(art ~ fem + mar + kid5 + phd + ment | fem + ment, data = bioChemists)
summary(fm.zip3)
##
## Call:
## zeroinfl(formula = art ~ fem + mar + kid5 + phd +
## ment | fem + ment, data = bioChemists)
##
## Pearson residuals:
## Min 1Q Median 3Q Max
## -2.341 -0.871 -0.270 0.547 7.159
##
## Count model coefficients (poisson with log link):
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.62786 0.11338 5.54 3.1e-08 ***
## femWomen -0.20871 0.06312 -3.31 0.00094 ***
## marMarried 0.13321 0.06619 2.01 0.04416 *
## kid5 -0.16355 0.04337 -3.77 0.00016 ***
## phd -0.00688 0.02855 -0.24 0.80944
## ment 0.01830 0.00226 8.09 5.8e-16 ***
##
## Zero-inflation model coefficients (binomial with logit link):
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.7264 0.2303 -3.15 0.0016 **
## femWomen 0.1131 0.2682 0.42 0.6734
## ment -0.1321 0.0409 -3.23 0.0012 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Number of iterations in BFGS optimization: 17
## Log-likelihood: -1.61e+03 on 9 Df
exp(cbind(coefficients(fm.zip3), confint(fm.zip3)))
## 2.5 % 97.5 %
## count_(Intercept) 1.8736 1.5003 2.3398
## count_femWomen 0.8116 0.7172 0.9185
## count_marMarried 1.1425 1.0035 1.3007
## count_kid5 0.8491 0.7799 0.9245
## count_phd 0.9931 0.9391 1.0503
## count_ment 1.0185 1.0140 1.0230
## zero_(Intercept) 0.4836 0.3080 0.7595
## zero_femWomen 1.1197 0.6619 1.8942
## zero_ment 0.8763 0.8088 0.9494