| tsb | R Documentation |
The Teunter-Syntetos-Babai (TSB) method for intermittent demand time series, with fixed or optimised smoothing parameters and initial values.
tsb(
data,
h = 10,
w = NULL,
init = c("mean", "naive"),
cost = c("mar", "msr", "mae", "mse", "msce", "mace"),
init.opt = c(TRUE, FALSE),
outplot = c(FALSE, TRUE),
opt.on = c(FALSE, TRUE),
na.rm = c(FALSE, TRUE),
probs = NULL,
qtype = 7,
model = NULL
)
data |
Intermittent demand time series. This can be a vector, a |
h |
Forecast horizon. When |
w |
Smoothing parameters. If |
init |
Initial values for demand and demand probability. This can be:
If |
cost |
Cost function used for optimisation: |
init.opt |
If |
outplot |
Plot of the forecast: |
opt.on |
This was meant to be used only by the optimisation of earlier versions
of the package. When |
na.rm |
If |
probs |
Probabilities of the quantiles of the demand over the lead time
|
qtype |
Type of empirical quantile calculation, passed to
|
model |
A model previously fitted with this function. Its smoothing
parameters, initial values, variant, and cost function are used, without
optimisation, to produce forecasts for |
TSB replaces the intervals of Croston's method with the probability of demand, which is updated in every period, while the non-zero demand is updated only when demand occurs. The forecast is the product of the two, a demand rate, and is constant over the horizon. As the probability is updated in every period, TSB reacts to items that stop being demanded. When the parameters are optimised, the smoothing parameter of the demand probability is kept no larger than that of the non-zero demand, following Teunter, Syntetos, and Babai (2011).
An object of class tsint, which is a list containing:
model |
Type of model fitted. |
frc.in |
In-sample demand rate. |
frc.out |
Out-of-sample demand rate. |
weights |
Smoothing parameters for demand and demand probability. |
initial |
Initialisation values for demand and demand probability smoothing. |
lt |
Only when |
fit.info |
Information used by the methods of the object, such as the series, the forecast from the end of the sample, and the cost function. Not intended for direct use. |
The object can be used with print, summary, plot, coef,
fitted, and forecast.
Conventional cost functions compare the forecast with the demand of each period. For intermittent demand this favours forecasts close to zero, and compares a demand rate with realised demand, which are not of the same nature. The package offers alternatives that compare like with like.
"mar" and "msr" compare the in-sample demand rate with the
cumulative mean of the series up to each period (Kourentzes, 2014). The cumulative
mean is winsorised over the first 30% of the sample, where it is based on few
observations. These are the recommended cost functions.
"msce" and "mace" use the cumulative forecast errors over
h periods from every in-sample origin, the same errors used for the lead time
quantiles. They need h of at least 1, and the optimised parameters
depend on h. Cost functions on multiple steps ahead errors shrink the
smoothing parameters towards zero, more strongly for longer horizons, and the
shrinkage can become excessive when the sample is short and the horizon is long
(Svetunkov, Kourentzes, and Killick, 2024). Use them with lead times that are small
relative to the length of the series.
"mse" and "mae" are the conventional cost functions. "mae"
is not recommended for intermittent demand, as it is particularly prone to favouring
forecasts close to zero.
The forecasts are demand rates, so a predictive distribution for the demand of a
single period is not meaningful. What is meaningful, and what matters for stock
control, is the cumulative demand over the lead time. When probs is provided,
h is understood as the lead time. More precisely, h should be the period
the stock decision must cover: the lead time under continuous review, or the lead time
plus the review period (the protection interval) under periodic review.
The cumulative errors over h periods are calculated from every in-sample
origin, and their empirical quantiles are added to the cumulative forecast over the
next h periods. The forecast errors at different steps ahead are correlated,
and the empirical distribution of the cumulative errors includes these covariances
without assuming a model for the demand (Saoud, Kourentzes, and Boylan, 2022). Reading
the quantiles directly from this distribution also avoids assuming a distribution for
the errors.
The resulting quantile is the stock needed to cover the demand over the lead time with the requested probability, i.e., the order-up-to level under periodic review or the reorder point under continuous review. The safety stock is the part of it above the cumulative forecast. Since demand cannot be negative, quantiles are truncated at zero. Probabilities below 0.5 are permitted, but are of little use in this setting: they result in negative safety stock and describe the lower tail of the demand over the lead time, which is not relevant to stock control.
The empirical quantiles are only as reliable as the number of cumulative errors
behind them, and a warning is given when there are fewer than 1/(1-max(probs)).
A fitted model can be applied to new data with model, for example when new
observations become available, without optimising the parameters again. The
smoothing parameters, initial values, variant, and cost function of the model are
used, and any of these inputs given in the call are ignored, except init.opt.
By default the initial values are not optimised, which is appropriate when
data extends the series the model was fitted to, as both start at the same
period. To apply the parameters of the model to a different series, use
init.opt=TRUE, so that the initial values are optimised for data,
while the smoothing parameters are kept fixed. The same is available with
forecast.tsint.
Nikolaos Kourentzes, nikolaos@kourentzes.com
The references for the cost functions and the lead time quantiles are given in
crost.
Teunter, R. H., Syntetos, A. A., and Babai, M. Z. (2011). Intermittent demand: linking forecasting to inventory obsolescence. European Journal of Operational Research, 214(3), 606–615.
Kourentzes, N. (2014). On intermittent demand model optimisation and selection. International Journal of Production Economics, 156, 180–190. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.ijpe.2014.06.007")}
crost, sexsm, plot.tsint.
# TSB with optimised parameters and initial values
fit <- tsb(ts.data1, outplot=TRUE)
fit$weights
# Different cost function
tsb(ts.data1, cost="msr")$weights
# Fixed parameters for the demand and the demand probability
tsb(ts.data1, w=c(0.2,0.05))$initial
# Fixed parameters and initial values
tsb(ts.data1, w=c(0.2,0.05), init=c(4,0.3), init.opt=FALSE)$frc.out
# Reuse the fitted model on an updated series
fit <- tsb(window(ts.data1, end=c(1985,12)))
tsb(ts.data1, model=fit)$frc.out
# Quantiles of the demand over a lead time of 4 periods
fit <- tsb(ts.data1, h=4, probs=c(0.9,0.95), outplot="leadtime")
fit$lt$quantile
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.