Skip to contents

The running month carries few onsets at the reporting date and would read as a shortfall everywhere, so both month sets stop lag_months before the month that contains as_of. spi_window() returns the window_months months ending there. spi_panel_months() returns every month from January of start_year to the same last month, so the seasonal and spatial terms of spi_expected() are estimated on the full history rather than on the window.

Usage

spi_window(as_of, window_months = 12L, lag_months = 1L)

spi_panel_months(as_of, start_year = 2016L, lag_months = 1L)

Arguments

as_of

Date. The reporting date.

window_months

Integer. Length of the rolling window in months. Default: 12.

lag_months

Integer. Closed months between the window and the month that contains as_of. Default: 1, so the window ends with the last full month.

start_year

Integer. First year of the panel the model is fitted on. Default: 2016.

Value

Sorted Date vector of first-of-month dates.

See also

Other spi preparation functions: spi_case_date(), spi_case_panel(), spi_pop_index()

Examples

spi_window(as.Date("2025-03-15"))
#>  [1] "2024-03-01" "2024-04-01" "2024-05-01" "2024-06-01" "2024-07-01"
#>  [6] "2024-08-01" "2024-09-01" "2024-10-01" "2024-11-01" "2024-12-01"
#> [11] "2025-01-01" "2025-02-01"
range(spi_panel_months(as.Date("2025-03-15"), start_year = 2024))
#> [1] "2024-01-01" "2025-02-01"