Skip to contents

Compute optimal per-stage sample sizes for an S-stage cluster design (S >= 2), minimizing cost for a given precision or minimizing variance for a given budget.

Usage

# S3 method for class 'data.frame'
n_cluster(
  x,
  stage_cost = NULL,
  ...,
  domains = NULL,
  budget = NULL,
  stage_n = NULL,
  allocation = c("separate", "joint"),
  domain_sampling = c("separate", "natural"),
  min_n_domain = NULL,
  fixed_cost = 0,
  resp_rate = 1,
  eligibility_rate = 1,
  eligible_per_unit = 1,
  N = NULL,
  fpc = c("auto", "none", "stage"),
  control = NULL,
  plan = NULL
)

n_cluster(x = NULL, ...)

# Default S3 method
n_cluster(
  x = NULL,
  ...,
  stage_cost = NULL,
  icc = NULL,
  unit_relvar = NULL,
  var_ratio = NULL,
  cv = NULL,
  budget = NULL,
  stage_n = NULL,
  resp_rate = 1,
  eligibility_rate = 1,
  eligible_per_unit = 1,
  fixed_cost = 0,
  N = NULL,
  fpc = c("auto", "none", "stage"),
  control = NULL,
  plan = NULL
)

# S3 method for class 'svyplan_prec'
n_cluster(x, ..., cv = NULL, budget = NULL)

Arguments

x

First argument used for S3 dispatch. Supply a numeric vector of per-stage costs (same as stage_cost), a data frame of indicators (one row per indicator with stage homogeneity and precision target columns), a svyplan_prec result from prec_cluster(), or a svyplan() profile. Leave NULL when supplying stage_cost by name.

stage_cost

Numeric vector of per-stage costs (length S >= 2, ordered from outermost stage 1 to innermost stage S). Optional unique names on stage_cost (such as c(district = 500, ea = 100, hh = 50)) flow into output stage names. Unnamed vectors use stage_1, ..., stage_S. Optional when passed as x in the default method, required (directly or via plan) for the data.frame method.

...

Additional arguments passed to methods. Unused arguments are rejected.

domains

Optional character vector naming domain columns in x (data frame method). Each domain is solved on its own unless allocation = "joint" in budget mode.

budget

Total budget. Specify exactly one of cv or budget in the single-indicator method, or supply alongside an indicator table to minimize the worst precision ratio within budget.

stage_n

Optional numeric vector of length stages fixing selected stage sizes. Use NA for free stages to optimize and positive numbers (>= 1) for fixed stages. At least one stage must remain NA (use prec_cluster() when all stages are fixed). Names, if given, place each value: the stage names, stage_<k>, or n_1, take_2, and so on. Other names are refused.

allocation

How a budget is split across domains, either "separate" (default) or "joint" (one budget split across domains to minimize the worst precision ratio). Applies when x is a data frame with domains and budget. Under "joint", every domain keeps at least one PSU in the continuous design as in the whole one, so the least a domain receives is the cost of its one-PSU design. The continuous split gives $n and $cost. The whole design in $operational is searched over the whole budget, not domain by domain within that split. It is the least worst ratio over whole designs that fit the budget, found by bisection between a feasible design and a ratio that no whole design reaches within the budget. The floors of each design (one PSU, or min_n_domain, in every domain) are checked against the budget on their own, and a refusal names the whole design when only its floors are out of reach.

domain_sampling

How per-domain requirements combine. Only "separate" (default) is supported for multistage cluster designs.

min_n_domain

Optional positive minimum total sample size per domain.

fixed_cost

Fixed overhead cost (C0). Default 0. Total cost is C0 + sum_{s=1}^S c_s * prod_{j=1}^s n_j. With domains, the separate allocation sizes each domain as its own design and charges C0 once per domain, while allocation = "joint" charges it once for the whole budget.

resp_rate

Expected response rate(s) in (0, 1], default 1. A scalar applies to the final stage (ultimate units) with earlier stages set to 1. A vector of length stages supplies stage-1 through stage-S rates. Its names, if given, place each rate: the stage names, stage_<k>, or resp_rate_1, ..., resp_rate_{S-1} with resp_rate for the last.

eligibility_rate

Share of issued final-stage units in scope, such as occupied dwellings, in (0, 1]. Default 1.

eligible_per_unit

Eligible units per final-stage unit, a positive number, default 1, such as married women per household. Can exceed 1. Multiplies the final-stage response rate in the realized take while sizes stay in final-stage units. With an indicator table, an eligible_per_unit column gives each row its own value, and the argument fills rows where it is absent or NA.

N

Optional numeric vector of length stages giving aggregate population counts from stage 1 to stage S (outermost to innermost, so N[1] <= N[2] <= ... <= N[S]). For example, 40 districts, 400 EAs, and 12000 households is N = c(40, 400, 12000). Names, if given, place each count: the stage names, stage_<k>, or N_1, ..., N_{S-1} with N for the last.

fpc

Which finite population correction the variance carries. "auto" (default) applies stage-by-stage correction ("stage") whenever N (or population columns) is supplied, and "none" otherwise. "stage" requires N (or population columns). Supply population counts only with "auto" or "stage".

control

NULL (default) or a list with max_nodes, the node limit of the whole-unit search (default 2e7). Under allocation = "joint", it bounds the joint search as a whole (the bisection and the spending of the leftover budget), and each domain's fit at its continuous share separately. gap is refused. A single search keeps no lower bound to stop at, and the joint search stops only when its bracket closes. Its measured gap is reported in $operational$search$gap.

plan

Optional svyplan() object providing design defaults.

icc

Numeric vector of stage homogeneities of length stages - 1 (canonical conditional measures from varcomp()), or a svyplan_varcomp object. Typical values in household surveys range from 0.01 to 0.10.

unit_relvar

Unit relvariance, the unit variance of the analysis variable over its squared mean, default 1. A proportion p has (1 - p) / p, so the default plans a proportion as if p = 0.5. A varcomp() result estimated from data sets it, and an explicit value is then refused. One backed out of a design effect sets none, so unit_relvar must be supplied beside it.

var_ratio

Ratio of stage component unit variance to the analysis variable's unit variance, default 1. A scalar supplies stage 1 and derives deeper ratios via k_s = k_{s-1} * (1 - icc_{s-1}), exact for equal-sized or PPS sub-units. Supply a length stages - 1 vector when unequal-sized sub-units are drawn by SRS. In that vector, an NA after the first entry is derived the same way. Refused when icc is a varcomp() result, which sets it.

cv

Target coefficient of variation (relative standard error). Specify exactly one of cv or budget in the single-indicator method.

Value

A svyplan_cluster object with components:

n

Named numeric vector of continuous per-stage sample sizes (length stages). With several indicators the continuous solve returns the best design it found.

stages

Integer number of stages (S >= 2).

total_n

Continuous total sample size (prod(n)).

cv

Coefficient of variation of the continuous optimum.

cost

Cost of the continuous optimum.

operational

Whole-unit field design: n (named integer stage sizes), total_n, cost, and cv, all recomputed from the integer design, and search, with status ("optimal" when the search proved the design cheapest for a precision target, or most precise for a budget, "limit" when it stopped at its node limit with the best design found), nodes and max_nodes. With domains, search$by_domain gives each domain's status and search$nodes_by_domain its node count. Under allocation = "joint", a domain's design is proven only jointly, so every domain carries the joint status, and nodes_by_domain splits the joint search's nodes among the domains. search also holds the worst ratio ratio of the returned design, the proven lower bound bound on it, their relative gap, the number of bisection trials, and each domain's whole cost in shares.

params

List of input parameters. Stage response rates are stored as resp_rate_1, ..., resp_rate_{S-1} and resp_rate, the names the allocation frames use.

With an indicator data frame, the same class also carries $indicators, $detail, and (when domains is set) $domains and $operational$domains.

Details

General S-stage model

For an \(S\)-stage design with stage variance components \(R_s = V k_s \delta_s\) for \(s = 1, \dots, S - 1\) and \(R_S = V k_{S-1}(1 - \delta_{S-1})\), gross stage sizes \(n_1, \dots, n_S\), stage response multipliers \(r_1, \dots, r_S\) (with \(r_S\) including eligibility_rate * eligible_per_unit), and per-parent capacities \(M_1 = N_1\), \(M_s = N_s / N_{s-1}\) for \(1 < s < S\) and \(M_S = N e / N_{S-1}\), where \(e\) is eligibility_rate * eligible_per_unit (all infinite under fpc = "none"), the squared CV is $$CV^2 = \sum_{s=1}^{S} \frac{R_s}{\prod_{j=1}^{s} n_j r_j} \left(1 - \frac{n_s r_s}{M_s}\right).$$ Regrouping terms by \(1 / \prod_{j=1}^s n_j\) yields the telescoping form $$CV^2 = \sum_{s=1}^{S} \frac{\alpha_s}{\prod_{j=1}^{s} n_j} - \kappa,$$ where \(\kappa = R_1 / M_1\), \(\alpha_s = (R_s - R_{s+1}/M_{s+1}) / \prod_{j=1}^s r_j\) for \(s < S\), and \(\alpha_S = R_S / \prod_{j=1}^S r_j\).

When all \(\alpha_s > 0\) and takes are unconstrained, Cauchy-Schwarz gives the exact cost-optimal per-stage takes $$n_s^* = \sqrt{\frac{c_{s-1} \alpha_s}{c_s \alpha_{s-1}}}, \quad s = 2, \dots, S.$$ Box constraints, fixed stages (stage_n), and non-positive \(\alpha_s\) (when a small parent cluster makes full enumeration optimal) are solved exactly via active-face elimination and log-convex coordinate optimization. Whole-unit operational designs in $operational come from a branch-and-bound search that proves the design cheapest for a precision target, or most precise for a budget, or reports status = "limit" when it stops at its node limit. A search that stops before finding any design raises an error of class svyplan_plan_unknown, since whether one exists is then unknown.

Several indicators at once

Pass an indicator data frame as the first argument to size one S-stage design against multiple precision targets simultaneously. Required stage homogeneity columns are icc_1, ..., icc_{S-1}. Optional stage columns are var_ratio_1, ..., var_ratio_{S-1}, stage response rates resp_rate_1, ..., resp_rate_{S-1} and resp_rate (final stage), and population counts N_1, ..., N_{S-1} and N (final stage).

The exact continuous solution above holds for one indicator. With several, the continuous optimum comes from a local search in log takes from several starting points, and it is not certified. The whole design in $operational keeps its own proof, since its branch-and-bound search does not depend on that starting point.

References

Valliant, R., Dever, J. A., and Kreuter, F. (2018). Practical Tools for Designing and Weighting Survey Samples, 2nd ed. Springer. Chapter 9.

See also

prec_cluster() for the inverse, varcomp() for estimating variance components, design_effect() for planning design effects, n_multi() for single-stage multi-indicator sizing, and n_alloc() for stratified multistage allocation.

Other cluster design functions: prec_cluster(), varcomp()

Examples

# 2-stage, budget mode
n_cluster(stage_cost = c(500, 50), icc = 0.05, budget = 100000)
#> Optimal 2-stage allocation
#> field design: stage_1 = 80 | stage_2 = 15 -> total n = 1200
#> cv = 0.0376, cost = 100000
#> design df = 79
#> # summary() for the continuous optimum, the design effect and costs

# 2-stage, CV mode with named stages
n_cluster(c(ea = 500, hh = 50), icc = 0.05, cv = 0.05)
#> Optimal 2-stage allocation
#> field design: ea = 52 | hh = 12 -> total n = 624
#> cv = 0.0498, cost = 57200
#> design df = 51
#> # summary() for the continuous optimum, the design effect and costs

# 2-stage, fixed cluster take (MICS/DHS style: 20 households per EA)
n_cluster(c(500, 50), icc = 0.05, budget = 100000, stage_n = c(NA, 20))
#> Optimal 2-stage allocation
#> field design: stage_1 = 66 | stage_2 = 20 -> total n = 1320
#> cv = 0.0384, cost = 99000
#> design df = 65
#> # summary() for the continuous optimum, the design effect and costs

# 3-stage with finite population correction (fpc = "auto" enables stage FPC)
n_cluster(c(300, 50, 10), icc = c(0.04, 0.10), unit_relvar = 0.7 / 0.3,
          cv = 0.06, N = c(40, 400, 12000))
#> Optimal 3-stage allocation
#> field design: stage_1 = 28 | stage_2 = 4 | stage_3 = 9 -> total n = 1008
#> corrected by stage for stage_1 = 40 | stage_2 = 400 | stage_3 = 12000
#> cv = 0.0600, cost = 24080
#> design df = 27
#> # summary() for the continuous optimum, the design effect and costs

# 4-stage design with custom stage names
n_cluster(
  c(district = 1000, ea = 200, segment = 60, hh = 15),
  icc = c(0.01, 0.03, 0.06),
  cv = 0.05
)
#> Optimal 4-stage allocation
#> field design: district = 15 | ea = 3 | segment = 3 | hh = 9 -> total n = 1215
#> cv = 0.0500, cost = 50325
#> design df = 14
#> # summary() for the continuous optimum, the design effect and costs

# Several indicators, 2-stage CV mode
indicators <- data.frame(
  name  = c("stunting", "anemia"),
  p     = c(0.30, 0.10),
  cv    = c(0.10, 0.15),
  icc_1 = c(0.02, 0.05)
)
n_cluster(indicators, stage_cost = c(500, 50))
#> Multi-indicator optimal allocation (2-stage)
#> field design: stage_1 = 52 | stage_2 = 12 -> total n = 624
#> worst cv = 0.1495 (anemia), cost = 57200
#> binding: anemia
#> 
#>  name     .n  .cv_target .cv_achieved .binding
#>  stunting 293 0.1000     0.0675               
#>  anemia   656 0.1500     0.1495       *       
#> 
#> # summary() for the continuous optimum and each indicator's precision

# Design separately for two regions
by_region <- data.frame(region = c("North", "South"), name = "coverage",
                        p = c(0.5, 0.4), cv = 0.08, icc_1 = 0.05)
n_cluster(by_region, stage_cost = c(50, 10), domains = "region")$operational$domains
#>   region stage_1 stage_2 .total_n        .cv .cost .binding
#> 1  North      23      10      230 0.07939992  3450 coverage
#> 2  South      34      10      340 0.07998162  5100 coverage