Declare the Size and Features of the Population

declare_population(..., handler = fabricate, label = NULL)

Arguments

...

Arguments to the population function

handler

A function that generates a data.frame containing features of the population. By default, the fabricatr function fabricate function is used, which allows you to draw single or multi-level hierarchical population data.

label

a step label

Value

a function that returns a data.frame

Examples

# Declare a single-level population with no covariates my_population <- declare_population(N = 100) head(my_population())
#> ID #> 1 001 #> 2 002 #> 3 003 #> 4 004 #> 5 005 #> 6 006
# Declare a single-level population with a covariate my_population <- declare_population( N = 100, height_ft = runif(N, 3.5, 8) ) head(my_population())
#> ID height_ft #> 1 001 4.541163 #> 2 002 5.541377 #> 3 003 5.251368 #> 4 004 6.432244 #> 5 005 5.487036 #> 6 006 5.307416
# Declare a two-level hierarchical population # containing cities within regions pop <- declare_population( regions = level(N = 5), cities = level(N = 10, pollution = rnorm(N, mean = 5))) head(my_population())
#> ID height_ft #> 1 001 4.784681 #> 2 002 6.894644 #> 3 003 5.042305 #> 4 004 3.531256 #> 5 005 4.855222 #> 6 006 3.734016
# Custom population functions my_population_function <- function(N) { data.frame(u = rnorm(N)) } my_population_custom <- declare_population( handler = my_population_function, N = 100) head(my_population_custom())
#> u #> 1 -2.0197586 #> 2 0.2559044 #> 3 0.3904464 #> 4 -0.8311341 #> 5 0.5195553 #> 6 -0.8455217