Display and coercion methods shared by every result the package returns.
print() gives the human-readable design, while as.integer(),
as.double(), and as.data.frame() extract it in the shapes a
downstream package can consume.
Usage
# S3 method for class 'svyplan_n'
print(x, ...)
# S3 method for class 'svyplan_cluster'
print(x, ...)
# S3 method for class 'svyplan_prec'
print(x, ...)
# S3 method for class 'svyplan_varcomp'
print(x, ...)
# S3 method for class 'svyplan_power'
print(x, ...)
# S3 method for class 'svyplan_n'
format(x, ...)
# S3 method for class 'svyplan_cluster'
format(x, ...)
# S3 method for class 'svyplan_prec'
format(x, ...)
# S3 method for class 'svyplan_varcomp'
format(x, ...)
# S3 method for class 'svyplan_power'
format(x, ...)
# S3 method for class 'svyplan_n'
as.integer(x, ...)
# S3 method for class 'svyplan_n'
as.double(x, ...)
# S3 method for class 'svyplan_cluster'
as.integer(x, ...)
# S3 method for class 'svyplan_cluster'
as.double(x, ...)
# S3 method for class 'svyplan_n'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
stringsAsFactors = FALSE,
validRN = TRUE,
...
)
# S3 method for class 'svyplan_prec'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
stringsAsFactors = FALSE,
validRN = TRUE,
...
)
# S3 method for class 'svyplan_varcomp'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
stringsAsFactors = FALSE,
validRN = TRUE,
...
)
# S3 method for class 'svyplan_cluster'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
stringsAsFactors = FALSE,
validRN = TRUE,
...
)
# S3 method for class 'svyplan_power'
as.integer(x, ...)
# S3 method for class 'svyplan_power'
as.double(x, ...)
# S3 method for class 'svyplan_power'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
stringsAsFactors = FALSE,
validRN = TRUE,
...
)
# S3 method for class 'svyplan_strata'
print(x, ...)
# S3 method for class 'svyplan_strata'
format(x, ...)
# S3 method for class 'svyplan_strata'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
stringsAsFactors = FALSE,
validRN = TRUE,
...
)
# S3 method for class 'svyplan_strata'
as.integer(x, ...)
# S3 method for class 'svyplan_strata'
as.double(x, ...)
# S3 method for class 'svyplan_twophase'
print(x, ...)Arguments
- x
A svyplan object.
- ...
Additional arguments are not supported and produce an error.
- row.names, optional
Standard
as.data.frame()arguments.- stringsAsFactors
Logical. Retained for compatibility when a result is converted through
data.frame().- validRN
Logical. Accepted for compatibility with
data.frame()in R 4.7.0 and later. Svyplan results already have valid row names.
Value
print() returns x invisibly. format() returns a character
vector, as.integer() and as.double() return numeric vectors, and
as.data.frame() returns a data frame; the shapes are described under
Details.
Details
Print and coercion
Constrained designs (n_cluster(), n_alloc(), n_multi_cluster())
carry two representations: the continuous mathematical
optimum in the top-level fields (n, cv, cost, ...) and the
whole-unit field design in $operational, whose cost and precision
are recomputed from the integer design. print() leads with the
field design and shows the continuous optimum as a diagnostic.
as.integer(x) returns the operational design in the same shape as
x$n: the named integer stage vector for svyplan_cluster objects,
the operational total for allocation results, and the ceiled scalar
otherwise. as.double(x) returns the continuous counterpart of the
same shape. For svyplan_strata, both coercions return the total sample
size. Boundary cutpoints remain available in $boundaries.
as.data.frame() returns the tabular form of a result, intended as
the stable handoff to downstream packages (e.g. samplyr). For
svyplan_n: the stratum allocation table ($detail) for
n_alloc() results, the per-domain table ($domains, falling back
to $detail) for n_multi() results, and a one-row summary
(n, n_int, se, moe, cv) otherwise. For svyplan_cluster:
the per-domain table when domains are present, otherwise a stage
table with columns stage, n, and n_int, where n is the continuous
optimum and n_int is the constraint-preserving operational design.
For svyplan_prec, detail-bearing multi-indicator and allocation results
return $detail. Single-indicator results return their sample size and
precision measures in one row. For svyplan_varcomp, stratified results
return $strata, while unstratified results return one row containing the
two- or three-stage components. For svyplan_power, one row contains the
two group sizes, their integer counterparts, power, effect, type, and the
quantity that was solved for.
See also
confint.svyplan for confidence intervals on a result.
Examples
# print leads with the operational (whole-unit) design
n_cluster(stage_cost = c(500, 50), icc = 0.05, cv = 0.05)
#> Optimal 2-stage allocation
#> field design: n_psu = 52 | n_per_psu = 12 -> total n = 624
#> cv = 0.0498, cost = 57200
#> continuous optimum: n_psu = 47.5681 | n_per_psu = 13.78405 (cv = 0.0500, cost = 56568)
#> design df = 51
# the tabular handoff to downstream packages
as.data.frame(n_prop(p = 0.3, moe = 0.05))
#> n n_int se moe cv
#> 1 322.6825 323 0.02551067 0.05 0.08503558