Distribute a sample across strata for a single indicator under a fixed total
n, a precision target (cv, moe, or rmoe), or a budget, using
Neyman, optimal, proportional, or Bankier power allocation. For multiple
indicators, overlapping domain targets, or a PSU register with certainty
selection, use n_alloc_joint().
Usage
n_alloc(frame, ...)
# Default S3 method
n_alloc(
frame,
...,
domains = NULL,
n = NULL,
cv = NULL,
moe = NULL,
rmoe = NULL,
budget = NULL,
alloc = c("neyman", "optimal", "proportional", "power"),
unit_cost = NULL,
alpha = 0.05,
deff = 1,
resp_rate = 1,
eligibility_rate = 1,
eligible_per_unit = 1,
df = NULL,
min_n_stratum = NULL,
min_n_domain = NULL,
alloc_q = 0.5,
fpc = c("unit", "stage", "none"),
control = NULL,
plan = NULL
)
# S3 method for class 'svyplan_prec'
n_alloc(
frame,
...,
n = NULL,
cv = NULL,
moe = NULL,
rmoe = NULL,
budget = NULL
)Arguments
- frame
For the default method, a stratum-level data frame describing the population to sample. Each row represents one stratum. When a design stratifies by several variables (such as region and urbanicity), cross them into a single stratification column first so that each row maps to one population cell.
Required columns
NPopulation count of units in each stratum. Must be positive and finite.
sdorvarWithin-stratum spread of the key variable, required except for a fixed
nunderalloc = "proportional"or"power". Supplysdorvar, not both. A frame withpand neither column derives its variance fromp, asN * p * (1 - p) / (N - 1)in an element design underfpc = "unit"andp * (1 - p)in a cluster design or underfpc = "none". Withoutsd,var, orp, fixed-nproportional and power rules allocate from stratum sizes alone and reportNAprecision.
Optional columns
stratumStratum label. Defaults to row numbers. Must be unique, or unique within each domain when
domainsis set.- Label columns
Other character, factor, or logical columns are carried into
$detailafterstratum.meanorpStratum population mean or proportion (in
[0, 1]). Required when solving forcvorrmoe, and byalloc = "power"whensdorvaris given.alloc_measurePositive stratum size measure used only by
alloc = "power". Defaults toN * abs(mean)(orN * p) when a variance is given, orNotherwise.unit_costPositive per-unit interviewing cost per stratum. Defaults to 1. Not allowed in cluster mode, which uses stage costs.
max_weightMaximum allowed gross sampling weight
N / nper stratum,NAfor none.min_n_stratumMinimum sample size per stratum,
NAfor none.n_stepWhole step size per stratum (
NAor 1 for none) son_intis a multiple ofn_step. Element frames only.take_allLogical (or 0/1). If
TRUE, every unit in the stratum is selected (census stratum). Element frames only.deff,resp_rate,eligibility_rate,eligible_per_unitPer-stratum design effect, response rate, eligibility rate, and eligible units per sampled unit.
NAentries fall back to the scalar argument, so a scalar other than 1 beside a column with noNAis refused, since it would have no effect. Vector arguments override these columns.icc_1, ...,icc_{S-1},var_ratio_1, ...,var_ratio_{S-1},take_2, ...,take_S,cost_1, ...,cost_S,N_1, ...,N_{S-1},resp_rate_1, ...,resp_rate_{S-1}Multistage cluster columns for arbitrary stage depth S >= 2. Adding
icc_1(andicc_2, ...,icc_{S-1}for deeper designs) activates stratified multistage allocation.
For
svyplan_precobjects, a precision result fromprec_alloc().- ...
Additional arguments passed to methods. Unused arguments are rejected.
- domains
Character vector of column names in
framethat partition strata into reporting domains, orNULL(default). When solving forcv,moe, orrmoe, the target is enforced inside every domain. Innandbudgetmodes, domains are reported in$domainsand constrained only ifmin_n_domainis supplied.- n
Total sample size. Specify exactly one of
n,cv,moe,rmoe, orbudget.- cv
Target coefficient of variation (relative standard error). Requires
meanorpinframe. Specify exactly one ofn,cv,moe,rmoe, orbudget.- moe
Target absolute margin of error (half-width of the confidence interval at
1 - alpha). Specify exactly one ofn,cv,moe,rmoe, orbudget.- rmoe
Target relative margin of error (
moe / abs(mean)). Requiresmeanorpinframe. Specify exactly one ofn,cv,moe,rmoe, orbudget.- budget
Total field budget. Caps the affordable allocation. Specify exactly one of
n,cv,moe,rmoe, orbudget.- alloc
Allocation rule, one of
"neyman"(default),"optimal","proportional", or"power".- unit_cost
Optional scalar or length-
nrow(frame)vector of per-stratum unit costs overridingframe$unit_cost. Element frames only.- alpha
Significance level for
moeandrmoe, default 0.05.- deff
Design effect multiplier (> 0). A scalar fills the
NArows offrame$deff, and a length-nrow(frame)vector overrides it.- resp_rate
Expected response rate among eligible units in
(0, 1]. Default 1. A scalar fills theNArows offrame$resp_rate, and a length-nrow(frame)vector overrides it.- eligibility_rate
Share of issued units in scope in
(0, 1]. Default 1. A scalar fills theNArows offrame$eligibility_rate, and a length-nrow(frame)vector overrides it.- eligible_per_unit
Expected eligible units per sampled unit (> 0). Default 1. A scalar fills the
NArows offrame$eligible_per_unit, and a length-nrow(frame)vector overrides it. May exceed 1 (for example, adults per household). Sample counts, bounds, weights, and costs remain in sampled units while variance terms useN * eligibility_rate * eligible_per_unitandresp_rate * eligibility_rate * eligible_per_unit.- df
Degrees of freedom of the variance estimator for computing
moeandrmoevia the Student t quantile.NULL(default) uses the normal quantile.- min_n_stratum
Optional minimum sample size per stratum. Scalar or length-
nrow(frame)vector overridingframe$min_n_stratum.- min_n_domain
Optional floor on each domain's total sample. Either a single positive number applied to every domain, or a data frame with columns
domain,level, andmin_n. Requires a singledomainscolumn. A floor above what the domain's strata can hold, continuously or in whole units, is refused.- alloc_q
Bankier power allocation exponent in
[0, 1], used only whenalloc = "power". Default 0.5.- fpc
Finite population correction mode, one of
"unit"(default),"stage", or"none"."unit"applies1 - n / Nto the stratum variance."stage"applies the stage-by-stage correction in cluster mode and requiresN_1, ...,N_{S-1}."none"drops the finite population correction.- control
NULL(default) or a list of branch-and-bound settings (max_nodes,gap) for searched whole-unit modes (cv/moe/rmoeunder"optimal"or"neyman", and"optimal"budgetmode without domains).max_nodesbounds the combination search. With three or more stages, the listing of take vectors before it has its own limit. An unfinished listing can return a"heuristic"design.- plan
Optional
svyplan()object providing design defaults.
Value
A svyplan_alloc object with type = "alloc", stages (1 for
element frames, S >= 2 for cluster frames), top-level continuous totals
and precision (n, se, moe, cv, rmoe), a stratum-level data
frame in $detail (also returned by as.data.frame()), an $operational
list for the integer field design, and $domains when domains is set.
Key columns of $detail include stratum, N, sd, unit_cost,
continuous n, operational n_int, base weight, effective size
n_eff, bounds .lower and .upper, .binding, .bound_source,
stratum precision (.se, .moe, .rmoe, .cv), and variance share
.share. Cluster mode adds take_2, ..., take_S, n_1, n_1_int,
and take_2_int, ..., take_S_int. When stage populations are
supplied it also adds N_1, ..., N_{S-1} and .frac_1, the continuous
first-stage sampling fraction n_1 / N_1.
Top-level fields report the continuous allocation. For fieldwork, use
$detail$n_int (and $detail$n_1_int, $detail$take_2_int, ... in
cluster mode). as.integer() returns the operational integer total.
$rates gives the rates the allocation used, one row per stratum, after
the argument and frame columns are resolved: resp_rate_1, ...,
resp_rate_{S-1} in cluster mode, then resp_rate and
eligibility_rate. eligible_per_unit is a yield and is not listed.
Details
Allocation rules
Allocation is controlled by alloc (matching strata_bound()).
proportional: \(n_h \propto N_h / r_h\)
neyman: \(n_h \propto N_h S_h \sqrt{d_h / r_h}\)
optimal: \(n_h \propto N_h S_h \sqrt{d_h / r_h} / \sqrt{c_h}\)
power: Bankier (1988) allocation, \(n_h \propto (S_h / |\mu_h|) X_h^q \sqrt{d_h / r_h}\), where \(X_h\) is
alloc_measure(defaultN * abs(mean)).
Bounds (min_n_stratum, max_weight, take_all, N_1) are enforced by
recursive Neyman allocation (Wesolowski et al., 2022). Fixed-n integer
rounding uses bounded largest-remainder / ORIC rounding (Cont and Heidari,
2014).
Cluster designs within strata
Adding icc_1 (and icc_2, ..., icc_{S-1} for deeper designs) to frame
switches n_alloc() to a stratified S-stage design. Each stratum's
effective SD is inflated by its S-stage clustering factor and its effective
per-element cost is (cost_1 + sum_{s=2}^S cost_s * prod_{j=2}^s take_j) / prod_{j=2}^S take_j. Missing take_s entries use the cost-optimal takes
from the stage costs and homogeneities, never below one expected response
per unit (a warning names the strata where that floor binds), and the
whole takes never fall below it either. A free take whose stage size per
parent unit cannot hold that floor is refused, in whole units as well as
continuously. N_1, ..., N_{S-1} cap the stage counts per stratum and
activate stage-level FPC when fpc = "stage". Under every fpc, a take
is at most the ratio of adjacent stage sizes (N_s / N_{s-1}, with N
for the last stage), continuously and, rounded down, in whole units. A
fixed take above it is refused, and so is a total that every PSU at those
takes cannot hold. The ratios describe balanced stages, so a design that
takes more from its larger parent units needs capacity data the frame does
not carry. A ratio whose sizes are not both given leaves its take uncapped.
Every PSU counted in N_1 is taken to contain at least one of the units
counted in N. The sampled PSUs of a stratum then hold at most N - N_1
units more than their count, under every fpc. A design within known
stage sizes meets this already. Where a stage size is missing, the bound
limits the takes, the totals and the whole PSU counts, free takes fall
when a total needs more PSUs than the room at the cost-optimal takes
leaves, and prec_alloc() warns about a supplied design that breaks it.
In fixed-n mode, when the rounded takes miss the whole total, each
stratum offers the whole totals near its share of n that its stage
sizes, PSU counts and bounds allow. These are other PSU counts at its
rounded takes, also for a stratum whose takes are all fixed, and other
free takes that field a nearby total exactly. Those keep the PSU count
and free takes within a factor of two of the continuous design, and take
any PSU count and takes the stage sizes allow when that design holds less
than one PSU. The strata totals are chosen to meet every min_n_domain
floor and to add up to n, or to come as close as they can. Totals far
from a stratum's share are not considered, so a design that reaches n
only by moving a stratum far from its share is not found, and a floor
that only such designs meet is refused.
Under "optimal", a stratum whose allocation needs more than N_1 PSUs
fields every PSU and raises its free takes instead.
In the searched modes, the whole design is found by branch-and-bound over
whole PSU counts and whole takes at every stage count, with control
setting its limits. Its status is in $operational$status ("optimal",
or "limit" when the node limit stopped it) and its record in
$optimization$search. With three or more stages, a stratum whose take
combinations are too many to list keeps a greedy rounding of the
continuous design. If numerical pruning loses a feasible starting design,
that design is retained. Both cases have status "heuristic" and a warning.
A target or budget that the cost-optimal takes cannot meet is not refused
when the search can still vary a take. The search then runs over every
take first, and the continuous design is the one at the takes of the whole
design, which $params$searched_takes records. prec_alloc() assesses
the design at those takes, and a new target given to n_alloc() on that
assessment sizes the original request again. The refusal stands when
the search proves that no whole design exists, and a search that stops
with no design raises an error of class svyplan_plan_unknown. With
domains, a domain whose min_n_domain floor sets its design, or whose
searched design the floor repair changes, is not proven either. Its
record in $optimization$domains reads "heuristic" with a reason,
and so does $operational$status.
Domains and steps
When domains is set and a precision target (cv, moe, or rmoe) is
given, every domain meets the target on its own strata. National precision
is reported in $se, $moe, and $cv without acting as a constraint. To
enforce national and domain targets simultaneously, or multiple indicators,
use n_alloc_joint().
When frame$n_step is supplied on an element frame, every stratum's n_int
is a whole multiple of n_step.
References
Valliant, R., Dever, J. A., and Kreuter, F. (2018). Practical Tools for Designing and Weighting Survey Samples, 2nd ed. Springer. Chapters 5 and 9.
Bankier, M. D. (1988). Power allocations: determining sample sizes for subnational areas. The American Statistician, 42(3), 174–177.
Cont, R. and Heidari, M. (2014). Optimal rounding under integer constraints. arXiv preprint arXiv:1501.00014.
Wesołowski, J., Wieczorkowski, R., and Wójciak, W. (2022). Optimality of the recursive Neyman allocation. Journal of Survey Statistics and Methodology, 10(5), 1263–1275.
See also
n_alloc_joint() for joint multi-indicator, overlapping-domain,
and PSU-register allocation, prec_alloc() for the inverse precision
assessment, strata_bound() for building strata, and n_multi() for
unstratified multi-indicator sizing.
Other stratified design functions:
merge_psus(),
n_alloc_joint(),
prec_alloc(),
prec_alloc_joint(),
strata_bound()
Examples
frame <- data.frame(
stratum = c("A", "B", "C"),
N = c(4000, 3000, 3000),
sd = c(10, 15, 8),
mean = c(50, 60, 55),
unit_cost = c(1, 1.5, 1)
)
n_alloc(frame, n = 600)
#> Stratum allocation (neyman, 3 strata)
#> field design: n = 600, cv = 0.0079, cost = 724
#> continuous design: n = 600, cv = 0.0079, se = 0.4305
#> (deff = 1)
#> design df = 597
n_alloc(frame, cv = 0.03)
#> Stratum allocation (neyman, 3 strata)
#> field design: n = 45, cv = 0.0298, cost = 54
#> continuous design: n = 44.23479, cv = 0.0300, se = 1.6350
#> (deff = 1)
#> design df = 42
n_alloc(frame, moe = 1.5)
#> Stratum allocation (neyman, 3 strata)
#> field design: n = 199, cv = 0.0140, cost = 240
#> continuous design: n = 198.5511, cv = 0.0140, se = 0.7653
#> (deff = 1)
#> design df = 196
frame_constraints <- transform(
frame,
max_weight = c(25, 20, NA),
take_all = c(FALSE, FALSE, TRUE)
)
n_alloc(frame_constraints, budget = 3500, alloc = "optimal", min_n_stratum = 40)
#> Stratum allocation (optimal, 3 strata)
#> field design: n = 3403, cv = 0.0076, cost = 3500
#> continuous design: n = 3403.425, cv = 0.0076, se = 0.4125
#> (min_n_stratum = 40, deff = 1)
#> design df = 401
frame_domains <- data.frame(
province = c("North", "North", "South", "South"),
stratum = c("Urban", "Rural", "Urban", "Rural"),
N = c(2000, 3000, 1800, 3200),
sd = c(12, 18, 10, 16),
mean = c(55, 48, 58, 50)
)
n_alloc(frame_domains, domains = "province",
cv = 0.04, alloc = "power", alloc_q = 0.3)
#> Stratum allocation (power, 4 strata)
#> field design: n = 104, cv = 0.0280, cost = 104
#> continuous design: n = 101.8385, cv = 0.0283, se = 1.4666
#> (deff = 1)
#> design df = 100
#> Domains: 2
#>
#> province .domain .n .se .moe .rmoe .cv .cost
#> North 5_North 58.67031 2.0320 3.982647 0.07839856 0.0400 59
#> South 5_South 43.16817 2.1152 4.145716 0.07839856 0.0400 43
# Power allocation on a size measure alone
sizes <- data.frame(stratum = c("A", "B", "C"), N = c(4e5, 1e5, 2.5e4))
n_alloc(sizes, n = 60, alloc = "power", alloc_q = 0.25, min_n_stratum = 15)
#> Stratum allocation (power, 3 strata)
#> field design: n = 60, cost = 60
#> continuous design: n = 60
#> (min_n_stratum = 15, deff = 1)
#> precision: not assessed (no 'sd', 'var' or 'p' in frame)
#> design df = 57
# Stratified two-stage design (EAs then households per stratum)
frame_cluster <- data.frame(
stratum = c("Urban", "Rural"),
N = c(50000, 150000),
sd = c(0.45, 0.48),
mean = c(0.35, 0.25),
icc_1 = c(0.03, 0.08),
cost_1 = c(300, 600),
cost_2 = c(40, 60)
)
n_alloc(frame_cluster, cv = 0.05)
#> Stratum allocation (neyman, two-stage, 2 strata)
#> field design: n = 2005, n_1 = 170, cv = 0.0500, cost = 205560
#> continuous design: n = 1979.882, cv = 0.0500, se = 0.0138
#> (deff = 1)
#> design df = 168