Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bschneidr/088948f83812aea0ec03d8af711a650d to your computer and use it in GitHub Desktop.
Save bschneidr/088948f83812aea0ec03d8af711a650d to your computer and use it in GitHub Desktop.
library(survey)
library(svyVGAM)
# Load some example data
data(nhanes_sxq)
# Save it to a file so it can also be used by Stata
haven::write_dta(data = nhanes_sxq,
path = "nhanes_sxq.dta")
# Set up survey design object
svy_design <- svydesign(data = nhanes_sxq,
id = ~SDMVPSU,
strat = ~SDMVSTRA, nest = TRUE,
weights = ~WTINT2YR)
# Fit the model and display a summary
model_fit <- svy_vglm(malepartners ~ RIDAGEYR + DMDEDUC,
family = zinegbinomial(),
design = svy_design, crit = "coef")
summary(model_fit)
confint(model_fit)
use "C:\Users\benja\OneDrive\Documents\Academics\JPSM\2021 - Spring\SURV701 - Analysis of Complex Sample Data\Interactive-Checks\nhanes_sxq.dta"
svyset SDMVPSU [pw = WTINT2YR], strata(SDMVSTRA)
svy: zinb malepartners RIDAGEYR DMDEDUC, inflate(RIDAGEYR DMDEDUC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment