| Title: | Forecasting Models for Intermittent Time Series |
|---|---|
| Description: | Extends the 'fable' framework to support forecasting methods specifically designed for intermittent time series data, where demand occurs sporadically with many zero values. All methods produce probabilistic forecasts returned as 'distributional' objects. The returned forecasts can be used to evaluate accuracy, plot and print the results seamlessly with 'fable'. The methods include: Harvey, Fernandes (1989) <doi:10.1080/07350015.1989.10509750>, Willemain, Smart, Schwarz (2004) <doi:10.1016/S0169-2070(03)00013-X>, Zhou, Viswanathan (2011) <doi:10.1016/j.ijpe.2010.09.021>, Snyder, Ord, Beaumont (2012) <doi:10.1016/j.ijforecast.2011.03.009>, Kolassa (2016) <doi:10.1016/j.ijforecast.2015.12.004>, Hasni, Aguir, Babai, Jemai (2019) <doi:10.1080/00207543.2018.1424375>, Damato, Azzimonti, Corani (2025) <doi:10.1016/j.ijforecast.2025.10.001>, Sbrana (2025) <doi:10.1080/01605682.2025.2569661>. |
| Authors: | Stefano Damato [aut, cre, cph] (ORCID: <https://orcid.org/0009-0001-0225-3736>), Lorenzo Zambon [aut] (ORCID: <https://orcid.org/0000-0002-8939-993X>), Dario Azzimonti [aut] (ORCID: <https://orcid.org/0000-0001-5080-3061>) |
| Maintainer: | Stefano Damato <[email protected]> |
| License: | LGPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-06-18 14:12:40 UTC |
| Source: | https://github.com/cran/fable.intermittent |
A dataset of monthly demand for automotive spare parts. The data contains 3000 intermittent time series, each spanning 24 monthly periods from January 2010 to December 2011.
autoauto
A tsibble with 72,000 rows and 3 variables:
Character. Unique identifier for each time series.
Date (yearmonth). The monthly time index.
Numeric. The demand quantity for the given month.
Turkmen, A. C., Januschowski, T., Wang, Y., & Cemgil, A. T. (2021). Forecasting intermittent and sparse time series: A unified probabilistic framework via deep renewal processes. PLOS ONE, 16(11), e0259764.
Available at https://github.com/canerturkmen/gluon-ts/tree/intermittent-datasets/datasets.
library(tsibble) autolibrary(tsibble) auto
Conjugate Bayesian dynamic model for count time series with a negative
binomial observation distribution and a Beta prior on the success probability
parameter. This extends the conjugate updating framework of Harvey &
Fernandes (1989) to the Beta-Negative Binomial family. The Beta prior is
updated at each time step using a discount factor w. Forecasts are available
as samples simulating from the model forward in time.
BETANBB(formula, ...)BETANBB(formula, ...)
formula |
Model specification. |
... |
Not used. |
A model specification.
Harvey, A. C., & Fernandes, C. (1989). Time series models for count or qualitative observations. Journal of Business & Economic Statistics, 7(4), 407–417. doi:10.1080/07350015.1989.10509750.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(BETANBB(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(BETANBB(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }
Construct a Tweedie distribution object using the compound Poisson–Gamma
parameterisation with power parameter in . The Tweedie family
is a subclass of exponential dispersion models that naturally produces exact
zeros (via the Poisson count component) mixed with continuous positive
values (via the Gamma severity component), making it well suited to
intermittent demand data.
dist_tweedie(mean = 1, dispersion = 1, power = 1.5)dist_tweedie(mean = 1, dispersion = 1, power = 1.5)
mean |
Mean parameter |
dispersion |
Dispersion parameter |
power |
Power parameter |
The density is evaluated using the series expansion of Dunn & Smyth (2005), implemented in C++ for performance.
A distributional distribution object of class dist_tweedie.
Dunn, P. K., & Smyth, G. K. (2005). Series evaluation of Tweedie exponential dispersion model densities. Statistics and Computing, 15(4), 267–280. doi:10.1007/s11222-005-4070-y.
d <- dist_tweedie(mean = 2, dispersion = 0.8, power = 1.5) d |> mean() d |> quantile(c(0.5, 0.9)) d |> density(c(0, 1.5, 3)) d |> distributional::variance() d |> distributional::generate(10)d <- dist_tweedie(mean = 2, dispersion = 0.8, power = 1.5) d |> mean() d |> quantile(c(0.5, 0.9)) d |> density(c(0, 1.5, 3)) d |> distributional::variance() d |> distributional::generate(10)
Naive non-parametric baseline for intermittent demand forecasting. The predictive distribution at every horizon is simply the empirical distribution of the observed values: forecasts are produced by resampling with replacement from the historical series. Point forecasts are the sample mean.
EMPDISTR(formula, hot_start = FALSE, ...)EMPDISTR(formula, hot_start = FALSE, ...)
formula |
Model specification. |
hot_start |
Logical. If |
... |
Not used. |
A model specification.
Hasni, M., Aguir, M. S., Babai, M. Z., & Jemai, Z. (2019). Spare parts demand forecasting: a review on bootstrapping methods. International Journal of Production Research, 57(15–16), 4791–4804. doi:10.1080/00207543.2018.1424375.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(EMPDISTR(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(EMPDISTR(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }
Extract fitted values from a BETANBB model
## S3 method for class 'BETANBB' fitted(object, ...)## S3 method for class 'BETANBB' fitted(object, ...)
object |
A model for which fitted values are required. |
... |
Not used. |
A numeric vector of fitted values.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, BETANBB(value)) fitted(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, BETANBB(value)) fitted(fit)
Extract fitted values from an EMPDISTR model
## S3 method for class 'EMPDISTR' fitted(object, ...)## S3 method for class 'EMPDISTR' fitted(object, ...)
object |
A model for which fitted values are required. |
... |
Not used. |
A numeric vector of fitted values.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, EMPDISTR(value)) fitted(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, EMPDISTR(value)) fitted(fit)
Extract fitted values from a GAMPOISB model
## S3 method for class 'GAMPOISB' fitted(object, ...)## S3 method for class 'GAMPOISB' fitted(object, ...)
object |
A model for which fitted values are required. |
... |
Not used. |
A numeric vector of fitted values.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, GAMPOISB(value)) fitted(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, GAMPOISB(value)) fitted(fit)
Extract fitted values from a HSPES model
## S3 method for class 'HSPES' fitted(object, ...)## S3 method for class 'HSPES' fitted(object, ...)
object |
A model for which fitted values are required. |
... |
Not used. |
A numeric vector of fitted values.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, HSPES(value)) fitted(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, HSPES(value)) fitted(fit)
Extract fitted values from a MARWAL model
## S3 method for class 'MARWAL' fitted(object, ...)## S3 method for class 'MARWAL' fitted(object, ...)
object |
A model for which fitted values are required. |
... |
Not used. |
A numeric vector of fitted values.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, MARWAL(value)) fitted(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, MARWAL(value)) fitted(fit)
Extract fitted values from a NEGBINES model
## S3 method for class 'NEGBINES' fitted(object, ...)## S3 method for class 'NEGBINES' fitted(object, ...)
object |
A model for which fitted values are required. |
... |
Not used. |
A numeric vector of fitted values.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, NEGBINES(value)) fitted(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, NEGBINES(value)) fitted(fit)
Extract fitted values from a STATICDISTR model
## S3 method for class 'STATICDISTR' fitted(object, ...)## S3 method for class 'STATICDISTR' fitted(object, ...)
object |
A model for which fitted values are required. |
... |
Not used. |
A numeric vector of fitted values.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, STATICDISTR(value)) fitted(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, STATICDISTR(value)) fitted(fit)
Extract fitted values from a TWEES model
## S3 method for class 'TWEES' fitted(object, ...)## S3 method for class 'TWEES' fitted(object, ...)
object |
A model for which fitted values are required. |
... |
Not used. |
A numeric vector of fitted values.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, TWEES(value)) fitted(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, TWEES(value)) fitted(fit)
Extract fitted values from a VZ model
## S3 method for class 'VZ' fitted(object, ...)## S3 method for class 'VZ' fitted(object, ...)
object |
A model for which fitted values are required. |
... |
Not used. |
A numeric vector of fitted values.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, VZ(value)) fitted(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, VZ(value)) fitted(fit)
Extract fitted values from a WSS model
## S3 method for class 'WSS' fitted(object, ...)## S3 method for class 'WSS' fitted(object, ...)
object |
A model for which fitted values are required. |
... |
Not used. |
A numeric vector of fitted values.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, WSS(value)) fitted(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, WSS(value)) fitted(fit)
Produces forecast distributions from a fitted BETANBB model using simulation.
## S3 method for class 'BETANBB' forecast(object, new_data, specials = NULL, times = 10000, ...)## S3 method for class 'BETANBB' forecast(object, new_data, specials = NULL, times = 10000, ...)
object |
A model for which forecasts are required. |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
times |
The number of sample paths to use in estimating the forecast distribution. |
... |
Other arguments passed to methods |
A distribution vector of class dist_sample.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, BETANBB(value)) forecast(fit, h = "7 days")ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, BETANBB(value)) forecast(fit, h = "7 days")
Produces forecast distributions by repeating the empirical distribution estimated from the training data at each forecast horizon.
## S3 method for class 'EMPDISTR' forecast(object, new_data, specials = NULL, ...)## S3 method for class 'EMPDISTR' forecast(object, new_data, specials = NULL, ...)
object |
A model for which forecasts are required. |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A distribution vector of class dist_sample.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, EMPDISTR(value)) forecast(fit, h = "7 days")ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, EMPDISTR(value)) forecast(fit, h = "7 days")
Produces forecast distributions from a fitted GAMPOISB model using simulation.
## S3 method for class 'GAMPOISB' forecast(object, new_data, specials = NULL, times = 10000, ...)## S3 method for class 'GAMPOISB' forecast(object, new_data, specials = NULL, times = 10000, ...)
object |
A model for which forecasts are required. |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
times |
The number of sample paths to use in estimating the forecast distribution. |
... |
Other arguments passed to methods |
A distribution vector of forecasts: for h=1 the vector class is
dist_negative_binomial; for h>1 the vector class is dist_sample.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, GAMPOISB(value)) forecast(fit, h = "7 days")ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, GAMPOISB(value)) forecast(fit, h = "7 days")
Produces forecast distributions from a fitted HSPES model using simulation.
## S3 method for class 'HSPES' forecast(object, new_data, specials = NULL, times = 10000, ...)## S3 method for class 'HSPES' forecast(object, new_data, specials = NULL, times = 10000, ...)
object |
A model for which forecasts are required. |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
times |
The number of sample paths to use in estimating the forecast distribution. |
... |
Other arguments passed to methods |
A distribution vector of forecasts: for h=1 the vector class is
dist_inflated (hurdle-shifted Poisson); for h>1 the vector class is dist_sample.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, HSPES(value)) forecast(fit, h = "7 days")ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, HSPES(value)) forecast(fit, h = "7 days")
Produces forecast distributions from a fitted MARWAL model.
## S3 method for class 'MARWAL' forecast(object, new_data, specials = NULL, ...)## S3 method for class 'MARWAL' forecast(object, new_data, specials = NULL, ...)
object |
A model for which forecasts are required. |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A distribution vector of class dist_normal.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, MARWAL(value)) forecast(fit, h = "7 days")ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, MARWAL(value)) forecast(fit, h = "7 days")
Produces forecast distributions from a fitted NEGBINES model using simulation.
## S3 method for class 'NEGBINES' forecast(object, new_data, specials = NULL, times = 10000, ...)## S3 method for class 'NEGBINES' forecast(object, new_data, specials = NULL, times = 10000, ...)
object |
A model for which forecasts are required. |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
times |
The number of sample paths to use in estimating the forecast distribution. |
... |
Other arguments passed to methods |
A distribution vector of forecasts: for h=1 the vector class is
dist_negative_binomial; for h>1 the vector class is dist_sample.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, NEGBINES(value)) forecast(fit, h = "7 days")ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, NEGBINES(value)) forecast(fit, h = "7 days")
Produces forecast distributions from a fitted STATICDISTR model.
## S3 method for class 'STATICDISTR' forecast(object, new_data, specials = NULL, ...)## S3 method for class 'STATICDISTR' forecast(object, new_data, specials = NULL, ...)
object |
A model for which forecasts are required. |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A distribution vector. The class depends on the static distribution
fitted by the STATICDISTR method.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, STATICDISTR(value)) forecast(fit, h = "7 days")ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, STATICDISTR(value)) forecast(fit, h = "7 days")
Produces forecast distributions from a fitted TWEES model using simulation.
## S3 method for class 'TWEES' forecast(object, new_data, specials = NULL, times = 10000, ...)## S3 method for class 'TWEES' forecast(object, new_data, specials = NULL, times = 10000, ...)
object |
A model for which forecasts are required. |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
times |
The number of sample paths to use in estimating the forecast distribution. |
... |
Other arguments passed to methods |
A distribution vector of forecasts: for h=1 the vector class is
dist_tweedie; for h>1 the vector class is dist_sample.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, TWEES(value)) forecast(fit, h = "7 days")ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, TWEES(value)) forecast(fit, h = "7 days")
Produces forecast distributions from a fitted VZ model using simulation.
## S3 method for class 'VZ' forecast(object, new_data, specials = NULL, times = 10000, ...)## S3 method for class 'VZ' forecast(object, new_data, specials = NULL, times = 10000, ...)
object |
A model for which forecasts are required. |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
times |
The number of sample paths to use in estimating the forecast distribution. |
... |
Other arguments passed to methods |
A distribution vector of forecasts of class dist_sample.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, VZ(value)) forecast(fit, h = "7 days")ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, VZ(value)) forecast(fit, h = "7 days")
Produces forecast distributions from a fitted WSS model using simulation.
## S3 method for class 'WSS' forecast(object, new_data, specials = NULL, times = 10000, ...)## S3 method for class 'WSS' forecast(object, new_data, specials = NULL, times = 10000, ...)
object |
A model for which forecasts are required. |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
times |
The number of sample paths to use in estimating the forecast distribution. |
... |
Other arguments passed to methods |
A distribution vector of forecasts of class dist_sample.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, WSS(value)) forecast(fit, h = "7 days")ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, WSS(value)) forecast(fit, h = "7 days")
Conjugate Bayesian dynamic model for count time series with a Poisson
observation distribution and a Gamma prior on the rate parameter, following
Harvey & Fernandes (1989). The Gamma prior is updated at each time step
using a discount factor w that controls how quickly past information
decays. The first-step forecast follows a Negative Binomial distribution,
and multi-step forecasts are obtained by simulating from the model forward in time.
GAMPOISB(formula, ...)GAMPOISB(formula, ...)
formula |
Model specification. |
... |
Not used. |
A model specification.
Harvey, A. C., & Fernandes, C. (1989). Time series models for count or qualitative observations. Journal of Business & Economic Statistics, 7(4), 407–417. doi:10.1080/07350015.1989.10509750.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(GAMPOISB(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(GAMPOISB(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }
Generate sample paths from a BETANBB model
## S3 method for class 'BETANBB' generate(x, new_data, specials = NULL, ...)## S3 method for class 'BETANBB' generate(x, new_data, specials = NULL, ...)
x |
A fitted |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A vector of future paths from a dataset using a fitted model.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, BETANBB(value)) generate(fit, new_data = tsibble::new_data(ts, 7))ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, BETANBB(value)) generate(fit, new_data = tsibble::new_data(ts, 7))
Generate sample paths from an EMPDISTR model
## S3 method for class 'EMPDISTR' generate(x, new_data, specials = NULL, ...)## S3 method for class 'EMPDISTR' generate(x, new_data, specials = NULL, ...)
x |
A fitted |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A new_data tibble with a .sim column of simulated values.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, EMPDISTR(value)) generate(fit, h = 7)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, EMPDISTR(value)) generate(fit, h = 7)
Generate sample paths from a GAMPOISB model
## S3 method for class 'GAMPOISB' generate(x, new_data, specials = NULL, ...)## S3 method for class 'GAMPOISB' generate(x, new_data, specials = NULL, ...)
x |
A fitted |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A vector of future paths from a dataset using a fitted model.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, GAMPOISB(value)) generate(fit, new_data = tsibble::new_data(ts, 7))ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, GAMPOISB(value)) generate(fit, new_data = tsibble::new_data(ts, 7))
Generate sample paths from a HSPES model
## S3 method for class 'HSPES' generate(x, new_data, specials = NULL, ...)## S3 method for class 'HSPES' generate(x, new_data, specials = NULL, ...)
x |
A fitted |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A vector of future paths from a dataset using a fitted model.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, HSPES(value)) generate(fit, new_data = tsibble::new_data(ts, 7))ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, HSPES(value)) generate(fit, new_data = tsibble::new_data(ts, 7))
Generate sample paths from a MARWAL model
## S3 method for class 'MARWAL' generate(x, new_data, specials = NULL, ...)## S3 method for class 'MARWAL' generate(x, new_data, specials = NULL, ...)
x |
A fitted |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A vector of future paths from a dataset using a fitted model.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, MARWAL(value)) generate(fit, new_data = tsibble::new_data(ts, 7))ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, MARWAL(value)) generate(fit, new_data = tsibble::new_data(ts, 7))
Generate sample paths from a NEGBINES model
## S3 method for class 'NEGBINES' generate(x, new_data, specials = NULL, ...)## S3 method for class 'NEGBINES' generate(x, new_data, specials = NULL, ...)
x |
A fitted |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A vector of future paths from a dataset using a fitted model.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, NEGBINES(value)) generate(fit, new_data = tsibble::new_data(ts, 7))ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, NEGBINES(value)) generate(fit, new_data = tsibble::new_data(ts, 7))
Generate sample paths from a STATICDISTR model
## S3 method for class 'STATICDISTR' generate(x, new_data, specials = NULL, ...)## S3 method for class 'STATICDISTR' generate(x, new_data, specials = NULL, ...)
x |
A fitted |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A vector of future paths from a dataset using a fitted model.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, STATICDISTR(value)) generate(fit, new_data = tsibble::new_data(ts, 7))ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, STATICDISTR(value)) generate(fit, new_data = tsibble::new_data(ts, 7))
Generate sample paths from a TWEES model
## S3 method for class 'TWEES' generate(x, new_data, specials = NULL, ...)## S3 method for class 'TWEES' generate(x, new_data, specials = NULL, ...)
x |
A fitted |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A vector of future paths from a dataset using a fitted model.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, TWEES(value)) generate(fit, new_data = tsibble::new_data(ts, 7))ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, TWEES(value)) generate(fit, new_data = tsibble::new_data(ts, 7))
Generate sample paths from a VZ model
## S3 method for class 'VZ' generate(x, new_data, specials = NULL, ...)## S3 method for class 'VZ' generate(x, new_data, specials = NULL, ...)
x |
A fitted |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A vector of future paths from a dataset using a fitted model.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, VZ(value)) generate(fit, new_data = tsibble::new_data(ts, 7))ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, VZ(value)) generate(fit, new_data = tsibble::new_data(ts, 7))
Generate sample paths from a WSS model
## S3 method for class 'WSS' generate(x, new_data, specials = NULL, ...)## S3 method for class 'WSS' generate(x, new_data, specials = NULL, ...)
x |
A fitted |
new_data |
A tsibble containing future index values to forecast. |
specials |
Passed by |
... |
Other arguments passed to methods |
A vector of future paths from a dataset using a fitted model.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, WSS(value)) generate(fit, new_data = tsibble::new_data(ts, 7))ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, WSS(value)) generate(fit, new_data = tsibble::new_data(ts, 7))
Exponential smoothing state space model for intermittent demand with a hurdle-shifted Poisson observation distribution, following the framework of Snyder, Ord & Beaumont (2012). The model decomposes demand into two components: a Bernoulli occurrence process (probability of non-zero demand) and a shifted Poisson demand-size process. Both components are driven by independent (optionally damped) exponential smoothing state equations. The first-step forecast follows an hurdle-shifted Poisson distribution, multi-step forecasts are obtained by simulating from the model forward in time.
HSPES(formula, damped = TRUE, ...)HSPES(formula, damped = TRUE, ...)
formula |
Model specification. |
damped |
Logical. If |
... |
Not used. |
A model specification.
Snyder, R. D., Ord, J. K., & Beaumont, A. (2012). Forecasting the intermittent demand for slow-moving inventories: A modelling approach. International Journal of Forecasting, 28(2), 485–496. doi:10.1016/j.ijforecast.2011.03.009.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(HSPES(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(HSPES(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }
A Random Walk model on the demand composed by a switching constant and an ARMA model, where the changes are controlled by a Markov Chain on the occurrence process. Parameters are estimated in closed-form on deseasonalized data, and forecasts are returned as Gaussian distributions for each time step.
MARWAL(formula, ...)MARWAL(formula, ...)
formula |
Model specification. |
... |
Not used. |
A model specification.
Sbrana, G. (2025). Markov Walk and Walmart sales prediction. Journal of the Operational Research Society, 1–12. doi:10.1080/01605682.2025.2569661.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(MARWAL(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(MARWAL(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }
Return model name
## S3 method for class 'BETANBB' model_sum(x)## S3 method for class 'BETANBB' model_sum(x)
x |
A fitted |
The model name as a string
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, BETANBB(value)) model_sum(fit[[1]][[1]])ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, BETANBB(value)) model_sum(fit[[1]][[1]])
Return model name
## S3 method for class 'EMPDISTR' model_sum(x)## S3 method for class 'EMPDISTR' model_sum(x)
x |
A fitted |
The model name as a string
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, EMPDISTR(value)) model_sum(fit[[1]][[1]])ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, EMPDISTR(value)) model_sum(fit[[1]][[1]])
Return model name
## S3 method for class 'GAMPOISB' model_sum(x)## S3 method for class 'GAMPOISB' model_sum(x)
x |
A fitted |
The model name as a string
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, GAMPOISB(value)) model_sum(fit[[1]][[1]])ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, GAMPOISB(value)) model_sum(fit[[1]][[1]])
Return model name
## S3 method for class 'HSPES' model_sum(x)## S3 method for class 'HSPES' model_sum(x)
x |
A fitted |
The model name as a string
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, HSPES(value)) model_sum(fit[[1]][[1]])ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, HSPES(value)) model_sum(fit[[1]][[1]])
Return model name
## S3 method for class 'MARWAL' model_sum(x)## S3 method for class 'MARWAL' model_sum(x)
x |
A fitted |
The model name as a string
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, MARWAL(value)) model_sum(fit[[1]][[1]])ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, MARWAL(value)) model_sum(fit[[1]][[1]])
Return model name
## S3 method for class 'NEGBINES' model_sum(x)## S3 method for class 'NEGBINES' model_sum(x)
x |
A fitted |
The model name as a string
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, NEGBINES(value)) model_sum(fit[[1]][[1]])ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, NEGBINES(value)) model_sum(fit[[1]][[1]])
Return model name
## S3 method for class 'STATICDISTR' model_sum(x)## S3 method for class 'STATICDISTR' model_sum(x)
x |
A fitted |
The model name as a string
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, STATICDISTR(value)) model_sum(fit[[1]][[1]])ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, STATICDISTR(value)) model_sum(fit[[1]][[1]])
Return model name
## S3 method for class 'TWEES' model_sum(x)## S3 method for class 'TWEES' model_sum(x)
x |
A fitted |
The model name as a string
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, TWEES(value)) model_sum(fit[[1]][[1]])ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, TWEES(value)) model_sum(fit[[1]][[1]])
Return model name
## S3 method for class 'VZ' model_sum(x)## S3 method for class 'VZ' model_sum(x)
x |
A fitted |
The model name as a string
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, VZ(value)) model_sum(fit[[1]][[1]])ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, VZ(value)) model_sum(fit[[1]][[1]])
Return model name
## S3 method for class 'WSS' model_sum(x)## S3 method for class 'WSS' model_sum(x)
x |
A fitted |
The model name as a string
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, WSS(value)) model_sum(fit[[1]][[1]])ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, WSS(value)) model_sum(fit[[1]][[1]])
Exponential smoothing state space model for intermittent demand with a negative binomial observation distribution, as proposed by Snyder, Ord & Beaumont (2012). The conditional mean of the negative binomial is governed by a (optionally damped) exponential smoothing process. The probability parameter is estimated to maximise the likelihood. The first-step forecast follows a Negative Binomial distribution, and multi-step forecasts are obtained by simulating from the model forward in time.
NEGBINES(formula, damped = TRUE, ...)NEGBINES(formula, damped = TRUE, ...)
formula |
Model specification. |
damped |
Logical. If |
... |
Not used. |
A model specification.
Snyder, R. D., Ord, J. K., & Beaumont, A. (2012). Forecasting the intermittent demand for slow-moving inventories: A modelling approach. International Journal of Forecasting, 28(2), 485–496. doi:10.1016/j.ijforecast.2011.03.009.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(NEGBINES(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(NEGBINES(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }
A dataset of monthly demand for spare parts from the Royal Air Force (RAF). The data contains 5000 intermittent time series, each spanning 84 monthly periods from January 1996 to December 2002. This is a widely used benchmark dataset for intermittent demand forecasting.
rafraf
A tsibble with 420,000 rows and 3 variables:
Character. Unique identifier for each time series.
Date (yearmonth). The monthly time index.
Numeric. The demand quantity for the given month.
Syntetos, A. A., & Boylan, J. E. (2005). The accuracy of intermittent demand estimates. International Journal of Forecasting, 21(2), 303–314.
Available at https://github.com/canerturkmen/gluon-ts/tree/intermittent-datasets/datasets.
library(tsibble) raflibrary(tsibble) raf
Extract residuals from a BETANBB model
## S3 method for class 'BETANBB' residuals(object, ...)## S3 method for class 'BETANBB' residuals(object, ...)
object |
A model for which residuals are required. |
... |
Not used. |
A numeric vector of residuals.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, BETANBB(value)) residuals(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, BETANBB(value)) residuals(fit)
Extract residuals from an EMPDISTR model
## S3 method for class 'EMPDISTR' residuals(object, ...)## S3 method for class 'EMPDISTR' residuals(object, ...)
object |
A model for which residuals are required. |
... |
Not used. |
A numeric vector of residuals.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, EMPDISTR(value)) residuals(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, EMPDISTR(value)) residuals(fit)
Extract residuals from a GAMPOISB model
## S3 method for class 'GAMPOISB' residuals(object, ...)## S3 method for class 'GAMPOISB' residuals(object, ...)
object |
A model for which residuals are required. |
... |
Not used. |
A numeric vector of residuals.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, GAMPOISB(value)) residuals(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, GAMPOISB(value)) residuals(fit)
Extract residuals from a HSPES model
## S3 method for class 'HSPES' residuals(object, ...)## S3 method for class 'HSPES' residuals(object, ...)
object |
A model for which residuals are required. |
... |
Not used. |
A numeric vector of residuals.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, HSPES(value)) residuals(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, HSPES(value)) residuals(fit)
Extract residuals from a MARWAL model
## S3 method for class 'MARWAL' residuals(object, ...)## S3 method for class 'MARWAL' residuals(object, ...)
object |
A model for which residuals are required. |
... |
Not used. |
A numeric vector of residuals.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, MARWAL(value)) residuals(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, MARWAL(value)) residuals(fit)
Extract residuals from a NEGBINES model
## S3 method for class 'NEGBINES' residuals(object, ...)## S3 method for class 'NEGBINES' residuals(object, ...)
object |
A model for which residuals are required. |
... |
Not used. |
A numeric vector of residuals.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, NEGBINES(value)) residuals(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, NEGBINES(value)) residuals(fit)
Extract residuals from a STATICDISTR model
## S3 method for class 'STATICDISTR' residuals(object, ...)## S3 method for class 'STATICDISTR' residuals(object, ...)
object |
A model for which residuals are required. |
... |
Not used. |
A numeric vector of residuals.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, STATICDISTR(value)) residuals(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, STATICDISTR(value)) residuals(fit)
Extract residuals from a TWEES model
## S3 method for class 'TWEES' residuals(object, ...)## S3 method for class 'TWEES' residuals(object, ...)
object |
A model for which residuals are required. |
... |
Not used. |
A numeric vector of residuals.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, TWEES(value)) residuals(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, TWEES(value)) residuals(fit)
Extract residuals from a VZ model
## S3 method for class 'VZ' residuals(object, ...)## S3 method for class 'VZ' residuals(object, ...)
object |
A model for which residuals are required. |
... |
Not used. |
A numeric vector of residuals.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, VZ(value)) residuals(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, VZ(value)) residuals(fit)
Extract residuals from a WSS model
## S3 method for class 'WSS' residuals(object, ...)## S3 method for class 'WSS' residuals(object, ...)
object |
A model for which residuals are required. |
... |
Not used. |
A numeric vector of residuals.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, WSS(value)) residuals(fit)ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fit <- model(ts, WSS(value)) residuals(fit)
Static (IID) count distribution model for intermittent demand, following Kolassa (2016). The method fits several candidate distributions — Poisson, hurdle-shifted Poisson, negative binomial, and hurdle-shifted negative binomial — to the observed series and selects the best by AIC. A mixture option that blends all four predictive distributions is also available.
STATICDISTR( formula, distr = c("auto", "pois", "hsp", "nbinom", "hsnb", "mixture"), hot_start = FALSE, criterion = c("aic", "bic"), ... )STATICDISTR( formula, distr = c("auto", "pois", "hsp", "nbinom", "hsnb", "mixture"), hot_start = FALSE, criterion = c("aic", "bic"), ... )
formula |
Model specification. |
distr |
Distribution choice: one of |
hot_start |
Logical. If |
criterion |
Information criterion to use for model selection when |
... |
Not used. |
A model specification.
Kolassa, S. (2016). Evaluating predictive count data distributions in retail sales forecasting. International Journal of Forecasting, 32(3), 788–803. doi:10.1016/j.ijforecast.2015.12.004.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(STATICDISTR(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(STATICDISTR(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }
Density, distribution function, quantile function and random generation for
the Tweedie distribution with mean equal to mean, dispersion equal to
dispersion, and power equal to power.
rtweedie(n, mean = 1, dispersion = 1, power = 1.5) dtweedie(x, mean = 1, dispersion = 1, power = 1.5, log = FALSE) ptweedie( q, mean = 1, dispersion = 1, power = 1.5, lower.tail = TRUE, log.p = FALSE ) qtweedie( p, mean = 1, dispersion = 1, power = 1.5, lower.tail = TRUE, log.p = FALSE )rtweedie(n, mean = 1, dispersion = 1, power = 1.5) dtweedie(x, mean = 1, dispersion = 1, power = 1.5, log = FALSE) ptweedie( q, mean = 1, dispersion = 1, power = 1.5, lower.tail = TRUE, log.p = FALSE ) qtweedie( p, mean = 1, dispersion = 1, power = 1.5, lower.tail = TRUE, log.p = FALSE )
n |
number of observations. If |
mean |
vector of means. |
dispersion |
vector of dispersion parameters. |
power |
vector of power parameters. |
x, q
|
vector of quantiles. |
log, log.p
|
logical; if |
lower.tail |
logical; if |
p |
vector of probabilities. |
If mean, dispersion, or power are not specified they assume the
default values of 1, 1, and 1.5, respectively.
The Tweedie distribution used here follows the compound Poisson-Gamma
parameterisation with power parameter in . It has
and
, where is mean,
is dispersion, and is power.
dtweedie gives the density, ptweedie gives the distribution
function, qtweedie gives the quantile function, and rtweedie
generates random samples.
The length of the result is determined by n for rtweedie, and is the
maximum of the lengths of the numerical arguments for the other functions.
The numerical arguments other than n are recycled to the length of the
result. Only the first elements of the logical arguments are used.
Dunn, P. K., & Smyth, G. K. (2005). Series evaluation of Tweedie exponential dispersion model densities. Statistics and Computing, 15(4), 267–280. doi:10.1007/s11222-005-4070-y.
Exponential smoothing state space model for intermittent demand with a Tweedie observation distribution. The conditional mean of the Tweedie is governed by a (optionally damped) exponential smoothing process. The power and dispersion parameter are estimated to maximise the likelihood. The Tweedie family naturally models both zeros and large spikes via its compound Poisson-Gamma nature. The first-step forecast follows a Tweedie distribution, and multi-step forecasts are obtained by simulating from the model forward in time. The model parameters are estimated by
TWEES(formula, damped = TRUE, scaling = TRUE, ...)TWEES(formula, damped = TRUE, scaling = TRUE, ...)
formula |
Model specification. |
damped |
Logical. If |
scaling |
Logical. If |
... |
Not used. |
A model specification.
Damato, S., Azzimonti, D., & Corani, G. (2025). Forecasting intermittent time series with Gaussian Processes and Tweedie likelihood. International Journal of Forecasting (in press). doi:10.1016/j.ijforecast.2025.10.001.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(TWEES(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(TWEES(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }
Non-parametric bootstrap forecasting method for intermittent demand proposed by Zhou & Viswanathan (2011). The time series is decomposed into demand sizes and inter-demand intervals via Croston's decomposition. Forecasts are generated by independently resampling from the empirical distributions of both components, preserving the marginal structure of the original series.
VZ(formula, ...)VZ(formula, ...)
formula |
Model specification. |
... |
Not used. |
A model specification.
Zhou, Chenxi, Viswanathan, S., (2011). Comparison of a new bootstrapping method with parametric approaches for safety stock determination in service parts inventory systems. International Journal of Production Economics 133(1) 481–485. doi:10.1016/j.ijpe.2010.09.021
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(VZ(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(VZ(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }
Markov-chain bootstrap forecasting method for intermittent demand proposed by Willemain, Smart & Schwarz (2004). Occurrence of non-zero demand is modelled with a two-state Markov chain whose transition probabilities are estimated from the observed binary occurrence sequence. Demand sizes are resampled from past non-zero observations with Gaussian jittering to smooth the empirical distribution.
WSS(formula, ...)WSS(formula, ...)
formula |
Model specification. |
... |
Not used. |
A model specification.
Willemain, T. R., Smart, C. N., & Schwarz, H. F. (2004). A new approach to forecasting intermittent demand for service parts inventories. International Journal of Forecasting, 20(3), 375–387. doi:10.1016/S0169-2070(03)00013-X.
ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(WSS(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }ts <- tsibble::tsibble( time = as.Date("2026-01-01") + seq_len(40), value = rnbinom(40, size = 1, prob = 0.3), index = time ) fc_ts <- ts |> model(WSS(value)) |> forecast(h = "7 days") fc_ts |> print() if (requireNamespace("ggtime", quietly = TRUE)) { library(ggtime) fc_ts |> autoplot(ts) }