Skip to contents

Builds the rolling-window SPI table for districts, or for a parent level such as the province. The SPI describes low relative AFP reporting: it compares the non-polio AFP cases each unit reported over the window with the number expected from spi_expected(), as an observed-to-expected ratio centred on the national ratio. The table also sets the NPAFP rate against its target. See spi_window_summary() for the window and how it differs from spi_index(), and spi_window_classify() for the classification.

Pass a fit, for example one the caller has cached, to skip the model. With no fit, the function builds the case panel with spi_case_panel() and the population panel with spi_pop_panel() over spi_panel_months(), and fits spi_expected() with its default model (harmonic season, iid year effect, negative binomial). Supplying cases also adds stool adequacy over the window from the adequate_stool column: rows with a blank value are left out and a value in adequate_values counts as adequate.

The defaults reproduce the weekly polio review pipeline for Afghanistan.

Usage

spi_rolling_index(
  fit = NULL,
  as_of,
  window_months = 12L,
  lag_months = 1L,
  start_year = 2016L,
  parents = NULL,
  cases = NULL,
  population = NULL,
  adjacency = NULL,
  districts = NULL,
  cols = list(),
  polio_pattern = "WPV|VDPV|COMPATIBLE",
  surveillance_types = "AFP",
  pop_year_col = "year",
  pop_col = "u15_pop",
  adequate_values = "Yes",
  person_time = "window",
  rate_target = 3,
  index_threshold = 0.8,
  min_expected = 1,
  rate_multiplier = 1e+05,
  annualise = FALSE,
  n_draws = 1000L,
  seed = 42L,
  ...
)

Arguments

fit

Optional spi_expected() result with draws kept. Default: NULL.

as_of

Date. The reporting date.

window_months, lag_months, start_year

See spi_window(). Defaults: 12, 1 and 2016.

parents

Optional two-column data frame mapping the district column to a parent unit. Default: NULL.

cases

Data frame of AFP cases. Needed to fit the model, and used for stool adequacy when given. Default: NULL.

population

Data frame of population estimates, needed to fit the model. See spi_pop_panel(). Default: NULL.

adjacency

District boundaries as an sf object, passed to spi_adjacency(), or an nb neighbour list. Needed to fit the model. Default: NULL.

districts

Character. District identifiers of the panel. Defaults to those of adjacency.

cols

Named list overriding the case column names; see spi_case_panel(). adequate_stool (default "adequate_stool_with_condition") is read for stool adequacy.

polio_pattern, surveillance_types

See spi_case_panel().

pop_year_col, pop_col

Year and population columns of population. Defaults: "year" and "u15_pop". The district column is cols$id.

adequate_values

Character. Values of the stool adequacy column that count as adequate. Default: "Yes".

person_time

See spi_window_summary(). Default: "window".

rate_target, index_threshold, min_expected, rate_multiplier, annualise

See spi_window_classify(). Defaults: 3, 0.8, 1, 100000 and FALSE.

n_draws, seed

Passed to spi_expected(). Defaults: 1000 and 42.

...

Further arguments passed to spi_expected().

Value

Tibble with one row per unit, the columns of spi_window_summary() and spi_window_classify(), and with cases also stool_cases, stool_adequate and stool_adequacy (percent). Sorted by spi_median.

See also

Other spi rolling window functions: spi_window_classify(), spi_window_summary()

Examples

if (FALSE) { # \dontrun{
rolling <- spi_rolling_index(
  as_of = Sys.Date(), cases = afp, population = pop,
  adjacency = boundaries
)
} # }