Declare the Size and Features of the Population

declare_population(..., population_function = fabricatr::fabricate_data)

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_data 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 7.122286 #> 2 002 4.079349 #> 3 003 7.815917 #> 4 004 4.519523 #> 5 005 6.196260 #> 6 006 7.123799
# 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 7.024077 #> 2 002 6.361128 #> 3 003 7.626477 #> 4 004 5.579781 #> 5 005 3.527535 #> 6 006 6.966079
# 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.9455454 #> 2 2.1888964 #> 3 -2.1081467 #> 4 -2.4998123 #> 5 -0.3028554 #> 6 0.1868019