Builds the design with morie_survey_design() and fits morie_survey_glm():
cluster-robust, stratified design-based standard errors.
Usage
morie_survey_complex_glm(
df,
formula,
weight_col,
family = "gaussian",
cluster_col = NULL,
strata_col = NULL,
nest = FALSE
)Arguments
- df
A
data.frameholding the (unit-level) sample data plus any weight/strata/cluster/domain columns referenced by name.- formula
A
formula(e.g.y ~ x1 + x2) for survey-weighted regression / GLM.- weight_col
Character; column name of the design weight variable in
df.- family
A
familyobject (e.g.stats::binomial()) passed to the survey-weighted GLM.- cluster_col
Character; column name of the cluster identifier in
df.- strata_col
Character; column name of the stratum identifier in
df.- nest
If TRUE, cluster IDs are only unique within a stratum (see
morie_survey_design()).
Value
A list: coefficients (a matrix of estimates, design-based standard errors,
t values and p-values on the design degrees of freedom: PSUs minus strata minus the
coefficients beyond the intercept), confint, vcov (the sandwich
\(A^{-1} B A^{-1}\) with \(B\) the Taylor-linearisation variance of the score totals)
and fit (the weighted glm giving the estimates).
Examples
set.seed(1)
df <- data.frame(y = rnorm(40), x = rnorm(40), w = runif(40, 0.5, 2))
str(morie_survey_complex_glm(df, y ~ x, "w"), max.level = 1)
#> List of 4
#> $ coefficients: num [1:2, 1:4] 0.11 0.123 0.135 0.14 0.813 ...
#> ..- attr(*, "dimnames")=List of 2
#> $ confint : num [1:2, 1:2] -0.163 -0.16 0.382 0.407
#> ..- attr(*, "dimnames")=List of 2
#> $ vcov : num [1:2, 1:2] 0.018142 0.000503 0.000503 0.019629
#> $ fit :List of 30
#> ..- attr(*, "class")= chr [1:2] "glm" "lm"
