Creates a svyrep.design object from a tbl_sample. "rwyb" builds
Rao-Wu-Yue-Beaumont factors with the svrep package from the recorded
stage mechanisms, and "random_groups" reads the replicates of
execute(reps = R). The other types build a survey::svydesign()
object and convert it with survey::as.svrepdesign().
Arguments
- x
A
tbl_sampleobject produced byexecute().- ...
Additional arguments passed to
survey::as.svrepdesign()and on to the replicate-weight generator it selects, such asreplicates,fay.rho,fpctype, ormse. Every argument must be named, and its name must be one those functions accept:typefollows the...and so is matched exactly, and a near miss such astypis reported rather than forwarded.designcannot be given, since this verb builds it from the sample. Fortype = "rwyb", onlyreplicates(default 500, integer at least 2),mse(default TRUE),compress(default TRUE) andlonely.psuare accepted.lonely.psu = "certainty"treats a final-stage stratum holding one noncertainty unit as taken with certainty, so it adds no variance of its own, whereas the default"fail"refuses such a stratum. Fortype = "random_groups", onlymse(defaultFALSE) is accepted.- type
The replicate method. The generic types,
"JK1"to"subbootstrap"below, resample first-stage units within first-stage strata and read nothing below them. The last three read more of the design."auto"(default): survey's choice,"JKn"for a stratified first stage and"JK1"otherwise."JK1"and"JKn": the delete-one jackknife of an unstratified first stage, and its stratified form (Wolter 2007, ch. 4). They keep the finite population correction of an equal-probability first stage."BRR"and"Fay": balanced half-samples, with Fay's damping set byfay.rho(Wolter 2007, ch. 3). They need an even number of first-stage units, at least two, in every first-stage stratum, and carry no finite population correction."bootstrap": the Canty-Davison bootstrap of first-stage units, which keeps an equal-probability first stage's correction (Canty and Davison 1999)."subbootstrap": the Rao-Wu rescaled bootstrap, with no finite population correction (Rao, Wu and Yue 1992). It accepts a PPS first stage."mrbbootstrap": Preston's multistage rescaled bootstrap, which reads the sampling fraction of every stage (Preston 2009). It reads one fraction per stratum, so it refuses a stage drawn with unequal probabilities without replacement, and it resamples none of a stratum of one, so it refuses a unit taken with probability 1 alone in its stratum above a later stage (samplyr_error_svrep_conversion_failed)."rwyb": the Rao-Wu-Yue-Beaumont bootstrap of every stage (Beaumont and Émond 2022). It needs the svrep package and is never chosen by"auto"."random_groups": the spread between the independent replicates ofexecute(reps = R), for any selection method (Wolter 2007, ch. 2).
The jackknife and balanced types give one set of replicate weights per sample. The bootstrap types draw from the session's random stream, so set a seed before the call, and raise
replicatesthrough...until the standard errors that will be read are stable. svrep'sestimate_boot_sim_cv()estimates that simulation error.- systematic_variance
What to do about the generic replicate weights built for
systematic,pps_systematicandpps_systematic_mrstages."warn"(default) builds them and warns once per call, naming every affected stage."approximate"builds them silently, for a caller who has acknowledged the approximation, and"error"refuses. Naming atypeis not an acknowledgment, since no type reproduces systematic selection. Census stages and stages that drew one unit in each pool are exempt, as inas_svydesign(). The choice and the affected stages are recorded in the"samplyr_systematic_variance"attribute of the result.- stages
NULL, the default, or1, which replicates the ultimate-cluster design ofas_svydesign(x, stages = 1): the stage-1 units are resampled within their strata, the correction is left out by choice, and no first-stage warning is raised. It is taken by the types that resample stage-1 units only, and refused with"mrbbootstrap","rwyb"and"random_groups"(samplyr_error_survey_argument).
Value
A svyrep.design object from the survey package. "rwyb" and
"random_groups" record their method in its "samplyr_replication"
attribute, and the treatment of systematic stages is recorded in
"samplyr_systematic_variance".
Details
What is replicated
A single-phase sample is replicated from the design as_svydesign()
exports, multi-stage samples, shared weights, independent frame stacks
and settled reserves included. A materialized occasion is replicated by
ultimate clusters, and a window's replicates are calibrated on the same
totals as its linearized design. "rwyb" is refused for an occasion
(samplyr_error_occasion_replicate_type). Of the two-phase samples, two
shapes are replicated, a second phase drawn within each final-stage pool
of phase 1, which is phase 1's design with a smaller final take, and a
second phase of a phase 1 fixed in one primary unit (every stage taken
for sure, which can be a census of its elements). Random groups, below,
also replicate a two-phase design executed whole with reps. The others
are refused (samplyr_error_svrep_twophase_unsupported).
The first stage under the generic types
The generic types read the spread of first-stage totals within first-stage strata, which carries the variance of the later stages as well. That reading needs no correction for a first stage drawn with replacement, and unequal probabilities at later stages reach it through the weights. It is approximate in three cases, each with a warning:
A PPS first stage drawn without replacement is read as drawn with replacement, and so is an equal-probability first stage under
"BRR","Fay"and"subbootstrap", which carry no correction. The variance leaves out the first-stage correction and tends to overstate, most at large first-stage sampling fractions (samplyr_warning_replicate_wr_first_stage)."JK1","JKn"and"bootstrap"keep an equal-probability first stage's correction and apply it to the later stages' variance too, which understates the variance as the first-stage fraction grows (samplyr_warning_replicate_first_stage_fpc).The minimum-replacement methods
pps_chromyandpps_systematic_mrare read as drawn with replacement, as every export reads them, which ignores the dependence between hits."mrbbootstrap"reads them that way too, with the same warning, and"rwyb"refuses them.
A first-stage unit taken with probability 1 above a later stage, by a
certainty rule or because its stratum is taken whole, is a stratum of
its own whose stage-2 units are resampled (see Statistical details). The
first stage is then stratified, so "JK1" is refused and "auto" takes
"JKn". "rwyb" reads every stage's probabilities and needs none of
these readings, and as_svydesign() gives the linearization variance.
Censuses
A stratum of a single stage taken whole keeps its full weight in every
replicate, so it adds no variance under any type. An unstratified census
gets two replicate columns at the full-sample weights under "JK1" and
"auto", so its variance is zero and it can be shared, stacked and
calibrated. When every row has the same weight the replicate matrix
stays uncompressed, and survey::calibrate() then needs
compress = FALSE (survey 4.5). A stratified census is refused under
"JKn" and "auto" (samplyr_error_svrep_conversion_failed), and
"bootstrap", "rwyb" and as_svydesign() give it a variance of zero.
Statistical details
Inside a PSU taken with certainty, the generic types resample the
stage-2 units of each stratum h of that PSU as drawn with replacement,
which leaves out stage 2's correction 1 - f_h. When stage 2 drew the
stratum with equal probabilities without replacement and no later stage
samples inside its units, the export replaces each replicate weight of
the stratum's rows by
$$w_k^{(r)*} = w_k + \sqrt{1 - f_h}\,\left(w_k^{(r)} - w_k\right),$$
where \(w_k\) is the full-sample weight and \(w_k^{(r)}\)
the weight in replicate r. This multiplies the stratum's contribution
to the variance of a linear estimator by 1 - f_h. For a total, the
jackknife and balanced types then give the without-replacement variance
of the stratum exactly, and the bootstrap types in expectation. One
factor serves every unit of the stratum, since the replicates contrast
those units with each other. A stratum with a unit sampled below it, or
a PPS stage 2, keeps the with-replacement reading, which tends to
overstate its contribution (samplyr_warning_replicate_certainty_stage_wr).
Rao-Wu-Yue-Beaumont bootstrap
type = "rwyb" supports SRS without replacement, independent draws with
replacement (srswr, pps_multinomial), independent Poisson selection
(bernoulli, pps_poisson), and combinations of these across stages.
Fixed-size PPS WOR (pps_brewer, pps_cps, pps_sampford,
pps_systematic) uses approximate joint probabilities, with a warning.
Equal-probability systematic stages use the SRS approximation governed by
systematic_variance. Custom methods must declare a supported variance
family. Balanced, spatial, Pareto, SPS and minimum-replacement methods
have no built-in RWYB mapping.
The adapter keeps stage-specific sampling units, strata and
probabilities. With-replacement stages resample draw occurrences, not
distinct population units. Certainty units have conditional replicate
factor one. Noncertainty singleton strata raise
samplyr_error_rwyb_singleton whenever their variance contribution is
needed, except under Poisson sampling, whose variance is estimable from
one unit, and at the final stage under lonely.psu = "certainty".
A selected unit with no descendant in the final sample is kept as a zero
row, because dropping it would change the earlier-stage resampling
distribution. This holds for a unit whose next register was empty and
for one in which a later Poisson stage selected nothing, which execution
records whatever frame_digest is, so estimates need na.rm = TRUE. A
sample that lacks that record is refused
(samplyr_error_rwyb_missing_parents). Empty samples cannot be
exported. With mse = TRUE the factors use scale 1 / replicates, and
with mse = FALSE they use 1 / (replicates - 1). The backend and stage
methods are recorded in the "samplyr_replication" attribute.
Random groups
type = "random_groups" takes a sample from execute(reps = R) as R
independent samples of the same design (Wolter 2007, ch. 2). The estimate
is the mean of the R replicate estimates, carried by the full-sample
weight .weight / R, and its variance is their spread divided by R, with
R - 1 degrees of freedom. A replicate that selected nothing counts as a
zero estimate. Nothing is assumed about the selection method, so the
route suits systematic, balanced, spatial or custom stages, which no
other type redraws. The cost is R samples.
The replicates must vary at every stage and phase. A sample that
continues one realized stage with reps, or replicates a later phase
over one realized first phase, is refused
(samplyr_error_random_groups_shared), because the shared selection's
variance would be left out. Replicate that stage or phase too, and
continue each replicate. A first phase fixed in one primary unit, every
stage taken for sure, such as the one unit of a one-unit population, has
no variance to leave out, and a later phase replicated over it is
accepted. A census of several primary units is not read as fixed. The sample must
hold every replicate of its
execution (samplyr_error_random_groups_input).
Variance by selection method
The generic types are refused for Poisson sampling, which needs
"rwyb". Bounded cube, LPM2 and SCPS have only the generic bootstrap of
"subbootstrap", and of "mrbbootstrap" when they are drawn with equal
probabilities, which does not recreate their constraints or spatial
algorithm. Only "random_groups" redraws a
systematic start. variance_estimation compares the estimators by
selection method.
References
Beaumont, J.-F. and Émond, N. (2022). A bootstrap variance estimation method for multistage sampling and two-phase sampling when Poisson sampling is used at the second phase. Stats, 5(2), 339-357. doi:10.3390/stats5020019
Canty, A. J. and Davison, A. C. (1999). Resampling-based variance estimation for labour force surveys. The Statistician, 48, 379-391.
Preston, J. (2009). Rescaled bootstrap for stratified multistage sampling. Survey Methodology, 35(2), 227-234.
Rao, J.N.K., Wu, C.F.J. and Yue, K. (1992). Some recent work on resampling methods for complex surveys. Survey Methodology, 18(2), 209-217.
Wolter, K. M. (2007). Introduction to Variance Estimation, 2nd ed. Springer.
See also
as_svydesign() for linearization export,
survey::as.svrepdesign() for the underlying conversion
Other survey export:
as_survey_design.tbl_sample(),
as_survey_rep.tbl_sample(),
as_svydesign(),
variance_estimators()
Examples
sample <- sampling_design() |>
stratify_by(region, alloc = "proportional") |>
draw(n = 300) |>
execute(bfa_eas, seed = 42)
rep_svy <- as_svrepdesign(sample, type = "auto")
survey::svymean(~households, rep_svy)
#> mean SE
#> households 71.668 3.6922
# The deterministic jackknife against linearization, and a seeded
# bootstrap with enough replicates for a stable second decimal.
survey::SE(survey::svytotal(~households, rep_svy))
#> [1] 164559.8
survey::SE(survey::svytotal(~households, as_svydesign(sample)))
#> households
#> households 164559.8
set.seed(1)
boot <- as_svrepdesign(sample, type = "bootstrap", replicates = 500)
#> Warning: Sampling fraction <1% in stratumBoucle du Mouhoun treated as zero.
#> Warning: Sampling fraction <1% in stratumCascades treated as zero.
#> Warning: Sampling fraction <1% in stratumCentre treated as zero.
#> Warning: Sampling fraction <1% in stratumCentre-Est treated as zero.
#> Warning: Sampling fraction <1% in stratumCentre-Nord treated as zero.
#> Warning: Sampling fraction <1% in stratumCentre-Ouest treated as zero.
#> Warning: Sampling fraction <1% in stratumCentre-Sud treated as zero.
#> Warning: Sampling fraction <1% in stratumEst treated as zero.
#> Warning: Sampling fraction <1% in stratumHauts-Bassins treated as zero.
#> Warning: Sampling fraction <1% in stratumNord treated as zero.
#> Warning: Sampling fraction <1% in stratumPlateau-Central treated as zero.
#> Warning: Sampling fraction <1% in stratumSahel treated as zero.
#> Warning: Sampling fraction <1% in stratumSud-Ouest treated as zero.
survey::SE(survey::svytotal(~households, boot))
#> [1] 174975.9
