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 6.2 #> 2 002 6.6 #> 3 003 4.8 #> 4 004 5.0 #> 5 005 7.4 #> 6 006 5.4
# 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 3.6 #> 2 002 4.8 #> 3 003 4.2 #> 4 004 6.8 #> 5 005 5.5 #> 6 006 6.2
# 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 -1.01 #> 2 0.22 #> 3 -0.64 #> 4 0.74 #> 5 -0.20 #> 6 0.71