draw: Draw a sample

Description Usage Arguments Value Methods Author(s) References See Also Examples

Description

Generic function for drawing a sample.

Usage

1
2
3
4
5
6
7
draw(x, setup, ...)

## S4 method for signature 'data.frame,SampleSetup'
draw(x, setup, i = 1)

## S4 method for signature 'data.frame,VirtualSampleControl'
draw(x, setup)

Arguments

x

the data to sample from.

setup

an object of class "SampleSetup" containing previously set up samples, a control object inheriting from the virtual class "VirtualSampleControl" or a character string specifying such a control class (the default being "SampleControl").

i

an integer specifying which one of the previously set up samples should be drawn.

...

if setup is a character string or missing, the slots of the control object may be supplied as additional arguments. See "SampleControl" for details on the slots.

Value

A data.frame containing the sampled observations. In addition, the column ".weight", which consists of the sample weights, is added to the data.frame.

Methods

x = "data.frame", setup = "character"

draw a sample using a control class specified by the character string setup. The slots of the control object may be supplied as additional arguments.

x = "data.frame", setup = "missing"

draw a sample using a control object of class "SampleControl". Its slots may be supplied as additional arguments.

x = "data.frame", setup = "SampleSetup"

draw a previously set up sample.

x = "data.frame", setup = "VirtualSampleControl"

draw a sample using a control object inheriting from the virtual class "VirtualSampleControl".

Author(s)

Andreas Alfons

References

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.

See Also

setup, "SampleSetup", "SampleControl", "TwoStageControl", "VirtualSampleControl"

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## load data
data(eusilcP)

## simple random sampling
draw(eusilcP[, c("id", "eqIncome")], size = 20)

## group sampling
draw(eusilcP[, c("hid", "id", "eqIncome")],
    grouping = "hid", size = 10)

## stratified simple random sampling
draw(eusilcP[, c("id", "region", "eqIncome")],
    design = "region", size = c(2, 5, 5, 3, 4, 5, 3, 5, 2))

## stratified group sampling
draw(eusilcP[, c("hid", "id", "region", "eqIncome")],
    design = "region", grouping = "hid",
    size = c(2, 5, 5, 3, 4, 5, 3, 5, 2))

simFrame documentation built on Oct. 14, 2021, 5:24 p.m.