Evaluate a svyplan result at new parameter combinations. Returns a data frame with the varied parameters and resulting quantities, suitable for sensitivity analysis or plotting.
Arguments
- object
A svyplan object (
svyplan_n,svyplan_cluster,svyplan_power, orsvyplan_prec). Forsvyplan_prec, only types"proportion","mean", and"ratio"are supported. Types"cluster"and"multi"are not supported.- newdata
A data frame of parameter combinations to evaluate. Column names must be valid parameters for the object type (see Details). Parameters not in
newdatastay at their original values from the object.- ...
Additional arguments are not supported and produce an error.
Value
A data frame with newdata columns followed by result
columns. The result columns depend on the object type:
svyplan_n:n,se,moe,cv,rmoe, except for atype = "change"result, which reports one size per occasion asn1andn2in place ofn, and a joint constrained allocation, which reports the design and cost columns described under Detailssvyplan_cluster:n_psu,n_per_psu, (opt.n_per_ssu),total_n,cv,costsvyplan_power:n,power,effectsvyplan_prec:se,moe,cv,rmoe
Details
Valid parameters for newdata by object type:
n_prop:p,moe,rmoe,cv,alpha,N,deff,resp_rate,df,min_casesn_mean:var,mu,moe,rmoe,cv,alpha,N,deff,resp_rate,dfn_ratio:r,cv_num,cv_den,component_cor,moe,rmoe,cv,alpha,N,deff,resp_rate,dfn_change:moe,rmoe,cv,alpha,N,deff,resp_rate,ratio,overlap,overlap_cor, andchangeon the mean scale only, since two proportions determine it. The occasion variances are held at the values the result was built from, so vary the design rather than the estimand: sweepingoverlapandoverlap_coris what prices a rotation against a fresh sample each round.n_pooled:moe,rmoe,cv,alpha,N,deff,resp_rate,muon the mean scale, andoccasionsonly where the overlap and correlation are flat across lags, a shaped profile being a statement about a horizon that changing the horizon would contradict. The lag profiles themselves cannot be varied, a grid row having nowhere to hold a vector.n_cluster:cv,budget,unit_relvar,resp_rate,fixed_cost, stage deltas (iccoricc_psu, plusicc_ssufor 3-stage), stage ratios (var_ratioorvar_ratio_psu, plusvar_ratio_ssufor 3-stage), and stage costs (cost_psu,cost_ssu,cost_tsu). For 2-stage designs,cost_tsualiasescost_ssu.power_prop:p1,p2,n,power,alpha,N,deff,alternative,overlap,overlap_cor,resp_rate(excluding the solved-for parameter). Not supported for objects with vectorn.power_mean:effect,var,n,power,alpha,N,deff,alternative,overlap,overlap_cor,resp_rate(excluding the solved-for parameter). Not supported for objects with vectorn.prec_prop:p,n,alpha,N,deff,resp_rate,df. A result that solved forpvaries the target it solved from,cvorrmoe, in place ofp.prec_mean:var,n,mu,alpha,N,deff,resp_rate,df. A result that solved formuvariescvin place ofmu.prec_ratio:r,n,cv_num,cv_den,component_cor,alpha,N,deff,resp_rate,df
For svyplan_n objects, moe, rmoe, and cv are mutually exclusive
in newdata. If one appears, that mode is used. If none appears, the
original mode is preserved.
Similarly, for svyplan_cluster objects, cv and budget are
mutually exclusive.
Multi-indicator (n_multi) and multi-indicator cluster results are
not supported. Use the underlying single-indicator functions instead.
A joint constrained allocation (n_alloc() with measures and targets)
varies two controls, and each grid row re-solves the stored problem.
A fixed-budget objective fit varies budget, tracing the
cost-versus-objective frontier. A fixed-take multistage fit varies the
takes, n_per_psu for a two-stage design and either n_per_psu or
n_per_ssu for a three-stage one, tracing what the fieldwork decision
costs. A scalar take applies to every stratum, so the per-stratum takes the
fit was built from are replaced rather than scaled. Sweep them
asymmetrically by editing frame and calling n_alloc() per point. Both
controls may appear together on a budget-objective fit, one row per
combination.
The result reports the continuous n and cost, the operational n_int
and cost_int, and .feasible. A multistage fit adds the PSU counts
n_psu and n_psu_int, and budget mode adds objective_value, its
equivalent cv, and whether the budget binds. A row the solver cannot
satisfy, a budget too small to fund the hard targets or a take that exceeds
the stage populations, gives an all-NA row with .feasible = FALSE and a
warning, so one infeasible point does not discard the rest of the grid. A
take that is not a positive whole number is a malformed grid rather than an
infeasible design point, and stops.
A certainty-aware fit (n_alloc() with psu) varies n_per_psu too, even
though the solver saw a one-stage problem, and reports n_psu_certain and
n_psu_draw in place of the PSU counts. This is how the take is priced. It
also sets the certainty threshold, so a larger take leaves fewer certainty
PSUs and costs more sample, and the resulting cost curve has a minimum
worth finding rather than assuming.
Precision targets stay out of reach of the grid. A one-stage minimum-cost
fit therefore has nothing to vary. Modify targets and call n_alloc()
again.
If evaluation fails for a particular row (e.g. invalid parameter
combinations), that row's result columns are NA and a warning is
issued.
See also
plot.svyplan to draw a one-parameter grid, and confint.svyplan for the interval implied by a single result.
Examples
# Sensitivity of sample size to deff and response rate
x <- n_prop(p = 0.3, moe = 0.05, deff = 1.5)
predict(x, expand.grid(
deff = seq(1, 3, 0.5),
resp_rate = c(0.7, 0.8, 0.9)
))
#> deff resp_rate n se moe cv rmoe
#> 1 1.0 0.7 460.9751 0.02551067 0.05 0.08503558 0.1666667
#> 2 1.5 0.7 691.4626 0.02551067 0.05 0.08503558 0.1666667
#> 3 2.0 0.7 921.9501 0.02551067 0.05 0.08503558 0.1666667
#> 4 2.5 0.7 1152.4376 0.02551067 0.05 0.08503558 0.1666667
#> 5 3.0 0.7 1382.9252 0.02551067 0.05 0.08503558 0.1666667
#> 6 1.0 0.8 403.3532 0.02551067 0.05 0.08503558 0.1666667
#> 7 1.5 0.8 605.0298 0.02551067 0.05 0.08503558 0.1666667
#> 8 2.0 0.8 806.7064 0.02551067 0.05 0.08503558 0.1666667
#> 9 2.5 0.8 1008.3829 0.02551067 0.05 0.08503558 0.1666667
#> 10 3.0 0.8 1210.0595 0.02551067 0.05 0.08503558 0.1666667
#> 11 1.0 0.9 358.5362 0.02551067 0.05 0.08503558 0.1666667
#> 12 1.5 0.9 537.8042 0.02551067 0.05 0.08503558 0.1666667
#> 13 2.0 0.9 717.0723 0.02551067 0.05 0.08503558 0.1666667
#> 14 2.5 0.9 896.3404 0.02551067 0.05 0.08503558 0.1666667
#> 15 3.0 0.9 1075.6085 0.02551067 0.05 0.08503558 0.1666667
# Power curve: how does power vary with sample size?
pw <- power_prop(p1 = 0.30, p2 = 0.35, n = 500, power = NULL)
predict(pw, data.frame(n = seq(100, 1000, 100)))
#> n power effect
#> 1 100 0.1175929 0.05
#> 2 200 0.1877131 0.05
#> 3 300 0.2581732 0.05
#> 4 400 0.3272968 0.05
#> 5 500 0.3938436 0.05
#> 6 600 0.4569385 0.05
#> 7 700 0.5160053 0.05
#> 8 800 0.5707088 0.05
#> 9 900 0.6209032 0.05
#> 10 1000 0.6665884 0.05
# Cluster design: sensitivity to icc (homogeneity)
cl <- n_cluster(stage_cost = c(500, 50), icc = 0.05, budget = 100000)
predict(cl, data.frame(icc = c(0.01, 0.03, 0.05, 0.10, 0.15)))
#> icc n_psu n_per_psu total_n cv cost
#> 1 0.01 48.23430 31.464265 1517.6570 0.02931966 1e+05
#> 2 0.03 71.47587 17.981472 1285.2413 0.03427016 1e+05
#> 3 0.05 84.08997 13.784049 1159.1003 0.03760588 1e+05
#> 4 0.10 102.63340 9.486833 973.6660 0.04357388 1e+05
#> 5 0.15 114.10493 7.527727 858.9507 0.04800166 1e+05
# Allocation: how does the CV change with sample size?
frame <- data.frame(
N = c(4000, 3000, 3000),
sd = c(10, 15, 8),
mean = c(50, 60, 55)
)
alloc <- n_alloc(frame, n = 600)
predict(alloc, data.frame(n = seq(200, 1000, 200)))
#> n se moe cv cost
#> 1 200 0.7624828 1.4944388 0.013990510 200
#> 2 400 0.5332495 1.0451498 0.009784394 400
#> 3 600 0.4305191 0.8438019 0.007899432 600
#> 4 800 0.3685682 0.7223803 0.006762719 800
#> 5 1000 0.3257913 0.6385393 0.005977823 1000
# Two-stage joint allocation: what does the per-PSU take cost?
cluster_frame <- data.frame(
stratum = c("Urban", "Rural"),
N = c(60000, 40000),
N_psu = c(600, 500),
n_per_psu = c(10, 10),
cost_psu = c(400, 550),
cost_ssu = c(20, 25)
)
cluster_measures <- data.frame(
stratum = rep(cluster_frame$stratum, 2),
name = rep(c("literacy", "income"), each = 2),
p = c(0.62, 0.48, NA, NA),
mean = c(NA, NA, 520, 380),
sd = c(NA, NA, 210, 160),
icc_psu = rep(c(0.04, 0.07), 2)
)
cluster_targets <- data.frame(
name = c("literacy", "income"),
cv = c(0.03, 0.04)
)
joint <- n_alloc(cluster_frame, measures = cluster_measures,
targets = cluster_targets)
predict(joint, data.frame(n_per_psu = c(6, 10, 14, 20)))
#> n_per_psu n_psu n cost n_psu_int n_int cost_int .feasible
#> 1 6 175.97204 1055.832 103715.64 176 1056 103760 TRUE
#> 2 10 122.67192 1226.719 83273.41 123 1230 83400 TRUE
#> 3 14 99.75419 1396.559 76626.54 100 1400 76800 TRUE
#> 4 20 82.48407 1649.681 74400.37 83 1660 74900 TRUE