sim_sample: Sampling component

Description Usage Arguments Details See Also Examples

View source: R/03-sim_sample.R

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

1
sim_sample(simSetup, smplFun = sample_number(size = 5L, groupVars = "idD"))

Arguments

simSetup

a sim_setup.

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

 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)

saeSim documentation built on Feb. 7, 2022, 5:07 p.m.