Description Usage Arguments Details Value Author(s) See Also Examples
A convenience wrapper for setting up multiple samples using setup
with control class SampleControl
.
1 2 3 
x 
the 
design 
a character, logical or numeric vector specifying variables (columns) to be used for stratified sampling. 
grouping 
a character string, single integer or logical vector specifying a grouping variable (column) to be used for sampling whole groups rather than individual observations. 
collect 
logical; if a grouping variable is specified and this is

fun 
a function to be used for sampling (defaults to

size 
an optional nonnegative integer giving the number of items (observations or groups) to sample. For stratified sampling, a vector of nonnegative integers, each giving the number of items to sample from the corresponding stratum. 
prob 
an optional numeric vector giving the probability weights, or a character string or logical vector specifying a variable (column) that contains the probability weights. 
... 
additional arguments to be passed to 
k 
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 passed directly via the ... argument.
An object of class "SampleSetup"
.
Andreas Alfons
setup
, "SampleControl"
,
"SampleSetup"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  data(eusilcP)
## simple random sampling
srss < simSample(eusilcP, size = 20, k = 4)
summary(srss)
draw(eusilcP[, c("id", "eqIncome")], srss, i = 1)
## group sampling
gss < simSample(eusilcP, grouping = "hid", size = 10, k = 4)
summary(gss)
draw(eusilcP[, c("hid", "id", "eqIncome")], gss, i = 2)
## stratified simple random sampling
ssrss < simSample(eusilcP, design = "region",
size = c(2, 5, 5, 3, 4, 5, 3, 5, 2), k = 4)
summary(ssrss)
draw(eusilcP[, c("id", "region", "eqIncome")], ssrss, i = 3)
## stratified group sampling
sgss < simSample(eusilcP, design = "region",
grouping = "hid", size = c(2, 5, 5, 3, 4, 5, 3, 5, 2), k = 4)
summary(sgss)
draw(eusilcP[, c("hid", "id", "region", "eqIncome")], sgss, i = 4)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.