| crost | R Documentation |
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.
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
)
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 intervals. This can be:
If |
nop |
Number of model parameters, used only if they are optimised. |
type |
Croston's method variant: |
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 |
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.
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 |
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
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")}
tsb, sexsm, crost.ma,
imapa, plot.tsint, lt.dist.
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.