Generates a tibble of random demographic information for each individual in the simulation. The returned demography
tibble can be modified post-hoc to use user-specified distributions and values.
Arguments
- N
The number of individuals in the simulation
- times
A vector of each time step in the simulation
- birth_times
A vector of birth times for each individual; defaults to NULL; if
birth_times
is not specified then the function will simulate uniformly distributed birth times for each individual from the times vector- age_min
A number matching the time resolution of
times
giving the youngest age possible by the end of the simulation; defaults to 0 which means individuals can be born up until the penultimate time step- removal_min
The minimum age at which an individual can be removed from the population. Defaults to 0
- removal_max
The maximum age at which an individual can be removed from the population. Defaults to
max(times)
- prob_removal
The probability that an individual will be removed from the population during the simulation, representing e.g., death or study attrition. If set to
NA
, then removal time will bemax(times)+1
- aux
An optional list of lists describing additional demographic factors. Each list must contain the variable name, a vector of possible factor levels, and their proportions to simulate from. Note that this is intended for categorical, uncorrelated variables. More complex demographic information should be added post-hoc. Defaults to NULL.
Value
A tibble of relevant demographic information for each individual in the simulation is returned; this output matches the required demography
input for the runserosim
function.
See also
Other demography:
simulate_birth_times()
,
simulate_removal_times()
Examples
## Example 1 -- default
generate_pop_demography(10, times=1:120, age_min=0, removal_min=0,
removal_max=120, prob_removal=0.3)
#> removal_min is less than the first time step. Setting to min(times).
#>
#> Joining with `by = join_by(i)`
#> # A tibble: 1,200 × 4
#> i birth removal times
#> <int> <int> <dbl> <int>
#> 1 1 39 121 1
#> 2 1 39 121 2
#> 3 1 39 121 3
#> 4 1 39 121 4
#> 5 1 39 121 5
#> 6 1 39 121 6
#> 7 1 39 121 7
#> 8 1 39 121 8
#> 9 1 39 121 9
#> 10 1 39 121 10
#> # ℹ 1,190 more rows
## Example 2 -- specified birth times
birth_times <- rpois(100, 5)
generate_pop_demography(N=100, times=1:120, birth_times=birth_times,
age_min=0, removal_min=0, removal_max=120, prob_removal=0.3)
#> removal_min is less than the first time step. Setting to min(times).
#>
#> Joining with `by = join_by(i)`
#> # A tibble: 12,000 × 4
#> i birth removal times
#> <int> <int> <dbl> <int>
#> 1 1 10 13 1
#> 2 1 10 13 2
#> 3 1 10 13 3
#> 4 1 10 13 4
#> 5 1 10 13 5
#> 6 1 10 13 6
#> 7 1 10 13 7
#> 8 1 10 13 8
#> 9 1 10 13 9
#> 10 1 10 13 10
#> # ℹ 11,990 more rows
## Example 3 -- using auxiliary variables
aux <- list("Sex"=list("name"="sex","options"=c("male", "female"), "proportion"=c(0.5,0.5)),
"Group"=list("name"="group","options"=c(1, 2, 3, 4),
"proportion"=c(0.25,0.25,0.25,0.25)) )
generate_pop_demography(10, 1:120, age_min=0, removal_min=0, removal_max=120,
prob_removal=0.3, aux=aux)
#> removal_min is less than the first time step. Setting to min(times).
#>
#> Joining with `by = join_by(i)`
#> # A tibble: 1,200 × 6
#> i birth removal times sex group
#> <int> <int> <dbl> <int> <chr> <dbl>
#> 1 1 43 111 1 male 1
#> 2 1 43 111 2 male 1
#> 3 1 43 111 3 male 1
#> 4 1 43 111 4 male 1
#> 5 1 43 111 5 male 1
#> 6 1 43 111 6 male 1
#> 7 1 43 111 7 male 1
#> 8 1 43 111 8 male 1
#> 9 1 43 111 9 male 1
#> 10 1 43 111 10 male 1
#> # ℹ 1,190 more rows