spi_pop_index() totals the under-15 population each year over the
districts that carry a positive population in every year requested, so a
denominator carried back in time is not compared against a changing set
of districts. spi_pop_panel() returns one denominator per district and
year. A district first drawn part way through the series has no
population for earlier years; those years take the district's first
population scaled by the index, or the first population unchanged where
the index is missing.
Usage
spi_pop_index(
population,
districts,
years,
id_col = "adm2_guid",
year_col = "year",
pop_col = "u15_pop"
)
spi_pop_panel(
population,
districts,
years,
id_col = "adm2_guid",
year_col = "year",
pop_col = "u15_pop"
)Arguments
- population
Data frame of population estimates. Rows for the same district and year are summed; missing and non-positive values are dropped.
- districts
Character. District identifiers the panel covers.
- years
Integer. Years the panel covers.
- id_col, year_col, pop_col
Character. Column names in
population. Defaults:"adm2_guid","year","u15_pop".
Value
spi_pop_index() returns a tibble with year and total.
spi_pop_panel() returns a tibble with the district column (named as
id_col), year, pop_u15 and a logical carried that is TRUE
where the value was carried back. Without carried, this is the
population input of spi_expected().
See also
Other spi preparation functions:
spi_case_date(),
spi_case_panel(),
spi_window()
Examples
pop <- tibble::tibble(
adm2_guid = c("D1", "D1", "D2"),
year = c(2023L, 2024L, 2024L),
u15_pop = c(100, 110, 50)
)
spi_pop_index(pop, c("D1", "D2"), 2023:2024)
#> # A tibble: 2 × 2
#> year total
#> <int> <dbl>
#> 1 2023 100
#> 2 2024 110
spi_pop_panel(pop, c("D1", "D2"), 2023:2024)
#> # A tibble: 4 × 4
#> adm2_guid year pop_u15 carried
#> <chr> <int> <dbl> <lgl>
#> 1 D1 2023 100 FALSE
#> 2 D1 2024 110 FALSE
#> 3 D2 2023 45.5 TRUE
#> 4 D2 2024 50 FALSE