Wrapper for svyglm
. Fit a generalised linear model to
data from a complex survey design, with inverse-probability weighting and
design-based standard errors.
svyglmuni(design, dependent, explanatory, ...)
Survey design.
Character vector of length 1: name of depdendent variable (must have 2 levels).
Character vector of any length: name(s) of explanatory variables.
Other arguments to be passed to svyglm
.
A list of univariable fitted model outputs. Output is of class
svyglmlist
.
Other finalfit model wrappers:
coxphmulti()
,
coxphuni()
,
crrmulti()
,
crruni()
,
glmmixed()
,
glmmulti_boot()
,
glmmulti()
,
glmuni()
,
lmmixed()
,
lmmulti()
,
lmuni()
,
svyglmmulti()
# Examples taken from survey::svyglm() help page.
library(survey)
library(dplyr)
data(api)
dependent = "api00"
explanatory = c("ell", "meals", "mobility")
library(survey)
library(dplyr)
data(api)
apistrat = apistrat %>%
mutate(
api00 = ff_label(api00, "API in 2000 (api00)"),
ell = ff_label(ell, "English language learners (percent)(ell)"),
meals = ff_label(meals, "Meals eligible (percent)(meals)"),
mobility = ff_label(mobility, "First year at the school (percent)(mobility)"),
sch.wide = ff_label(sch.wide, "School-wide target met (sch.wide)")
)
# Linear example
dependent = "api00"
explanatory = c("ell", "meals", "mobility")
# Stratified design
dstrat = svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
# Univariable fit
fit_uni = dstrat %>%
svyglmuni(dependent, explanatory) %>%
fit2df(estimate_suffix = " (univariable)")
# Multivariable fit
fit_multi = dstrat %>%
svyglmmulti(dependent, explanatory) %>%
fit2df(estimate_suffix = " (multivariable)")
# Pipe together
apistrat %>%
summary_factorlist(dependent, explanatory, fit_id = TRUE) %>%
ff_merge(fit_uni) %>%
ff_merge(fit_multi) %>%
select(-fit_id, -index) %>%
dependent_label(apistrat, dependent)
#> Dependent: API in 2000 (api00) unit
#> 1 English language learners (percent)(ell) [0.0,84.0] Mean (sd)
#> 2 Meals eligible (percent)(meals) [0.0,100.0] Mean (sd)
#> 3 First year at the school (percent)(mobility) [1.0,99.0] Mean (sd)
#> value Coefficient (univariable) Coefficient (multivariable)
#> 1 652.8 (121.0) -3.73 (-4.36--3.10, p<0.001) -0.48 (-1.25-0.29, p=0.222)
#> 2 652.8 (121.0) -3.38 (-3.71--3.05, p<0.001) -3.14 (-3.70--2.58, p<0.001)
#> 3 652.8 (121.0) -1.43 (-3.31-0.46, p=0.137) 0.23 (-0.55-1.00, p=0.567)
# Binomial example
## Note model family needs specified and exponentiation if desired
dependent = "sch.wide"
explanatory = c("ell", "meals", "mobility")
# Univariable fit
fit_uni = dstrat %>%
svyglmuni(dependent, explanatory, family = "quasibinomial") %>%
fit2df(exp = TRUE, estimate_name = "OR", estimate_suffix = " (univariable)")
# Multivariable fit
fit_multi = dstrat %>%
svyglmmulti(dependent, explanatory, family = "quasibinomial") %>%
fit2df(exp = TRUE, estimate_name = "OR", estimate_suffix = " (multivariable)")
# Pipe together
apistrat %>%
summary_factorlist(dependent, explanatory, fit_id = TRUE) %>%
ff_merge(fit_uni) %>%
ff_merge(fit_multi) %>%
select(-fit_id, -index) %>%
dependent_label(apistrat, dependent)
#> Dependent: School-wide target met (sch.wide) No
#> 1 English language learners (percent)(ell) Mean (SD) 22.5 (19.3)
#> 2 Meals eligible (percent)(meals) Mean (SD) 46.0 (29.1)
#> 3 First year at the school (percent)(mobility) Mean (SD) 13.9 (8.6)
#> Yes OR (univariable) OR (multivariable)
#> 1 20.5 (20.0) 1.00 (0.98-1.01, p=0.715) 1.00 (0.97-1.02, p=0.851)
#> 2 44.7 (29.0) 1.00 (0.99-1.01, p=0.968) 1.00 (0.98-1.02, p=0.732)
#> 3 17.2 (13.0) 1.06 (1.00-1.12, p=0.049) 1.06 (1.00-1.13, p=0.058)