sim_sample {saeSim} | R Documentation |
Sampling component
Description
One of the components which can be added to a sim_setup
. This component can be used to add a sampling mechanism to the simulation set-up. A sample will be drawn after the population is generated (sim_gen
) and variables on the population are computed (sim_comp_pop
).
Usage
sim_sample(simSetup, smplFun = sample_number(size = 5L, groupVars = "idD"))
Arguments
simSetup |
a |
smplFun |
function which controls the sampling process. |
Details
Potentially you can define a smplFun
yourself. Take care that it has one argument, named dat
being the data as data.frame, and returns the sample as data.frame.
See Also
sample_number
, sample_fraction
Examples
# Simple random sample - 5% sample:
sim_base_lm() %>% sim_sample(sample_fraction(0.05))
# Simple random sampling proportional to size - 5% in each domain:
sim_base_lm() %>% sim_sample(sample_fraction(0.05, groupVars = "idD"))
# User defined sampling function:
sample_mySampleFun <- function(dat) {
dat[sample.int(nrow(dat), 10), ]
}
sim_base_lm() %>% sim_sample(sample_mySampleFun)
[Package saeSim version 0.11.0 Index]