Skip to contents

Re-exported from svyplan. Compute the design effect or effective sample size from sampling weights. Five methods are available: Kish (default), Henry, Spencer, Chen-Rust, and cluster planning.

Usage

design_effect(x = NULL, ...)

effective_n(x = NULL, ...)

# S3 method for class 'tbl_sample'
design_effect(x, ..., y = NULL, x_cal = NULL, method = "kish")

# S3 method for class 'tbl_sample'
effective_n(x, ..., y = NULL, x_cal = NULL, method = "kish")

Arguments

x

A numeric weight vector or a tbl_sample.

...

Passed to the svyplan method.

y

<data-masking> Outcome variable (column name). Required for Henry, Spencer, and CR methods.

x_cal

<data-masking> Calibration covariate (column name). Required for the Henry method.

method

Design effect method. One of "kish" (default), "henry", "spencer", or "cr". See svyplan::design_effect() for details.

Details

The tbl_sample methods extract what they can from the sample:

  • Weights from .weight

  • Selection probabilities from .weight_1 (for Spencer)

  • Stratification and clustering variables from the stored design (for CR)

The user only needs to supply column names for variables that are not part of the sampling metadata: y (outcome) for all non-Kish methods, and x_cal (calibration covariate) for Henry.

Examples

# Kish design effect (default)
set.seed(1)
frame <- data.frame(
  id = 1:200,
  stratum = rep(c("A", "B"), each = 100),
  income = c(rnorm(100, 50, 10), rnorm(100, 80, 15))
)
samp <- sampling_design() |>
  stratify_by(stratum) |>
  draw(n = c(A = 10, B = 40)) |>
  execute(frame, seed = 1)

design_effect(samp)
#> [1] 1.5625
effective_n(samp)
#> [1] 32

# Spencer (selection probabilities extracted automatically)
design_effect(samp, y = income, method = "spencer")
#> [1] 3.57891