Skip to contents

These are the svyplan generics re-exported by samplyr. Samplyr adds tbl_sample methods rather than defining competing generics.

Usage

design_effect(x = NULL, ...)

effective_n(x = NULL, ...)

# S3 method for class 'tbl_sample'
design_effect(x, ...)

# S3 method for class 'tbl_sample'
effective_n(x, ...)

Arguments

x

A tbl_sample, or a numeric weight vector passed to the svyplan method.

...

Passed to the svyplan method: the planning arguments icc, n_per_psu, n_per_ssu and var_ratio are the useful ones here. Every argument must be named. svyplan reports any name it does not recognize.

Value

design_effect() returns a numeric svyplan_deff object. Use as.double() for the value. effective_n() returns a numeric scalar.

Details

The tbl_sample methods report the weighting loss: how much precision the realized weights cost relative to a self-weighting sample of the same size. This is Kish's design effect, \(n \sum w_i^2 / (\sum w_i)^2\), computed from the .weight column, so it equals 1 for a self-weighting design and rises with weight variability. It is outcome-independent, which is what makes it available from the sample alone.

It is one component of a full design effect and not a substitute for one. Clustering and stratification also move precision, and neither is visible in the weights. To estimate a design effect that reflects them, fit the design and ask the estimator: as_svydesign() then survey::svymean(deff = TRUE), which is outcome-specific by necessity. To anticipate the clustering component before collecting data, name the planning arguments in the same call: design_effect(x, icc = , n_per_psu = ) forwards them to svyplan::design_effect() and returns the weighting loss multiplied by the anticipated clustering component. Positional arguments are refused, since these methods take no outcome variable.

Examples

set.seed(1207)
frame <- data.frame(
  id = 1:200,
  stratum = rep(c("A", "B"), each = 100),
  income = c(rnorm(100, 50, 10), rnorm(100, 80, 15))
)

# A disproportionate allocation costs precision through its weights
samp <- sampling_design() |>
  stratify_by(stratum) |>
  draw(n = c(A = 10, B = 40)) |>
  execute(frame, seed = 1213)

design_effect(samp)
#> Planning design effect: 1.5625
effective_n(samp)
#> [1] 32

# A proportional allocation is self-weighting, so the loss is 1
prop_samp <- sampling_design() |>
  stratify_by(stratum) |>
  draw(n = c(A = 25, B = 25)) |>
  execute(frame, seed = 1213)

design_effect(prop_samp)
#> Planning design effect: 1.0000

# Anticipating the clustering component: the weighting loss above,
# multiplied by the clustering component the planning arguments imply
design_effect(samp, icc = 0.05, n_per_psu = 25)
#> Planning design effect: 3.4375