Skip to contents

Allocate a sample across atomic strata to meet precision requirements for multiple indicators and domains at once, or to minimize a priority-weighted relative variance within a fixed budget. Supports element allocation, fixed-take multistage allocation, and two-stage allocation with a free within-PSU take. A PSU register adds certainty-aware two-stage planning.

Usage

n_alloc_joint(frame, ...)

# Default S3 method
n_alloc_joint(
  frame,
  measures = NULL,
  ...,
  targets = NULL,
  objective = NULL,
  budget = NULL,
  psu = NULL,
  certainty_cutoff = NULL,
  n_psu_per_zone = NULL,
  control = NULL,
  unit_cost = NULL,
  alpha = 0.05,
  deff = 1,
  resp_rate = 1,
  eligibility_rate = 1,
  eligible_per_unit = 1,
  df = NULL,
  min_n_stratum = NULL,
  take_2_min = NULL,
  take_2_max = NULL,
  take_2_step = NULL,
  fpc = c("unit", "stage", "none"),
  plan = NULL
)

# S3 method for class 'svyplan_prec'
n_alloc_joint(frame, ...)

Arguments

frame

For the default method, a stratum-level data frame describing atomic allocation strata. Required columns are unique, non-missing stratum and positive finite N (ultimate units). Optional columns include max_weight, min_n_stratum, deff, resp_rate, eligibility_rate, eligible_per_unit, and complete domain columns named by targets$domain or objective$domain. Indicator values (p, mean, sd, var) belong in measures, not frame.

  • For element designs, use the stratum and ultimate-unit totals without numbered stage columns. Optional unit_cost prices each unit and take_all marks strata to enumerate.

  • For fixed takes, supply whole stage populations N_1, ..., N_{S-1}, whole takes take_2, ..., take_S, and positive stage costs cost_1, ..., cost_S. Stage costs replace unit_cost.

  • For a free two-stage take, supply N_1 or psu and positive cost_1 and cost_2. Omit take_2 or set it to NA in the strata whose takes should be optimized. Bound the take with take_2_min, take_2_max, and take_2_step, as arguments or as frame columns of the same names.

  • For a PSU register, supply psu in place of N_1. A fixed take uses take_2 and can use element costs or the pair cost_1, cost_2. A free take uses the stage costs and bounds above.

For svyplan_prec objects, a precision result from prec_alloc_joint().

...

Additional arguments passed to methods. Unused arguments are rejected.

measures

Long data frame keyed by stratum and indicator name. Supply one row for each indicator and stratum covered by its targets or objective. Each row specifies either p in [0, 1], or mean and one of non-negative sd or var. Optional columns deff, resp_rate, eligibility_rate, eligible_per_unit, icc_1, ..., icc_{S-1}, var_ratio_1, ..., var_ratio_{S-1}, and resp_rate_1, ..., resp_rate_{S-1} override stratum defaults in frame and scalar arguments where supported. A scalar deff, resp_rate, eligibility_rate or eligible_per_unit other than 1 is refused when every row that a target or the objective uses takes the value from its own column or the frame column. Register fits use icc_1 and ultimate-unit resp_rate. They require eligibility as an argument or frame column, a variance ratio of 1, and no upper-stage response-rate columns.

targets

Optional long data frame with one precision target per row. Requires name and exactly one positive cv, moe, or rmoe. Optional columns are domain (default ".overall"), level (NA for ".overall"), alpha, df, and constraint. Leaving out level applies a domain row to every level of that domain in frame. Required unless both objective and budget are supplied.

objective

Optional estimates whose priority-weighted relative variance is minimized within budget. Either a character vector of indicator names (overall domain, equal priority) or a data frame with name and optional domain, level, priority, and component columns. Requires budget.

budget

Optional positive field budget. Must be supplied with objective.

psu

Optional PSU register for certainty-aware two-stage allocation, one row per PSU, with stratum and N (ultimate units in the PSU). PSU sizes must sum to frame$N within each stratum. Supply unique psu_id values to join the plan back to the register. Optional certainty flags PSUs that must be included. zone_order requires zoning and orders PSUs within each stratum without missing values or ties. The default zone order is decreasing PSU size.

certainty_cutoff

Optional inclusion probability threshold in (0, 1] at which a register PSU is taken with certainty. Scalar, length-nrow(frame) vector, or frame$certainty_cutoff. Requires psu.

n_psu_per_zone

Optional 1 or 2, the number of PSUs drawn per zone in each stratum remainder. Requires psu. A selection zone is a group of noncertainty PSUs, formed by ordering the remainder of a stratum (psu$zone_order, by default decreasing size) and cutting it by cumulative size. No geographic variable is needed. With two PSUs per zone the zones are the variance groups. With one PSU per zone the zones are collapsed into variance groups of two or three, which can span input strata, and $psu$.variance_group gives each PSU's group.

control

Optional list with max_nodes (default 5000L) and gap (default 0) controlling the whole-unit search.

unit_cost

Optional scalar or length-nrow(frame) vector of per-unit stratum costs, overriding frame$unit_cost. Not used with stage costs.

alpha

Significance level, default 0.05.

deff

Default design effect multiplier (> 0), scalar or length nrow(frame).

resp_rate

Default expected response rate among eligible units in (0, 1].

eligibility_rate

Default share of issued units in scope in (0, 1]. For a register, supply the rate by argument or in frame.

eligible_per_unit

Default eligible units per sampled unit (> 0). Not available with psu.

df

Optional degrees of freedom for turning moe and rmoe targets into variances with a t quantile.

min_n_stratum

Optional minimum sample size per stratum. Scalar, length-nrow(frame) vector, or frame$min_n_stratum.

take_2_min

Optional minimum within-PSU take for free-take two-stage optimization. Positive whole number, scalar or length-nrow(frame) vector, overriding frame$take_2_min. Default is 1.

take_2_max

Optional maximum within-PSU take for free-take two-stage optimization. Positive whole number, scalar or length-nrow(frame) vector, overriding frame$take_2_max. Defaults to N / N_1 (or the smallest noncertainty PSU size when psu is supplied).

take_2_step

Optional integer step between candidate within-PSU takes for free-take two-stage optimization. Positive whole number, scalar or length-nrow(frame) vector, overriding frame$take_2_step. Default is 1.

fpc

Finite population correction. "unit" (default) uses the ultimate-unit correction. "stage" uses stage-by-stage corrections with N_1, ..., N_{S-1}. "none" applies no correction. Leave this at its default for a PSU register, which uses its own certainty and remainder variance model.

plan

Optional svyplan() object providing design defaults.

Value

A svyplan_alloc_joint object inheriting from svyplan_alloc.

  • stages counts field stages: 1 for elements, the stage count of a cluster frame, and 2 for a PSU register. In a register fit, params$stages is 1 because clustering enters the precision model through a design effect.

  • n is the continuous total. In detail, n and n_int give continuous and whole ultimate units by stratum. Cluster frames also report PSU counts n_1 and n_1_int, and stage takes take_2, ..., take_S with their whole values take_2_int, ..., take_S_int. The whole field design is n_1_int PSUs with take_s_int units at each later stage.

  • constraints reports each target, achieved precision, and pass indicator at the continuous design. operational gives the whole total, cost, constraint results, all_pass, and search status. Whole counts are stored as doubles and can represent integers exactly up to 2^53.

  • optimization describes the continuous solve and holds the whole-unit search record in search. Fixed-budget runs also report objective and objective_value.

  • For registers, detail$n_psu_certain and detail$n_psu_draw count the certainty PSUs and the remainder draws, and detail$n_1_int is their sum. detail$take_2 and take_2_int give the remainder take. Zoned fits add detail$n_zone. The psu table gives certainty and take_2 per PSU, plus psu_id if supplied, .zone for zoned fits, and .variance_group when drawing one PSU per zone. On certainty rows take_2 is the PSU's own take. On remainder rows it is the take if the PSU is drawn.

  • rates gives the rates the fit used, one row per stratum and indicator that a target or the objective reads, with stratum, name, resp_rate_1, ..., resp_rate_{S-1} for the stages of the precision model, resp_rate and eligibility_rate. Each rate comes from the measure row, then the stratum's frame column, then the argument.

  • targets, binding, and params retain the requirements, binding constraints, and inputs.

Details

Minimum-cost and fixed-budget problems

Without objective, n_alloc_joint() finds the cheapest allocation meeting every precision requirement in targets. With objective and budget, it minimizes the priority-weighted sum of squared CVs across the objective components subject to budget and any hard requirements in targets. Replanning from prec_alloc_joint() uses the achieved metrics as targets in minimum-cost mode and the assessed cost as the budget in objective mode. It optimizes the resulting problem again.

Multistage and register designs

Fixed-take multistage designs keep later-stage takes fixed and optimize the first-stage PSU counts (n_1) per stratum. Population columns (N, N_1, ..., N_{S-1}) are stratum totals, while takes (take_2, ..., take_S) count units per parent unit. Stage response rates (resp_rate_1, ..., resp_rate_{S-1}, resp_rate) act at the stage they name.

With a psu register, n_alloc_joint() separates certainty PSUs from the remainder, prices certainty visits alongside drawn PSUs, and chooses the whole-unit field design by branch-and-bound search over per-stratum designs. A cluster frame or register cannot use take_all.

Read the field design and its certificate

Use $operational for fieldwork. Its whole counts may differ from the continuous design. Read $operational$status and $optimization$search to see whether the search proved optimality, reached the requested gap, or stopped at its node limit.

For a non-register minimum-cost fit with fixed takes, the continuous solver checks KKT conditions. With a free take, the continuous minimum-cost certificate is a duality gap. $optimization$classification is "optimal" when the design costs within a relative 1e-6 of the Lagrangian dual bound in $optimization$dual_value, and "feasible" otherwise, with the gap in $optimization$relative_duality_gap. That gap is (cost - dual_value) / cost, so a feasible design meets every target and its cost exceeds the optimum by at most the gap times its own cost.

In non-register free-take budget mode, a budget below the dual cost bound is refused. A budget between the bound and the cheapest design found raises an error of class svyplan_plan_unknown. Otherwise the design is the most precise the solver found within the budget, and its certificate is a bound on precision. Weak duality gives $optimization$objective_lower_bound, below which no design can go that costs at most the budget, or at most the returned design when that costs more. The design is "optimal" when its objective lies within a relative 1e-6 of that bound ($optimization$objective_gap). It is "feasible", with both fields missing, when the solver has no multiplier for the objective, as at a budget that only the cheapest design fits. Continuous and whole free-take fits allow a relative budget tolerance of 1e-6.

See vignette("joint-allocation") for the three input tables, assessment of whole designs, and an example of a fixed-budget grid.

References

Bethel, J. (1989). Sample allocation in multivariate surveys. Survey Methodology, 15(1), 47–57.

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

See also

prec_alloc_joint() for the inverse assessment, n_alloc() for classic single-indicator stratum allocation, merge_psus() for merging small PSUs before register planning, and predict.svyplan() for budget and take frontiers.

Other stratified design functions: merge_psus(), n_alloc(), prec_alloc(), prec_alloc_joint(), strata_bound()

Examples

frame <- data.frame(
  stratum = c("North urban", "North rural", "South urban"),
  region = c("North", "North", "South"),
  N = c(1000, 1800, 1200)
)
measures <- data.frame(
  stratum = rep(frame$stratum, 2),
  name = rep(c("coverage", "income"), each = 3),
  p = c(0.5, 0.4, 0.6, NA, NA, NA),
  mean = c(NA, NA, NA, 50, 55, 60),
  sd = c(NA, NA, NA, 10, 12, 15)
)
targets <- data.frame(
  name = c("coverage", "income"),
  domain = c(".overall", "region"),
  level = c(NA, "North"),
  cv = c(0.06, NA),
  moe = c(NA, 3)
)
fit <- n_alloc_joint(frame, measures, targets = targets)
fit
#> Joint constrained allocation (Bethel)
#> question: cheapest design meeting every precision target
#> field design: n = 268, cost = 268 (2 targets, all pass)
#> continuous optimum: n = 267.4031, cost = 267 (integerizing costs +0.22%)
#> binding: coverage@.overall:cv (target 0.06, achieved 0.06)
prec_alloc_joint(fit, n = fit$detail$n_int)
#> Joint allocation precision (2 constraints)
#> targets: all pass

# Fixed-budget weighted objective subject to the same targets
bought <- n_alloc_joint(
  frame, measures, targets = targets,
  objective = "income", budget = 400
)
bought$objective
#>         component   name   domain level priority      .relvar        .cv
#> 1 income@.overall income .overall  <NA>        1 0.0001130444 0.01063223
#>   .contribution .share
#> 1  0.0001130444      1

# Fixed and free takes for a two-stage coverage plan
cluster <- data.frame(
  stratum = c("A", "B"), N = c(20000, 8000), N_1 = c(400, 160),
  cost_1 = 400, cost_2 = 40, take_2 = c(12, 8)
)
coverage <- data.frame(
  stratum = c("A", "B"), name = "coverage", p = c(0.5, 0.4), icc_1 = 0.05
)
goal <- data.frame(name = "coverage", cv = 0.10)
held <- n_alloc_joint(cluster, coverage, targets = goal)
open <- n_alloc_joint(transform(cluster, take_2 = NULL), coverage,
                      targets = goal, take_2_min = 2, take_2_max = 20)
held$detail[c("n_1_int", "take_2")]
#>   n_1_int take_2
#> 1      10     12
#> 2       6      8
open$detail[c("n_1_int", "take_2_int")]
#>   n_1_int take_2_int
#> 1       9         14
#> 2       4         15

# A register with two remainder PSUs drawn per zone
register <- data.frame(stratum = "A", psu_id = seq_len(100), N = 1000)
zoned <- n_alloc_joint(
  data.frame(stratum = "A", N = 100000, take_2 = 10),
  coverage[1, ], targets = transform(goal, cv = 0.08),
  psu = register, n_psu_per_zone = 2
)
zoned$detail[c("n_psu_certain", "n_psu_draw", "n_zone", "n_int")]
#>   n_psu_certain n_psu_draw n_zone n_int
#> 1             0         24     12   240
prec_alloc_joint(zoned)
#> Joint allocation precision (1 constraints)
#> targets: all pass