svyglm.zip | R Documentation |
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, ...)
formula |
An object of class |
design |
An object of class |
... |
Other arguments passed down to |
Code modified from https://notstatschat.rbind.io/2015/05/26/zero-inflated-poisson-from-complex-samples/.
An object of class svymle
and svyglm.zip
,
with some additional information about the model.
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
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.