Changelog
Source:NEWS.md
svyplan 0.17.0
Initial CRAN release.
svyplan sizes survey samples and reports the precision a size buys. It reports stratum-level design quantities such as sizes, sampling fractions and base weights. It never draws a sample and never attaches selection probabilities or weights to units, which is the sampling stage’s work.
Single-stage size, precision and power functions accept deff, N and resp_rate and take a svyplan() profile as plan. Cluster functions take icc and stage costs in place of deff. Every n_ function has a prec_ counterpart, so passing a sized result to it reports the precision the design was sized for, and named ... overrides evaluate a variation of it. Results carry print(), summary(), format() and as.data.frame() methods, and confint(), plot() or predict() where those apply. Optimization results with a whole-unit recommendation keep it in $operational, separate from the continuous solution. Integer coercion uses that recommendation when available, or rounds the continuous size up.
Sample size determination
-
n_prop(),n_mean()andn_ratio()size a proportion, a mean, or a ratio of two totals observed on the same units. Targets aremoe,cv, orrmoe, a margin of error relative to the estimand. MICS uses relative margins of error, while DHS also describes precision using relative standard errors (cv). These targets differ by the confidence-level multiplier. - Proportions offer four intervals, Wald, Wilson, log-odds, and the Korn and Graubard (1998) beta. Each size inverts the half-width its
prec_prop()counterpart reports, so the four converge as the margin of error shrinks and separate only where the expected number of positive cases is small. -
min_casessizes a proportion against a minimum expected number of positive cases, the constraint that binds for a rare outcome in a small domain. Every proportion result reports theexpected_casesa design should yield. In an indicator table,min_respondentsfloors the eligible respondents a row needs, and a row may carry that floor alone, for an estimate whose precision is not modeled, such as the interviews with women a DHS asks of every domain. -
n_ratio()takes the quantities a pilot yields, the anticipated ratio with each component’s coefficient of variation and their correlation across units. A ratio’s design effect and homogeneity belong to the linearized variabley - r * xrather than to either component. -
n_cluster()allocates two- and three-stage cluster designs in budget and cv modes. Losses are named for the stage they act on,resp_rate_psu,resp_rate_ssu, andresp_rate, because a lost cluster and a lost ultimate unit move the cost-optimal take differently. Any stage size may be fixed, and the remaining stages solve that restricted problem.fpc = "stage"withNandN_psu, andN_ssuat three stages, corrects each component by its own stage’s sampling fraction, for one indicator or several. It moves the cost-optimal takes when PSUs or SSUs are small and caps the design at the population. Withdomains, each domain’s counts are columns ofindicators, separately or under one joint budget. With domains solved separately, abudgetapplies to each domain. -
eligible_per_unitsizes a sample of households for an estimate over the eligible persons they hold, an average number per household that may exceed one.n_prop(),prec_prop(),n_mean(),prec_mean(),n_cluster(),prec_cluster(), jointn_alloc()andprec_alloc(),power_prop(),power_mean(),power_did(), and the proportion and mean rows ofn_multi()andprec_multi()take it, each row with its own group. Sizes, bounds and costs stay in households, and the variance reads the eligible respondents out ofN * eligible_per_uniteligible persons. -
eligibility_rateis the share of issued units in scope, such as dwellings found occupied, andresp_ratethe response rate among them, as a survey report publishes it. Every function that takesresp_ratetakeseligibility_rate, except the two-phase pair. With a finiteNthe population in scope isN * eligibility_rate, andn_alloc()andprec_alloc()weight strata by it, with one rate per stratum from a vector or aframecolumn, a PSU register included. -
n_alloc()allocates a stratified sample from a frame of stratum sizes and variabilities, in fixed-n, target-cv, orbudgetmode, by proportional, Neyman, optimal, or Bankier power allocation. Anicc_psuframe column makes it a stratified two-stage design, wherefpcpicks between the ultimate-unit correction, the exact stage-by-stage one, and none. An element allocation takesfpc = "none"too, for a plan built on published design effects. Bankier allocation weights each stratum’s population CV by a size measure raised toalloc_q. The measure is the stratum totalN * abs(mean)unless a positivealloc_measureframe column supplies another. With that default measure,alloc_q = 1gives Neyman allocation. A frame withpand nosdorvartakes its variance fromp, as joint allocation does. Ann_stepcolumn makes each stratum’s whole size a multiple of its step, such as PSUs in sets of 12 for monthly fieldwork. Proportional and power allocation of a fixednneed only the stratum sizes, and then report no precision.min_n_stratumsets one floor for every stratum or one per stratum, as a vector or a frame column, andmin_n_domainone on each domain’s total, such as 400 households per province, held in the whole design.$detailcarries the frame’s character, factor and logical columns afterstratum. Withdomains, the target-cvmode gives each domain the smallest total that meets the target inside it, allocated there by the rule. The target-cvmode of optimal and Neyman allocation gives the cheapest whole allocation meeting the target, per domain withdomains, and without domains thebudgetmode of optimal allocation the smallest whole variance the budget buys, each found by a search undercontrol = list(max_nodes =, gap =). In cluster mode the search sets each stratum’s whole PSU count and, under optimal allocation with stage costs andN_psu, any take the frame leaves free, within the average PSU size. A fixed-ncluster design fields whole PSUs at a whole take near its cost-optimal value, or every PSU at a take risen pastN_psu. - Long
measuresandtargetstables request joint constrained allocation across indicators and overlapping domains. Withoutobjectivethe result is the cheapest design meeting every requirement, and withobjectiveandbudgetit is the best design that budget buys. A KKT-certified continuous optimum is reported separately from the whole-unit design, which a search proves the cheapest, or the best within the budget, undercontrol = list(max_nodes =, gap =). An element-level proportion measure uses the population varianceN * p * (1 - p) / (N - 1), so a one-stratum joint allocation equalsn_prop(). Multistage designs use the working variancep * (1 - p). Atargetsorobjectivetable with adomaincolumn and nolevelcolumn applies each row to every level of that domain. Aframecolumndefforresp_rateis the stratum default under themeasuresrows, as for the stage parameters, and indicator values inframeare refused. -
psugivesn_alloc()a PSU register, which separates the PSUs a PPS design would select with certainty and reports the take each fielded PSU carries. A stratum with a single PSU carries no between-PSU variance, so itsicc_psumay beNA.certainty_cutofftakes PSUs with certainty from an inclusion probability below one, for every stratum or per stratum.n_psu_per_zonecuts each stratum’s remainder into zones of about equal size and draws one or two PSUs from each. With two, every stratum’s variance can be estimated. With one,$psu$.pairgroups the zones for a collapsed variance. Without zones, a stratum that draws a single PSU from its remainder raises a warning of classsvyplan_single_draw. The field design is chosen whole. Each stratum’s designs are listed, under stage costs also those holding its largest PSUs in certainty below the threshold, and a search picks the cheapest meeting every target. It proves that design optimal, or stops aftercontrol$max_nodesnodes, or withincontrol$gapof a lower bound, and reports the gap. A design within 1e-6 of the bound reads"gap"rather than"limit". Withobjectiveandbudgetit picks the design with the smallest weighted relative variance whose field cost stays within the budget. Certainty visits are priced as a fixed cost, and the clustering reads the responding take.predict()on a register fit reports each row’s search status. Avar_ratio_psuother than 1 and a PSU-level response rate are refused with a register. A register PSU smaller than its take is refused, andmerge_psus()merges small PSUs with their neighbors in row order to a minimum size. -
n_multi()sizes a table of indicators, with optional per-domain sizing and amin_n_domainfloor.prec_multi()reports each row’s precision with its domain columns.n_cluster(indicators = )andprec_cluster(indicators = )take the same table for a multistage design, so a cluster argument never changes whatn_multi()returns. -
n_twophase()allocates a two-phase sample. One allocator covers double sampling for stratification and nonresponse follow-up, which differ only in which strata are markedtake_all. Every result prices the single-phase design that skips phase 1, since two-phase sampling is not always the better buy.assuranceconverts required respondents into an issue clearing a stated binomial probability.$operationalis the cheapest whole design meeting a cv target, or the most precise a budget buys, found by search over both phases. -
n_change()andn_pooled()size an occasion of a repeated survey, for a change between two occasions and for an estimate pooled across several. Precision comes from the product ofoverlapandoverlap_cor, so a full panel of uncorrelated measurements saves nothing.overlap_drawsays how the shared units are drawn, as a fixed count with the rest of the sample, the rotating-panel case, or as a retained panel topped up on each occasion by a fresh sample drawn independently from the whole frame. The two differ only in the finite population terms, and the second pools two occasions. -
n_panel()sizes the recruitment a panel needs to still deliver a required responding sample after several waves of attrition. It embeds ann_mean(),n_prop(),prec_mean(), orprec_prop()result rather than restating its arguments. A fixed panel reportsn_issued, and a rotating onen_entrantsper occasion beside then_in_sampleits live cohorts hold between them.startreports what a rotating design delivers while it climbs to its steady state, andassuranceagain converts an expected-value recruitment into an assured one. -
design_schedule()turns a rotating launch into a versioned, package-neutral operational manifest, validated field by field, for a sampling package to field.
Precision analysis
- Each
n_*function has aprec_*counterpart reportingse,moe,cv, andrmoefor a size already chosen, namelyprec_prop(),prec_mean(),prec_ratio(),prec_cluster(),prec_alloc(),prec_multi(),prec_twophase(),prec_change(),prec_pooled(), andprec_panel(). -
prec_prop()andprec_mean()also solve the remaining direction. Supplyingcvorrmoein place of the level returns the smallest estimand the design measures that precisely, which is the planning form of a publication threshold. -
prec_alloc()reports at three levels, the population overall, each stratum in$detailwith its share of the design variance, and each domain in$domains, using the same tablen_alloc()returns so a design and its assessment compare row for row. For a cluster allocation,n_per_psusets the take, so the whole-unit counts and whole take of$operationalreproduce its precision exactly. -
predict()sweeps a precision result over the inputs innewdata. On aprec_alloc()result a number innrescales the stratum sizes to that total and keeps their shares, and a list columnncompares candidate allocations row by row. Onprec_change()the occasions vary together throughnor apart throughn1andn2.
Power analysis
-
power_prop()andpower_mean()solve a two-sample test for sample size, power, or minimum detectable effect, with unequal group sizes and variances, an allocation ratio, a two-sided or one-sidedalternative, and arcsine and log-odds transforms. -
power_did()covers difference-in-differences, parametrized bytreatandcontrolbaseline and endline pairs, for proportion and mean outcomes. - All three accept panel overlap between the two occasions of a repeated survey, with the same
overlap_drawasn_change(). Bernoulli outcomes use the same finite-population variance as the precision family on every scale, Wald, arcsine, and log-odds alike, and correlations between repeated Bernoulli outcomes are restricted to the attainable Frechet-Hoeffding range. - Solved sample sizes are at least two units per group and report the power achieved at that size. A requested power used to solve a size or minimum detectable effect must exceed
alpha, the power at zero effect, and two-sided solutions include both rejection tails. A design that enumerates its population has no minimum detectable effect and says so.
Stratification
-
strata_bound()builds candidate boundaries for a continuous stratification variable by cumulative root frequency, geometric progression, LH coordinate optimization, or Kozak’s random search, under the same four allocation methodsn_alloc()offers.$stratamatches then_alloc()frame contract, so the table can be handed straight on. With acvtarget, Neyman and optimal allocation give the smallest or cheapest whole allocation meeting it at the chosen boundaries, at least two units a sampled stratum, which a search proves and$searchreports. - Bounded allocation satisfies the requested total together with minimum, maximum, and take-all constraints. Boundary searches reserve the census take correctly, including the full-population scaling of a target CV.
-
predict()applies fitted boundaries to new data, returning a factor.
Design components
-
varcomp()estimates the between- and within-PSU relvariance components of a frame or a sample, with methods for formulas, numeric vectors, andsurvey::svydesignobjects. PSUs, and at three stages SSUs, may be drawn by simple random sampling or proportional to size, and the result records which, sincevar_ratio_ssudepends on it when SSU sizes vary. Withoutprobthe between-PSU term is the simple random sampling one at two and three stages, so the stage-by-stage correction reproduces the variance of equal-size units drawn without replacement exactly. Weights are read as inverse inclusion probabilities, so a previous round’s unequal-probability sample gives approximately design-unbiased components. At three stages the stage-2 and stage-3 weights can be given as two columns, which the element-stage correction needs when much of each SSU is sampled.varcomp(deff = )backs aniccout of a published design effect instead. Its page explains squaring a published DEFT and removing the weighting loss it carries.estimator = "ratio"returns the components of the ratio estimator of a mean, which with PSUs of unequal size drawn with equal probability are smaller than those of the default expansion estimator. -
design_effect()builds the design effect a planned design should produce from clustering, unequal weighting, and stratification components, reading them off a plan where one is supplied. It anticipates a design effect from design parameters and does not estimate a realized one from collected data, which issurvey::svymean(deff = TRUE). Read off a cluster result it uses the takes that respond, as thecvdoes, and off an allocation from stratum sizes alone it gives Kish’s weighting loss. -
effective_n()mirrors it, returningn * resp_rate / deff. -
design_df()counts the degrees of freedom a planned design’s variance estimator will have, the planning analogue ofsurvey::degf(), with additive per-stratum and non-additive per-domain detail. For an allocation,method = "satterthwaite"weights the strata by their shares of the planned variance instead. A zoned PSU register counts its zones, or its collapsed zone groups at one PSU per zone, whose per-stratum counts need not add up when a group joins strata.dfswitches the interval quantile from the normal totin every function that builds an interval. -
design_rotation()declares the occasions a unit spends in and out of sample over its whole life, from a compact spec in either notation the literature uses or from an explicit per-occasion take. It is the objectdesign_overlap()anddesign_schedule()both read, so a pattern is parsed in one place. -
design_overlap()reports the issued-sample overlap that rotation produces at every lag, and withwindowthe mean number of occasions a unit is in sample within that many consecutive occasions.plot()draws the rotation chart the design would be published as.
Survey plan profiles
-
svyplan()captures shared design defaults such asdeff,N,resp_rate,eligible_per_unit, stage-specific response rates,df,alpha,stage_cost, andunit_cost, validated at construction. Pass it asplan = planor pipe withplan |> n_prop(...). Explicit arguments override a profile, andupdate()revises one.
Naming
- Argument names say what a quantity is rather than reproducing one textbook’s symbol.
iccis the design-based measure of homogeneity within clusters,var_ratiothe ratio of a stage component’s unit variance to the analysis variable’s, andunit_relvarthe unit relvariance.?svyplan-packagecarries the full symbol map. - Stage sizes distinguish counts from takes,
n_psuagainstn_per_psuandn_per_ssu. Sample-size floors are named for what they count,min_n_domainagainstmin_n_stratum. Cluster functions cost stages throughstage_costand stratified ones cost strata throughunit_cost. - Wherever a mean is planned, dispersion is given as
varorsd, and exactly one of the two.
Validation
- Arguments a configuration cannot use are rejected rather than silently discarded, whether passed by name or through
..., so a misspelling raises an error instead of computing under an unintended default. Optional arguments sit after...and must be fully named. - Targets requiring more than
Nunits, sizes above a frame, out-of-range rates and correlations, non-whole counts, and stage parameters a design does not have are all refused where they are supplied, rather than surfacing later as an optimizer failure or an infinite precision. - Infeasibility is reported with the binding quantity named. A joint allocation distinguishes targets unattainable at the stratum bounds, targets attainable but unaffordable, and the absence of a whole-unit design meeting every target inside the budget.
S3 classes
-
svyplanfor a design profile,svyplan_nandsvyplan_precfor sizes and precision,svyplan_clusterfor multistage allocations,svyplan_twophase,svyplan_panelandsvyplan_schedulefor the longitudinal family,svyplan_power,svyplan_strata,svyplan_varcomp,svyplan_deff,svyplan_df, andsvyplan_overlap. - All classes have
print()andformat()methods.print()reports the answer and the design behind it, andsummary()carries the derived detail, the assumptions, and the diagnostics. -
svyplan_deff,svyplan_df, andsvyplan_overlapare usable as the plain numbers they stand for while carrying the decomposition each was built from.