svyglm.zip() is an extension to the survey-package
to fit survey-weighted zero-inflated Poisson models. It uses
svymle to fit sampling-weighted
maximum likelihood estimates, based on starting values provided
by zeroinfl.
svyglm.zip(formula, design, ...)An object of class svymle and svyglm.zip,
with some additional information about the model.
Code modified from https://notstatschat.rbind.io/2015/05/26/zero-inflated-poisson-from-complex-samples/.
if (require("survey")) {
data(nhanes_sample)
set.seed(123)
nhanes_sample$malepartners <- rpois(nrow(nhanes_sample), 2)
nhanes_sample$malepartners[sample(1:2992, 400)] <- 0
# create survey design
des <- svydesign(
id = ~SDMVPSU,
strat = ~SDMVSTRA,
weights = ~WTINT2YR,
nest = TRUE,
data = nhanes_sample
)
# fit negative binomial regression
fit <- svyglm.zip(
malepartners ~ age + factor(RIDRETH1) | age + factor(RIDRETH1),
des
)
# print coefficients and standard errors
fit
}
#> term estimate std.error conf.low conf.high p.value
#> 2 age 0.0149 0.0354 0.9469 1.0879 0.6745
#> 3 factor(RIDRETH1)2 0.0185 0.0754 0.8787 1.1810 0.8062
#> 4 factor(RIDRETH1)3 -0.0449 0.0284 0.9043 1.0107 0.1133
#> 5 factor(RIDRETH1)4 -0.0240 0.0276 0.9250 1.0305 0.3843
#> 6 factor(RIDRETH1)5 0.0371 0.0617 0.9197 1.1712 0.5470
#> 7 tp.(Intercept) -1.6694 0.4717 0.0747 0.4748 <0.001 ***
#> 8 tp.age -0.0333 0.2831 0.5553 1.6848 0.9064
#> 9 tp.factor(RIDRETH1)2 0.1548 0.2571 0.7053 1.9323 0.5472
#> 10 tp.factor(RIDRETH1)3 -0.3969 0.2111 0.4446 1.0169 0.0601 .
#> 11 tp.factor(RIDRETH1)4 -0.2330 0.3050 0.4357 1.4402 0.4450
#> 12 tp.factor(RIDRETH1)5 -0.3303 0.4744 0.2836 1.8214 0.4863
#>
#> Showing robust standard errors on link-scale (untransformed).