Last active
April 8, 2021 19:23
-
-
Save bschneidr/d7cb07654f56a795af9b9f0f0cd95e91 to your computer and use it in GitHub Desktop.
Fitting multinomial and generalized ordered logistic models with `survey` and `svyVGAM`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(survey) | |
library(svyVGAM) | |
data(api) | |
# Prepare data with binary, categorical, and ordered outcomes ---- | |
apiclus2 <- transform(apiclus2, mealcat = cut(meals,c(0,25,50,75,100))) | |
apiclus2 <- transform(apiclus2, mealcat_ordered = as.ordered(cut(meals,c(0,25,50,75,100)))) | |
apiclus2 <- transform(apiclus2, mealcat_high = as.ordered(cut(meals, c(0,50,100)))) | |
# Set up the survey design object ---- | |
dclus2 <- svydesign(id = ~dnum+snum, fpc = ~fpc1+fpc2, data = apiclus2) | |
# Fit a binary logistic model ---- | |
bin_model <- svyglm(formula = mealcat_high ~ avg.ed + mobility + stype, | |
family = quasibinomial(), | |
design = dclus2) | |
# Fit a multinomial model ---- | |
mn_model <- svy_vglm(formula = mealcat~avg.ed+mobility+stype, | |
family = multinomial(refLevel = 1), | |
design = dclus2) | |
# Fit a generalized ordered logistic model ---- | |
geologit_model <- svy_vglm(formula = mealcat_ordered ~ avg.ed + mobility + stype, | |
family = cumulative(link = "logitlink", parallel = FALSE), | |
design = dclus2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment