Declare the Size and Features of the Population

declare_population(..., population_function = fabricate)

Arguments

...

Arguments to the population function

population_function

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.

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.589458 #> 2 002 5.804985 #> 3 003 5.154746 #> 4 004 5.306979 #> 5 005 3.868974 #> 6 006 7.185889
# 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 5.810576 #> 2 002 4.826766 #> 3 003 5.990076 #> 4 004 7.628853 #> 5 005 4.712629 #> 6 006 5.009555
# Custom population functions my_population_function <- function(N) { data.frame(u = rnorm(N)) } my_population_custom <- declare_population( population_function = my_population_function, N = 100) head(my_population_custom())
#> u #> 1 -0.6342080 #> 2 1.4568107 #> 3 0.9258306 #> 4 0.4850524 #> 5 -0.8024315 #> 6 -0.1914365