declare_population: Declare the size and features of the population

Description Usage Arguments Value Examples

Description

Declare the size and features of the population

Usage

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

Arguments

...

arguments to be captured, and later passed to the handler

handler

a tidy-in, tidy-out function

label

a string describing the step

Value

A potential outcomes declaration, which is a function that returns a data.frame.

Examples

 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
36
37
38
39
40
41
42
# Declare a single-level population with no covariates
my_population <- declare_model(N = 100)

# Declare a population from existing data
my_population <- declare_model(sleep)

# Declare a single-level population with a covariate
my_population <- declare_model(
  N = 6,
  female = rbinom(n = N, 1, prob = 0.5),
  height_ft = rnorm(N, mean = 5.67 - 0.33 * female, sd = 0.25)
)


# Declare a population from existing data

declare_population(mtcars)

# Resample from existing data

declare_population(N = 100, data = mtcars, handler = resample_data)


# Declare a two-level hierarchical population
# containing cities within regions and a
# pollution variable defined at the city level

my_population <- declare_model(
  regions = add_level(N = 5),
  cities = add_level(N = 10, pollution = rnorm(N, mean = 5))
)

# Declare a population using a custom function

# the default handler is fabricatr::fabricate, 
# but you can supply any function that returns a data.frame

my_population_function <- function(N) {
  data.frame(u = rnorm(N))
}

my_population_custom <- declare_model(N = 10, handler = my_population_function)

DeclareDesign documentation built on Feb. 15, 2021, 1:07 a.m.