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
stratumand positive finiteN(ultimate units). Optional columns includemax_weight,min_n_stratum,deff,resp_rate,eligibility_rate,eligible_per_unit, and complete domain columns named bytargets$domainorobjective$domain. Indicator values (p,mean,sd,var) belong inmeasures, notframe.For element designs, use the stratum and ultimate-unit totals without numbered stage columns. Optional
unit_costprices each unit andtake_allmarks strata to enumerate.For fixed takes, supply whole stage populations
N_1, ...,N_{S-1}, whole takestake_2, ...,take_S, and positive stage costscost_1, ...,cost_S. Stage costs replaceunit_cost.For a free two-stage take, supply
N_1orpsuand positivecost_1andcost_2. Omittake_2or set it toNAin the strata whose takes should be optimized. Bound the take withtake_2_min,take_2_max, andtake_2_step, as arguments or as frame columns of the same names.For a PSU register, supply
psuin place ofN_1. A fixed take usestake_2and can use element costs or the paircost_1,cost_2. A free take uses the stage costs and bounds above.
For
svyplan_precobjects, a precision result fromprec_alloc_joint().- ...
Additional arguments passed to methods. Unused arguments are rejected.
- measures
Long data frame keyed by
stratumand indicatorname. Supply one row for each indicator and stratum covered by its targets or objective. Each row specifies eitherpin[0, 1], ormeanand one of non-negativesdorvar. Optional columnsdeff,resp_rate,eligibility_rate,eligible_per_unit,icc_1, ...,icc_{S-1},var_ratio_1, ...,var_ratio_{S-1}, andresp_rate_1, ...,resp_rate_{S-1}override stratum defaults inframeand scalar arguments where supported. A scalardeff,resp_rate,eligibility_rateoreligible_per_unitother than 1 is refused when every row that a target or the objective uses takes the value from its own column or theframecolumn. Register fits useicc_1and ultimate-unitresp_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
nameand exactly one positivecv,moe, orrmoe. Optional columns aredomain(default".overall"),level(NAfor".overall"),alpha,df, andconstraint. Leaving outlevelapplies a domain row to every level of that domain inframe. Required unless bothobjectiveandbudgetare 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 withnameand optionaldomain,level,priority, andcomponentcolumns. Requiresbudget.- 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
stratumandN(ultimate units in the PSU). PSU sizes must sum toframe$Nwithin each stratum. Supply uniquepsu_idvalues to join the plan back to the register. Optionalcertaintyflags PSUs that must be included.zone_orderrequires 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, orframe$certainty_cutoff. Requirespsu.- n_psu_per_zone
Optional
1or2, the number of PSUs drawn per zone in each stratum remainder. Requirespsu. 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_groupgives each PSU's group.- control
Optional list with
max_nodes(default5000L) andgap(default0) controlling the whole-unit search.- unit_cost
Optional scalar or length-
nrow(frame)vector of per-unit stratum costs, overridingframe$unit_cost. Not used with stage costs.- alpha
Significance level, default
0.05.- deff
Default design effect multiplier (
> 0), scalar or lengthnrow(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 inframe.- eligible_per_unit
Default eligible units per sampled unit (
> 0). Not available withpsu.- df
Optional degrees of freedom for turning
moeandrmoetargets into variances with atquantile.- min_n_stratum
Optional minimum sample size per stratum. Scalar, length-
nrow(frame)vector, orframe$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, overridingframe$take_2_min. Default is1.- take_2_max
Optional maximum within-PSU take for free-take two-stage optimization. Positive whole number, scalar or length-
nrow(frame)vector, overridingframe$take_2_max. Defaults toN / N_1(or the smallest noncertainty PSU size whenpsuis 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, overridingframe$take_2_step. Default is1.- fpc
Finite population correction.
"unit"(default) uses the ultimate-unit correction."stage"uses stage-by-stage corrections withN_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.
stagescounts field stages: 1 for elements, the stage count of a cluster frame, and 2 for a PSU register. In a register fit,params$stagesis 1 because clustering enters the precision model through a design effect.nis the continuous total. Indetail,nandn_intgive continuous and whole ultimate units by stratum. Cluster frames also report PSU countsn_1andn_1_int, and stage takestake_2, ...,take_Swith their whole valuestake_2_int, ...,take_S_int. The whole field design isn_1_intPSUs withtake_s_intunits at each later stage.constraintsreports each target, achieved precision, and pass indicator at the continuous design.operationalgives 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.optimizationdescribes the continuous solve and holds the whole-unit search record insearch. Fixed-budget runs also reportobjectiveandobjective_value.For registers,
detail$n_psu_certainanddetail$n_psu_drawcount the certainty PSUs and the remainder draws, anddetail$n_1_intis their sum.detail$take_2andtake_2_intgive the remainder take. Zoned fits adddetail$n_zone. Thepsutable givescertaintyandtake_2per PSU, pluspsu_idif supplied,.zonefor zoned fits, and.variance_groupwhen drawing one PSU per zone. On certainty rowstake_2is the PSU's own take. On remainder rows it is the take if the PSU is drawn.ratesgives the rates the fit used, one row per stratum and indicator that a target or the objective reads, withstratum,name,resp_rate_1, ...,resp_rate_{S-1}for the stages of the precision model,resp_rateandeligibility_rate. Each rate comes from the measure row, then the stratum'sframecolumn, then the argument.targets,binding, andparamsretain 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