tsb: TSB method

View source: R/tsb.R

tsbR Documentation

TSB method

Description

The Teunter-Syntetos-Babai (TSB) method for intermittent demand time series, with fixed or optimised smoothing parameters and initial values.

Usage

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
)

Arguments

data

Intermittent demand time series. This can be a vector, a ts object, or a data frame, in which case only the first column is used.

h

Forecast horizon. When probs is provided, h is understood as the lead time. See the section "Lead time quantiles".

w

Smoothing parameters. If w == NULL then the parameters are optimised. Otherwise, a vector of two values: the first is the smoothing parameter for the non-zero demand and the second for the demand probability.

init

Initial values for demand and demand probability. This can be:

  • c(z,p): a vector of two scalars, where the first is the initial demand and the second is the initial demand probability;

  • "naive": the initial demand is the first non-zero demand and the initial demand probability is that of the first period;

  • "mean": same as "naive", but the initial demand probability is the mean of all in-sample probabilities.

If init.opt == TRUE, these are the starting values of the optimisation.

cost

Cost function used for optimisation: "mar" for the mean absolute rate, "msr" for the mean squared rate, "mae" for the mean absolute error, "mse" for the mean squared error, "msce" for the mean squared cumulative error, and "mace" for the mean absolute cumulative error. See the section "Cost functions".

init.opt

If TRUE, the initial values are optimised.

outplot

Plot of the forecast: FALSE for no plot, TRUE or "period" for the per-period view, and "leadtime" for the lead time view. Both views, with additional options, are available afterwards with plot.tsint.

opt.on

This was meant to be used only by the optimisation of earlier versions of the package. When TRUE, no optimisation and no checks on the inputs are performed. This argument is deprecated and will be removed in a future version of the package.

na.rm

If TRUE, NA values are removed before modelling.

probs

Probabilities of the quantiles of the demand over the lead time h, for example c(0.9,0.95). If NULL, no quantiles are calculated. See the section "Lead time quantiles".

qtype

Type of empirical quantile calculation, passed to quantile.

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 data. See the section "Reusing a fitted model".

Details

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).

Value

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 probs is provided. See crost.

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.

Cost functions

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.

Lead time quantiles

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)).

Reusing a fitted model

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.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

References

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")}

See Also

crost, sexsm, plot.tsint.

Examples

# 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


tsintermittent documentation built on Nov. 14, 2026, 5:06 p.m.