crost: Croston's method and variants

View source: R/crost.R

crostR Documentation

Croston's method and variants

Description

Croston's method and its variants, the Syntetos-Boylan approximation (SBA) and the Shale-Boylan-Johnston correction (SBJ), for intermittent demand time series, with fixed or optimised smoothing parameters and initial values.

Usage

crost(
  data,
  h = 10,
  w = NULL,
  init = c("mean", "naive"),
  nop = c(2, 1),
  type = c("croston", "sba", "sbj"),
  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. If w is a single parameter, then the same is used for smoothing both the demand and the intervals. If two parameters are provided, then the second is used to smooth the intervals.

init

Initial values for demand and intervals. This can be:

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

  • "naive": the initial demand is the first non-zero demand and the initial interval is the first interval;

  • "mean": same as "naive", but the initial interval is the mean of all in-sample intervals.

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

nop

Number of model parameters, used only if they are optimised. 1 uses the same parameter for the demand and the intervals, while 2 uses separate parameters. There is no reason to expect the demand and the intervals to change at the same rate, so 2 is recommended.

type

Croston's method variant: "croston" for Croston's method, "sba" for the Syntetos-Boylan approximation, and "sbj" for the Shale-Boylan-Johnston correction.

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

The forecasts of Croston's method and its variants are demand rates: the average demand per period, rather than the demand expected in each period. For example, a forecast of 0.5 implies one unit of demand every two periods. The forecast is constant over the horizon.

Croston's method updates the non-zero demand and interval estimates only in periods with demand, so the in-sample forecast frc.in is NA up to and including the period of the first demand.

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

initial

Initialisation values for demand and interval smoothing.

components

List of c.in and c.out containing the non-zero demand and interval vectors for in- and out-of-sample respectively. The third element is the coefficient used to scale the demand rate for "sba" and "sbj".

lt

Only when probs is provided. A list with the lead time h, the probabilities probs, the cumulative forecast over the lead time frc, the quantiles of the demand over the lead time quantile, the safety stock ss, the in-sample cumulative errors errors, their origins origin, their number n, and the quantile type qtype. See lt.dist for details.

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

Optimisation of the methods and the MAR and MSR cost functions: 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")}

Shrinkage of multiple steps ahead cost functions: Svetunkov, I., Kourentzes, N., and Killick, R. (2024). Multi-step estimators and shrinkage effect in time series models. Computational Statistics, 39(3), 1203–1239. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/s00180-023-01377-x")}

Cumulative errors for the lead time distribution: Saoud, P., Kourentzes, N., and Boylan, J. E. (2022). Approximations for the lead time variance: A forecasting and inventory evaluation. Omega, 110, 102614. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.omega.2022.102614")}

See Also

tsb, sexsm, crost.ma, imapa, plot.tsint, lt.dist.

Examples

# Croston's method with optimised parameters and initial values
fit <- crost(ts.data1)
fit
summary(fit)

# SBA with a plot of the forecast
crost(ts.data1, type="sba", outplot=TRUE)

# Same parameter for demand and intervals
crost(ts.data1, type="sba", nop=1)$weights

# Different cost functions
crost(ts.data1, type="sba", cost="msr")$weights
crost(ts.data1, type="sba", cost="mse")$weights

# Fixed smoothing parameters, with optimised initial values
crost(ts.data1, w=c(0.1,0.05))$initial

# Fixed smoothing parameters and initial values
crost(ts.data1, w=c(0.1,0.05), init=c(5,3), init.opt=FALSE)$frc.out

# Initial values as the first demand and interval, not optimised
crost(ts.data1, w=0.1, init="naive", init.opt=FALSE)$initial

# Quantiles of the demand over a lead time of 3 periods
fit <- crost(ts.data1, h=3, type="sba", probs=c(0.9,0.95))
fit$lt$quantile  # Order-up-to level or reorder point
fit$lt$ss        # Safety stock
plot(fit, view="leadtime")

# Optimise on the cumulative errors over the lead time
crost(ts.data1, h=3, type="sba", cost="msce", probs=0.95)$weights

# Reuse a fitted model on an updated series, without optimisation
fit <- crost(window(ts.data1, end=c(1985,12)), type="sba")
crost(ts.data1, model=fit)$frc.out

# Use the smoothing parameters of the model on another series
crost(ts.data2, model=fit, init.opt=TRUE)$initial


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