Skip to contents

The design-weighted GLM with the linearisation (sandwich) variance of survey::svyglm() (Binder 1983; Lumley 2004), computed natively for weights, strata, clusters and a finite-population correction. Rows with a missing model variable leave the fit but stay in the design with a zero score, as in survey. Family accepts the same strings as the Python module ("gaussian", "binomial", "poisson", "gamma", "negativebinomial") or any R family object; binomial and Poisson fits use the quasi family (same estimates, no non-integer warning).

Usage

morie_survey_glm(
  design,
  formula,
  family = c("gaussian", "binomial", "poisson", "gamma", "negativebinomial")
)

Arguments

design

A design from morie_survey_design(). A survey::svydesign object is accepted too and read into the same native form (one-stage designs).

formula

A formula (e.g. y ~ x1 + x2) for survey-weighted regression / GLM.

family

A family object (e.g. stats::binomial()) passed to the survey-weighted GLM.

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).

References

Binder, D. A. (1983). On the variances of asymptotically normal estimators from complex surveys. International Statistical Review 51, 279-292.

Lumley, T. (2004). Analysis of complex survey samples. Journal of Statistical Software 9(1), 1-19.

Examples

set.seed(1)
df <- data.frame(y = rnorm(40), x = rnorm(40), w = runif(40, 0.5, 2),
                 s = rep(c("a", "b"), 20), psu = rep(1:10, each = 4))
d <- morie_survey_design(df, "w", strata_col = "s", cluster_col = "psu", nest = TRUE)
morie_survey_glm(d, y ~ x)$coefficients
#>              Estimate Std. Error   t value  Pr(>|t|)
#> (Intercept) 0.1095511  0.1374531 0.7970074 0.4364374
#> x           0.1233802  0.1244213 0.9916324 0.3352824