Learn R Programming

simFrame (version 0.1.2)

setup: Set up multiple samples

Description

Generic function for setting up multiple samples.

Usage

setup(x, control, ...)

## S3 method for class 'data.frame,SampleControl': setup(x, control)

Arguments

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.

Value

  • An object of class "SampleSetup".

Details

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.

See Also

simSample, draw, SampleControl, VirtualSampleControl, SampleSetup

Examples

Run this code
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)

Run the code above in your browser using DataLab