Description Objects from the Class Slots Details Extends Accessor and mutator methods Methods UML class diagram Note Author(s) References See Also Examples
Class for controlling the setup of samples.
Objects can be created by calls of the form new("SampleControl", ...)
or SampleControl(...).
design:Object of class "BasicVector" specifying
variables (columns) to be used for stratified sampling.
grouping:Object of class "BasicVector" specifying a
grouping variable (column) to be used for sampling whole groups rather
than individual observations.
collect:Object of class "logical"; if a grouping
variable is specified and this is FALSE (which is the default
value), groups are sampled directly. If grouping variable is specified
and this is TRUE, individuals are sampled in a first step. In a
second step, all individuals that belong to the same group as any of the
sampled individuals are collected and added to the sample. If no
grouping variable is specified, this is ignored.
fun:Object of class "function" to be used for
sampling (defaults to srs). It should return a vector
containing the indices of the sampled items (observations or groups).
size:Object of class "OptNumeric"; an optional
non-negative integer giving the number of items (observations or groups)
to sample. In case of stratified sampling, a vector of non-negative
integers, each giving the number of items to sample from the
corresponding stratum, may be supplied.
prob:Object of class "OptBasicVector"; an optional
numeric vector giving the probability weights, or a character string or
logical vector specifying a variable (column) that contains the
probability weights.
dots:Object of class "list" containing additional
arguments to be passed to fun.
k:Object of class "numeric"; a single positive
integer giving the number of samples to be set up.
There are some restrictions on the argument names of the function
supplied to fun. If it needs population data as input,
the corresponding argument should be called x and should expect
a data.frame. If the sampling method only needs the population size
as input, the argument should be called N. Note that fun is
not expected to have both x and N as arguments, and that the
latter is much faster for stratified sampling or group sampling.
Furthermore, if the function has arguments for sample size and probability
weights, they should be called size and prob, respectively.
Note that a function with prob as its only argument is perfectly valid
(for probability proportional to size sampling). Further arguments of
fun may be supplied as a list via the slot dots.
Class "VirtualSampleControl", directly.
Class "OptSampleControl", by class "VirtualSampleControl", distance 2.
In addition to the accessor and mutator methods for the slots inherited from
"VirtualSampleControl", the following are available:
getDesignsignature(x = "SampleControl"): get slot
design.
setDesignsignature(x = "SampleControl"): set slot
design.
getGroupingsignature(x = "SampleControl"): get slot
grouping.
setGroupingsignature(x = "SampleControl"): set slot
grouping.
getCollectsignature(x = "SampleControl"): get slot
collect.
setCollectsignature(x = "SampleControl"): set slot
collect.
getFunsignature(x = "SampleControl"): get slot
fun.
setFunsignature(x = "SampleControl"): set slot
fun.
getSizesignature(x = "SampleControl"): get slot
size.
setSizesignature(x = "SampleControl"): set slot
size.
getProbsignature(x = "SampleControl"): get slot
prob.
setProbsignature(x = "SampleControl"): set slot
prob.
getDotssignature(x = "SampleControl"): get slot
dots.
setDotssignature(x = "SampleControl"): set slot
dots.
In addition to the methods inherited from
"VirtualSampleControl", the following are available:
clusterSetupsignature(cl = "ANY", x = "data.frame",
control = "SampleControl"): set up multiple samples on a cluster.
setupsignature(x = "data.frame",
control = "SampleControl"): set up multiple samples.
showsignature(object = "SampleControl"): print the
object on the R console.
A slightly simplified UML class diagram of the framework can be found in
Figure 1 of the package vignette An Object-Oriented Framework for
Statistical Simulation: The R Package simFrame. Use
vignette("simFrame-intro") to view this vignette.
The slots grouping and fun were named group and
method, respectively, prior to version 0.2. Renaming the slots was
necessary since accessor and mutator functions were introduced in this
version and functions named getGroup, getMethod and
setMethod already exist.
Andreas Alfons
Alfons, A., Templ, M. and Filzmoser, P. (2010) An Object-Oriented Framework for Statistical Simulation: The R Package simFrame. Journal of Statistical Software, 37(3), 1–36. doi: 10.18637/jss.v037.i03.
"VirtualSampleControl",
"TwoStageControl", "SampleSetup",
setup, draw
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | data(eusilcP)
## simple random sampling
srsc <- SampleControl(size = 20)
draw(eusilcP[, c("id", "eqIncome")], srsc)
## group sampling
gsc <- SampleControl(grouping = "hid", size = 10)
draw(eusilcP[, c("hid", "hid", "eqIncome")], gsc)
## stratified simple random sampling
ssrsc <- SampleControl(design = "region",
size = c(2, 5, 5, 3, 4, 5, 3, 5, 2))
draw(eusilcP[, c("id", "region", "eqIncome")], ssrsc)
## stratified group sampling
sgsc <- SampleControl(design = "region", grouping = "hid",
size = c(2, 5, 5, 3, 4, 5, 3, 5, 2))
draw(eusilcP[, c("hid", "id", "region", "eqIncome")], sgsc)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.