| setup {simFrame} | R Documentation |
Generic function for setting up multiple samples.
setup(x, control, ...) ## S4 method for signature 'data.frame, SampleControl': setup(x, control)
x |
the data to sample from. |
control |
a control object inheriting from the virtual class
"VirtualSampleControl" or a character string specifying such a
control class (the default being "SampleControl"). |
... |
if control is a character string or missing, the slots of
the control object may be supplied as additional arguments. |
The control class "SampleControl" is highly flexible and allows
stratified sampling as well as sampling of whole groups rather than
individuals with a specified sampling method. Hence it is often sufficient
to implement the desired sampling method for the simple non-stratified case
to extend the existing framework. See "SampleControl"
for some restrictions on the argument names of such a function, which should
return a vector containing the indices of the sampled observations.
Nevertheless, for very complex sampling procedures, it is possible to define
a control class "MySampleControl" extending
"VirtualSampleControl", and the corresponding method
setup(x, control) with signature 'data.frame, MySampleControl'.
In order to optimize computational performance, it is necessary to
efficiently set up multiple samples. Thereby the slot k of
"VirtualSampleControl" needs to be used to control the number of
samples, and the resulting object must be of class SampleSetup.
An object of class "SampleSetup".
Andreas Alfons, alfons@statistik.tuwien.ac.at
simSample, draw,
SampleControl, VirtualSampleControl,
SampleSetup
data(eusilc)
## simple random sampling
srss <- setup(eusilc, size = 20, k = 3)
draw(eusilc[, c("id", "eqIncome")], srss, i = 1)
## group sampling
gss <- setup(eusilc, group = "hid", size = 10, k = 3)
draw(eusilc[, c("hid", "id", "eqIncome")], gss, i = 2)
## stratified sampling
stss <- setup(eusilc, design = "region",
size = c(2, 5, 5, 3, 4, 5, 3, 5, 2), k = 3)
draw(eusilc[, c("id", "region", "eqIncome")], stss, i = 3)