Description Usage Arguments Value Examples
Declare the size and features of the population
1 | declare_population(..., handler = fabricate, label = NULL)
|
... |
arguments to be captured, and later passed to the handler |
handler |
a tidy-in, tidy-out function |
label |
a string describing the step |
A function that returns a data.frame.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | # Default handler is fabricatr::fabricate
# Declare a single-level population with no covariates
my_population <- declare_population(N = 100)
# Declare a population from existing data
my_population <- declare_population(sleep)
# Declare a single-level population with a covariate
my_population <- declare_population(
N = 6,
gender = draw_binary(N, prob = 0.5),
height_ft = rnorm(N, mean = 5 + 4/12 + 4/12 * gender, sd = 3/12)
)
my_population()
# Declare a two-level hierarchical population
# containing cities within regions and a
# pollution variable defined at the city level
my_population <- declare_population(
regions = add_level(N = 5),
cities = add_level(N = 10, pollution = rnorm(N, mean = 5))
)
my_population()
# Declare a population using a custom function
my_population_function <- function(N) {
data.frame(u = rnorm(N))
}
my_population_custom <- declare_population(N = 10, handler = my_population_function)
my_population_custom()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.