library(haven) # import Stata data and labels
library(dplyr) # data manipulation
library(pscl) # zero-inflated models: zeroinfl()
gss <- read_dta("https://tdmize.github.io/data/data/cda_gss.dta")
gss <- gss |> filter(year >= 2002 & year <= 2014)
# Data management: Christian (Protestant, Catholic, Christian) vs not religious
gss <- gss |>
mutate(notrelig = case_when(relig %in% c(1, 2, 11) ~ 0, relig == 4 ~ 1))
# Keep model variables; drop any missing data
gss <- gss[c("mntlhlth", "physhlth", "woman", "race3", "year", "college", "parent",
"faminc", "metro", "notrelig", "married", "age")]
gss <- gss[complete.cases(gss), ]
# Treat binary/nominal variables as factors
gss <- gss |>
mutate(across(c(woman, married, race3, college, parent), as_factor),
notrelig = factor(notrelig, labels = c("Christian", "Not Religious")),
year = factor(year))
# Zero-inflated negative binomial model
mhmod <- zeroinfl(mntlhlth ~ woman + married + poly(age, 2) + poly(faminc, 2) +
race3 + college + parent + notrelig + year |
woman + married + poly(age, 2) + faminc + race3 + college + parent + notrelig + year,
data = gss, dist = "negbin")
summary(mhmod)
Call:
zeroinfl(formula = mntlhlth ~ woman + married + poly(age, 2) + poly(faminc, 2) + race3 +
college + parent + notrelig + year | woman + married + poly(age, 2) + faminc + race3 +
college + parent + notrelig + year, data = gss, dist = "negbin")
Pearson residuals:
Min 1Q Median 3Q Max
-0.70893 -0.49775 -0.39685 -0.01617 7.38423
Count model coefficients (negbin with log link):
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.24222 0.08619 26.016 < 2e-16 ***
womanWomen -0.08650 0.05558 -1.556 0.119660
marriedMarried -0.10595 0.06001 -1.765 0.077495 .
poly(age, 2)1 0.08715 2.23512 0.039 0.968899
poly(age, 2)2 5.28061 2.18499 2.417 0.015659 *
poly(faminc, 2)1 -8.91421 2.32953 -3.827 0.000130 ***
poly(faminc, 2)2 5.74210 2.01414 2.851 0.004360 **
race3black -0.03601 0.08215 -0.438 0.661114
race3other 0.02573 0.10045 0.256 0.797857
collegeCollege Degree -0.40765 0.06283 -6.488 8.68e-11 ***
parentParent 0.06026 0.06528 0.923 0.355973
notreligNot Religious 0.03178 0.06561 0.484 0.628162
year2006 -0.25107 0.07082 -3.545 0.000392 ***
year2010 -0.17478 0.07442 -2.349 0.018847 *
year2014 -0.09226 0.07668 -1.203 0.228885
Log(theta) -0.28587 0.06105 -4.682 2.84e-06 ***
Zero-inflation model coefficients (binomial with logit link):
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.252691 0.113770 2.221 0.02635 *
womanWomen -0.756337 0.075160 -10.063 < 2e-16 ***
marriedMarried 0.340096 0.082019 4.147 3.38e-05 ***
poly(age, 2)1 20.254751 2.842793 7.125 1.04e-12 ***
poly(age, 2)2 12.050151 2.750861 4.381 1.18e-05 ***
faminc 0.003870 0.001257 3.078 0.00208 **
race3black 0.680270 0.105183 6.468 9.96e-11 ***
race3other 0.266097 0.133441 1.994 0.04614 *
collegeCollege Degree -0.293784 0.090152 -3.259 0.00112 **
parentParent -0.169210 0.090598 -1.868 0.06181 .
notreligNot Religious -0.306703 0.094124 -3.259 0.00112 **
year2006 0.118076 0.094720 1.247 0.21255
year2010 -0.223418 0.107494 -2.078 0.03767 *
year2014 0.193785 0.101043 1.918 0.05513 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Theta = 0.7514
Number of iterations in BFGS optimization: 43
Log-likelihood: -9441 on 30 Df
# Exponentiated count model coefficients (IRRs)
round(exp(coef(mhmod, model = "count")), 3) (Intercept) womanWomen marriedMarried poly(age, 2)1
9.414 0.917 0.899 1.091
poly(age, 2)2 poly(faminc, 2)1 poly(faminc, 2)2 race3black
196.489 0.000 311.719 0.965
race3other collegeCollege Degree parentParent notreligNot Religious
1.026 0.665 1.062 1.032
year2006 year2010 year2014
0.778 0.840 0.912