Skip to contents

Helper to create generic calendar regressors without relying on any country-specific datasets shipped with the package. This is deliberate: production holiday calendars should usually come from an authoritative institutional source, not from a generic package dataset.

Usage

build_user_xreg(
  y,
  td_candidates = NULL,
  holidays = NULL,
  frequency = NULL,
  td_usertype = "holiday",
  default_center = c("calendar", "mean", "none")
)

Arguments

y

A ts (or ts-boxable) target series used for alignment.

td_candidates

Optional named list of precomputed regressors (ts-boxable).

holidays

Optional list defining moving-holiday regressors. Each element may be:

  • a Date vector (holiday dates), or

  • a list with fields dates (Date), start (int), end (int), center (chr), name (chr) Windows are in days relative to the holiday date. Defaults: start=-7, end=0. Names on the holidays list are preserved when name is not supplied inside an element.

frequency

Optional frequency to use for holiday regressors (defaults to frequency(y)).

td_usertype

X-13 usertype label for all returned regressors (default "holiday").

default_center

Default centering for holiday regressors.

Value

A named list of ts regressors aligned to y. Attribute td_usertype is attached for downstream use.

Details

Supports:

  • Precomputed regressors (td_candidates): named list of ts-boxable series

  • Moving-holiday regressors (holidays): built via seasonal::genhol()

The output is directly consumable by auto_seasonal_analysis() via its td_candidates argument.

Examples

diwali_dates <- as.Date(c("2022-10-24", "2023-11-12", "2024-11-01"))
xreg <- build_user_xreg(
  y = AirPassengers,
  holidays = list(diwali = list(dates = diwali_dates, start = -1, end = 1)),
  td_usertype = "holiday"
)
names(xreg)
#> [1] "diwali"