setup
with control class SampleControl
.simSample(x, design = character(), group = character(),
method = srs, size = NULL, prob = NULL, ..., k = 1)
data.frame
to sample from.srs
). It should return a vector containing the indices
of the sampled items (observations or groups).method
."SampleSetup"
.method
. 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 method
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
method
may be passed directly via the ...argument.setup
, SampleControl
,
SampleSetup
data(eusilc)
## simple random sampling
srss <- simSample(eusilc, size = 20, k = 3)
draw(eusilc[, c("id", "eqIncome")], srss, i = 1)
## group sampling
gss <- simSample(eusilc, group = "hid", size = 10, k = 3)
draw(eusilc[, c("hid", "id", "eqIncome")], gss, i = 2)
## stratified sampling
stss <- simSample(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