Skip to contents

A one-stage design: sampling weights, optional strata, optional primary sampling units (clusters) and an optional finite-population correction. Everything here is native; the variance of the estimators built on it is the Taylor linearisation of survey::svyrecvar.

Usage

morie_survey_design(
  data,
  weights_col,
  strata_col = NULL,
  cluster_col = NULL,
  fpc_col = NULL,
  nest = FALSE
)

Arguments

data

data.frame.

weights_col

Column name of the sampling weights (inverse inclusion probabilities).

strata_col

Optional strata column.

cluster_col

Optional PSU/cluster column.

fpc_col

Optional finite-population-correction column: the population size of the stratum (number of PSUs when clustered), or the sampling fraction when every value is <= 1.

nest

If TRUE, cluster IDs are only unique within a stratum; if FALSE (the default) a cluster ID that appears in two strata is an error, as in survey::svydesign.

Value

An object of class "morie_survey_design": a list with the data, the weights, and per-row stratum, PSU, PSU count of the stratum and population size.

Examples

set.seed(1)
df <- data.frame(y = 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)
class(d)
#> [1] "morie_survey_design"          "morie_survey_design_fallback"
morie_survey_mean(d, "y")
#> $mean
#> [1] 0.07347258
#> 
#> $se
#> [1] 0.1481628
#>