validate_decomposition() creates a sample decomposition and errors from a dataset, a reference decomposition, and decomposition parameters. It is designed to be used as a mapping function passed to map() within cv_decomposition().

validate_decomposition(.i, .data, .ref, period, trend)

Arguments

.i

The index of the sample; all data up to this point will be used

.data

The data to sample

.ref

A reference decomposition used to calculate errors

period

The length of time to use in seasonal decomposition; can be a time-based definition (e.g. "1 week") or an integer number of days. If NULL or "auto", period is set automatically using the tunable heuristics in the timetk package.

trend

The length of time to use in trend decomposition; can be a time-based definition (e.g. "1 month") or an integer number of days. If NULL or "auto", trend is set automatically using the tunable heuristics in the timetk package.

Value

A tibble containing the time index of the data, as well as columns sample (an indicator of the sample to which the data belongs), horizon, observed, season, trend, remainder, season_error, trend_error, and remainder_error