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_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, ...)
# S3 method for class 'svyplan_n'
print(x, ...)
# S3 method for class 'svyplan_alloc'
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_alloc'
format(x, ...)
# S3 method for class 'svyplan_cluster'
format(x, ...)
# S3 method for class 'svyplan_prec'
format(x, ...)
# S3 method for class 'svyplan_twophase'
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_alloc'
as.integer(x, ...)
# S3 method for class 'svyplan_alloc'
as.double(x, ...)
# S3 method for class 'svyplan_alloc'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
stringsAsFactors = FALSE,
validRN = TRUE,
...
)
# 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_twophase'
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'
summary(object, ...)
# S3 method for class 'svyplan_power'
summary(object, ...)
# S3 method for class 'svyplan_strata'
summary(object, ...)
# S3 method for class 'svyplan_varcomp'
summary(object, ...)
# S3 method for class 'svyplan_overlap'
summary(object, ...)
# S3 method for class 'svyplan_rotation'
summary(object, ...)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.- object
A svyplan object, for
summary().
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. summary() of a size or a cluster design is described in
summary.svyplan_n. A result type with no structured summary yet
returns itself from summary(), so it prints as print() does.
Details
Print and coercion
Constrained designs (n_cluster(), n_alloc())
carry two representations: the continuous design 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() shows the field design. For n_cluster() the
continuous optimum is read in summary() (see summary.svyplan_n). For
n_alloc() the print also shows the allocation rule's continuous design
as a diagnostic, which a two-stage frame with a finite population
correction can improve on (see n_alloc()).
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, the sum of the ceiled
quotas for n_multi() with separate domain quotas, and the ceiled scalar
otherwise. A count past R's integer range has no integer form, and
as.integer(x) then stops with an error of class svyplan_count_range.
x$operational$n keeps such a field count as a double. 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. 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, rmoe) otherwise, with an occasion
column and one row per occasion for a two-occasion n_change(). 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: stage_1 = 52 | stage_2 = 12 -> total n = 624
#> cv = 0.0498, cost = 57200
#> design df = 51
#> # summary() for the continuous optimum, the design effect and costs
# the tabular handoff to downstream packages
as.data.frame(n_prop(p = 0.3, moe = 0.05))
#> n n_int se moe cv rmoe
#> 1 322.6825 323 0.02551067 0.05 0.08503558 0.1666667