Description Usage Arguments Details See Also Examples
View source: R/03-sim_sample.R
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
).
1 | sim_sample(simSetup, smplFun = sample_number(size = 5L, groupVars = "idD"))
|
simSetup |
a |
smplFun |
function which controls the sampling process. |
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.
sample_number
, sample_fraction
1 2 3 4 5 6 7 8 9 10 11 12 | # 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.