This generates based on predefined age groups and proportions, however you could also define these yourself.

gen_population(
  total_pop = 1000,
  groups = c("0-4", "5-14", "15-29", "30-44", "45+"),
  strata = c("Male", "Female"),
  proportions = c(0.079, 0.134, 0.139, 0.082, 0.066),
  counts = NULL,
  tibble = TRUE
)

Arguments

total_pop

The overal population count of interest - the default is 1000 people

groups

A character vector of groups - the default is set for age groups: c("0-4","5-14","15-29","30-44","45+")

strata

A character vector for stratifying groups - the default is set for gender: c("Male", "Female")

proportions

A numeric vector specifying the proportions (as decimals) for each group of the total_pop. The default repeats c(0.079, 0.134, 0.139, 0.082, 0.067) for strata. However you can change this manually, make sure to have the length equal to groups times strata (or half thereof). These defaults are based of MSF general emergency intervention standard values.

counts

A numeric vector specifying the counts for each group. The default is NULL - as most often proportions above will be used. If is not NULL then total_pop and proportions will be ignored. Make sure the length of this vector is equal to groups times strata (or if it is half then it will repeat for each strata). For reference, the MSF general emergency intervention standard values are c(7945, 13391, 13861, 8138, 6665) based on above groups for a 100,000 person population.

tibble

Return data as a tidyverse tibble (default is TRUE)

Examples

# get population counts based on proportion, unstratified
gen_population(groups = c(1, 2, 3, 4), 
               strata = NULL, 
               proportions = c(0.3, 0.2, 0.4, 0.1))
#> # A tibble: 4 × 3
#>   groups proportions     n
#>    <dbl>       <dbl> <dbl>
#> 1      1         0.3   300
#> 2      2         0.2   200
#> 3      3         0.4   400
#> 4      4         0.1   100

# get population counts based on proportion, stratified
gen_population(groups = c(1, 2, 3, 4), 
               strata = c("a", "b"), 
               proportions = c(0.3, 0.2, 0.4, 0.1))
#> Warning: Given proportions (or counts) is not the same as
#> groups multiplied by strata length, they will be repeated to match
#> Warning: The sum of given proportions is more than 5% away from 100% 
#> If the intention was to provide proportions by strata then ignore this message
#> # A tibble: 8 × 4
#>   groups strata proportions     n
#>    <dbl> <fct>        <dbl> <dbl>
#> 1      1 a              0.3   300
#> 2      2 a              0.2   200
#> 3      3 a              0.4   400
#> 4      4 a              0.1   100
#> 5      1 b              0.3   300
#> 6      2 b              0.2   200
#> 7      3 b              0.4   400
#> 8      4 b              0.1   100

# get population counts based on counts, unstratified
gen_population(groups = c(1, 2, 3, 4), 
               strata = NULL, 
               counts = c(20, 10, 30, 40))
#> # A tibble: 4 × 3
#>   groups proportions     n
#>    <dbl>       <dbl> <dbl>
#> 1      1         0.2    20
#> 2      2         0.1    10
#> 3      3         0.3    30
#> 4      4         0.4    40

# get population counts based on counts, stratified
gen_population(groups = c(1, 2, 3, 4), 
               strata = c("a", "b"), 
               counts = c(20, 10, 30, 40))
#> Warning: Given proportions (or counts) is not the same as
#> groups multiplied by strata length, they will be repeated to match
#> # A tibble: 8 × 4
#>   groups strata proportions     n
#>    <dbl> <fct>        <dbl> <dbl>
#> 1      1 a             0.1     20
#> 2      2 a             0.05    10
#> 3      3 a             0.15    30
#> 4      4 a             0.2     40
#> 5      1 b             0.1     20
#> 6      2 b             0.05    10
#> 7      3 b             0.15    30
#> 8      4 b             0.2     40

# get population counts based on counts, stratified - type out counts
# for each group and strata
gen_population(groups = c(1, 2, 3, 4), 
               strata = c("a", "b"), 
               counts = c(20, 10, 30, 40, 40, 30, 20, 20))
#> # A tibble: 8 × 4
#>   groups strata proportions     n
#>    <dbl> <fct>        <dbl> <dbl>
#> 1      1 a           0.0952    20
#> 2      2 a           0.0476    10
#> 3      3 a           0.143     30
#> 4      4 a           0.190     40
#> 5      1 b           0.190     40
#> 6      2 b           0.143     30
#> 7      3 b           0.0952    20
#> 8      4 b           0.0952    20