| Title: | Intermittent Time Series Forecasting |
|---|---|
| Description: | Time series methods for intermittent demand forecasting. Includes Croston's method and its variants (Moving Average, SBA), and the TSB method. Users can obtain optimal parameters on a variety of loss functions, or use fixed ones. Intermittent time series classification methods and iMAPA that uses multiple temporal aggregation levels are also provided. Empirical quantiles of the demand over the lead time are calculated from the cumulative forecast errors. |
| Authors: | Nikolaos Kourentzes [cre, aut] (ORCID: <https://orcid.org/0000-0003-0211-5218>), Fotios Petropoulos [ctb] (ORCID: <https://orcid.org/0000-0003-3039-4955>) |
| Maintainer: | Nikolaos Kourentzes <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 2.0 |
| Built: | 2026-11-09 09:52:02 UTC |
| Source: | https://github.com/trnnick/tsintermittent |
Time series methods for intermittent demand forecasting. The package includes Croston's method and its variants (SBA and SBJ), Croston-style moving averages, the TSB method, and simple exponential smoothing, with parameters and initial values that can be optimised using cost functions designed for intermittent demand (Kourentzes, 2014). Intermittent time series classification and iMAPA, which combines forecasts from multiple temporal aggregation levels, are also provided (Petropoulos and Kourentzes, 2015). Empirical predictive distributions of the demand over the lead time can be calculated for all methods.
crost: Croston's method, SBA, and SBJ.
crost.ma: Croston-style moving averages.
tsb: TSB method.
sexsm: Simple exponential smoothing.
imapa: iMAPA, combining forecasts from multiple temporal
aggregation levels.
data.frc: Forecasting multiple series with a single call.
The input probs of the forecasting methods: quantiles of the demand over
the lead time and safety stock, when fitting a model.
lt.dist: Quantiles of the demand over the lead time, for a fitted
model with any lead time and probabilities, or for forecasts produced otherwise.
print, summary, coef, and fitted: see
tsint-methods, and plot.imapa for iMAPA.
plot: per-period and lead time views of the forecasts, see
plot.tsint, and plot.imapa for the additional views of
iMAPA.
forecast: point forecasts for any horizon, optionally for new data, see
forecast.tsint.
The input model of the forecasting methods, or model.fit of
imapa: a fitted model applied to new data without optimisation.
idclass: Classification of intermittent demand series, to select
between Croston's method, SBA, and SES.
print and plot: see plot.idclass.
crost.decomp: Croston decomposition into non-zero demand and
intervals.
simID: Simulation of intermittent demand series.
See vignette("tsintermittent") for an introduction.
Maintainer: Nikolaos Kourentzes [email protected] (ORCID)
Authors:
Nikolaos Kourentzes [email protected] (ORCID)
Other contributors:
Fotios Petropoulos [email protected] (ORCID) [contributor]
Kourentzes, N. (2014). On intermittent demand model optimisation and selection. International Journal of Production Economics, 156, 180–190. doi:10.1016/j.ijpe.2014.06.007
Petropoulos, F., and Kourentzes, N. (2015). Forecast combinations for intermittent demand. Journal of the Operational Research Society, 66(6), 914–924. doi:10.1057/jors.2014.62
Useful links:
https://kourentzes.com/forecasting/2014/06/23/intermittent-demand-forecasting-package-for-r/
Report bugs at https://github.com/trnnick/tsintermittent/issues
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 )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, [email protected]
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. 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. 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. 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# 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
Decompose an intermittent demand time series into the non-zero demand and the intervals between demands, as used by Croston's method.
crost.decomp(data, init = c("naive", "mean"))crost.decomp(data, init = c("naive", "mean"))
data |
Intermittent demand time series. This can be a vector, a |
init |
Initial value for the intervals. This can be:
|
A list containing:
demand |
Non-zero demand vector. |
interval |
Intervals vector. |
Nikolaos Kourentzes, [email protected]
crost.decomp(ts.data1) # The first interval replaced by the mean interval crost.decomp(ts.data1, init="mean")$intervalcrost.decomp(ts.data1) # The first interval replaced by the mean interval crost.decomp(ts.data1, init="mean")$interval
Croston's method and its variants, using moving averages instead of exponential smoothing for the non-zero demand and the intervals, with fixed or optimised orders.
crost.ma( data, h = 10, w = NULL, nop = c(2, 1), type = c("croston", "sba", "sbj"), cost = c("mar", "msr", "mae", "mse", "msce", "mace"), outplot = c(FALSE, TRUE), na.rm = c(FALSE, TRUE), probs = NULL, qtype = 7, model = NULL )crost.ma( data, h = 10, w = NULL, nop = c(2, 1), type = c("croston", "sba", "sbj"), cost = c("mar", "msr", "mae", "mse", "msce", "mace"), outplot = 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 |
Moving average orders. If |
nop |
Number of model parameters, used only if they are optimised. |
type |
Croston's method variant: |
cost |
Cost function used for optimisation: |
outplot |
Plot of the forecast: |
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 orders, variant, and
cost function are used, without optimisation, to produce forecasts for
|
The orders are optimised by a grid search over all orders up to the number of non-zero demands minus one, as the cost functions are not smooth in integer orders. When several orders give the same minimum cost, the one with the smallest interval order, and then the smallest demand order, is used. The forecasts are demand rates, constant over the horizon.
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. |
order |
Moving average orders for demand and interval. |
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)).
Nikolaos Kourentzes, [email protected]
The references for the cost functions and the lead time quantiles are given in
crost.
Kourentzes, N. (2014). On intermittent demand model optimisation and selection. International Journal of Production Economics, 156, 180–190. doi:10.1016/j.ijpe.2014.06.007
# Optimised orders fit <- crost.ma(ts.data1, outplot=TRUE) fit$order # Same order for demand and intervals, SBA variant crost.ma(ts.data1, nop=1, type="sba")$order # Fixed orders crost.ma(ts.data1, w=c(3,2))$frc.out # Reuse the fitted orders on an updated series fit <- crost.ma(window(ts.data1, end=c(1985,12))) crost.ma(ts.data1, model=fit)$order # Quantiles of the demand over a lead time of 2 periods crost.ma(ts.data1, h=2, probs=c(0.9,0.95))$lt$quantile# Optimised orders fit <- crost.ma(ts.data1, outplot=TRUE) fit$order # Same order for demand and intervals, SBA variant crost.ma(ts.data1, nop=1, type="sba")$order # Fixed orders crost.ma(ts.data1, w=c(3,2))$frc.out # Reuse the fitted orders on an updated series fit <- crost.ma(window(ts.data1, end=c(1985,12))) crost.ma(ts.data1, model=fit)$order # Quantiles of the demand over a lead time of 2 periods crost.ma(ts.data1, h=2, probs=c(0.9,0.95))$lt$quantile
Forecast all columns of a data frame or matrix of intermittent demand series with a single call.
data.frc( data.in, method = c("crost", "crost.ma", "tsb", "sexsm", "imapa", "auto"), ... )data.frc( data.in, method = c("crost", "crost.ma", "tsb", "sexsm", "imapa", "auto"), ... )
data.in |
Data frame with time series, one per column. This can also be a matrix or array with each column being a different time series. |
method |
Forecasting method: |
... |
Additional inputs passed to the forecasting functions, for example
|
With method="auto", series that cannot be classified, because they
have fewer than two non-zero values, are forecasted with SES.
A list containing:
frc.out |
Data frame containing the forecasts of all time series. |
out |
List with the output of the forecasting function for each series. To
access an element of all outputs use, for example,
|
lt.out |
Only when |
Nikolaos Kourentzes, [email protected]
crost, tsb, sexsm,
crost.ma, imapa, idclass.
set.seed(1) dataset <- simID(5, 60, idi=1.5, cv2=0.5) # SBA for all series fit <- data.frc(dataset, method="crost", type="sba", h=6) fit$frc.out # Smoothing parameters of all series sapply(fit$out, "[[", "weights") # Automatic selection between Croston, SBA, and SES data.frc(dataset, method="auto", h=6)$frc.out # Quantiles of the demand over a lead time of 3 periods data.frc(dataset, method="tsb", h=3, probs=c(0.9,0.95))$lt.outset.seed(1) dataset <- simID(5, 60, idi=1.5, cv2=0.5) # SBA for all series fit <- data.frc(dataset, method="crost", type="sba", h=6) fit$frc.out # Smoothing parameters of all series sapply(fit$out, "[[", "weights") # Automatic selection between Croston, SBA, and SES data.frc(dataset, method="auto", h=6)$frc.out # Quantiles of the demand over a lead time of 3 periods data.frc(dataset, method="tsb", h=3, probs=c(0.9,0.95))$lt.out
Point forecasts from a model fitted with crost,
tsb, sexsm, crost.ma, or
imapa, for any horizon, without optimising the model again. The fitted
model can also be applied to new data.
## S3 method for class 'tsint' forecast(object, h = NULL, newdata = NULL, ...)## S3 method for class 'tsint' forecast(object, h = NULL, newdata = NULL, ...)
object |
A fitted model, of class |
h |
Forecast horizon. If |
newdata |
Optional time series to apply the fitted model to, for example the
series updated with new observations. The parameters and initial values of the
model are used without optimisation, see the section "Reusing a fitted model" in
|
... |
Unused. |
This method gives only the point forecasts, i.e., the expected demand per
period. For Croston's method and its variants, TSB, and iMAPA these are demand
rates, constant over the horizon. No prediction intervals are provided. For these
methods a predictive distribution is meaningful only for the demand over the lead
time, not for the demand of each period, so per-period intervals would be
misleading. Note that the parameters of a model optimised with the cost functions
"msce" or "mace" depend on the horizon used when fitting it, and
they are not reoptimised for a new h.
Everything else is available in the native functions of the package:
quantiles of the demand over the lead time and the safety stock, with the
input probs of the forecasting functions, e.g.,
crost(y, h=3, probs=c(0.9,0.95))$lt, or for an existing fitted model, for
any lead time and probabilities, without refitting, with
lt.dist, e.g., lt.dist(fit, h=3, probs=0.95);
plots of the forecasts per period and over the lead time, with
plot.tsint and plot.imapa;
the parameters and a summary of the model, with coef and
summary, see tsint-methods;
the fitted model applied to new data, keeping its smoothing parameters but
optimising its initial values, with the input model of the forecasting
functions and init.opt=TRUE, e.g., crost(y, model=fit, init.opt=TRUE).
A vector of point forecasts of length h. If the series was a ts
object, the forecasts are a ts object continuing its time index.
Nikolaos Kourentzes, [email protected]
fit <- crost(window(ts.data1, end=c(1985,12)), type="sba") # Point forecasts for a different horizon forecast(fit, h=6) # The fitted model applied to the updated series forecast(fit, h=6, newdata=ts.data1) # Quantiles of the demand over a lead time of 3 periods, in the native way lt.dist(fit, h=3, probs=c(0.9,0.95))fit <- crost(window(ts.data1, end=c(1985,12)), type="sba") # Point forecasts for a different horizon forecast(fit, h=6) # The fitted model applied to the updated series forecast(fit, h=6, newdata=ts.data1) # Quantiles of the demand over a lead time of 3 periods, in the native way lt.dist(fit, h=3, probs=c(0.9,0.95))
Categorise intermittent demand time series according to their average inter-demand interval and the squared coefficient of variation of their non-zero demand, indicating whether they should be modelled with Croston's method, SBA, or SES.
idclass( data, type = c("PKa", "SBC", "KHa", "KH", "PK"), a.in = NULL, outplot = c("summary", "detail", "none"), plot.focus = NULL )idclass( data, type = c("PKa", "SBC", "KHa", "KH", "PK"), a.in = NULL, outplot = c("summary", "detail", "none"), plot.focus = NULL )
data |
Time series dataset, where each column is a series. Alternatively, this can be a single series. |
type |
Type of categorisation:
The exact schemes are computationally expensive, as SBA is optimised for each
series, unless |
a.in |
Vector of SBA interval smoothing parameters, one for each series. This is
used by the exact categorisations |
outplot |
Plot of the categorisation:
Both plots are also available afterwards with |
plot.focus |
Only relevant to |
The Petropoulos-Kourentzes classification extends the Kostenko-Hyndman one
for series without zero demand, p = 1, which are assigned to SES instead of
Croston's method or SBA. Such series are rare at the original frequency, but common
once a series is temporally aggregated, which is why this classification is used by
imapa. Series with fewer than two non-zero values cannot be
categorised; a warning is given and they are left out of all classes.
An object of class idclass, which is a list containing:
idx.croston |
Index of series that are categorised under Croston. |
idx.sba |
Index of series that are categorised under SBA. |
idx.ses |
Index of series that are categorised under SES. Provided only for
|
cv2 |
Squared coefficient of variation of non-zero demand. |
p |
Average inter-demand interval. |
summary |
Summary of number of series under each category. |
fit.info |
Information used by the methods of the object. Not intended for direct use. |
Nikolaos Kourentzes, [email protected]
Petropoulos, F., and Kourentzes, N. (2015). Forecast combinations for intermittent demand. Journal of the Operational Research Society, 66(6), 914–924. doi:10.1057/jors.2014.62
Syntetos, A. A., Boylan, J. E., and Croston, J. D. (2005). On the categorization of demand patterns. Journal of the Operational Research Society, 56(5), 495–503.
Kostenko, A. V., and Hyndman, R. J. (2006). A note on the categorization of demand patterns. Journal of the Operational Research Society, 57(10), 1256–1257.
plot.idclass, imapa, data.frc.
# Create some data, where each column is a time series set.seed(1) dataset <- simID(100, 60, idi=1.15, cv2=0.3) idclass(dataset) # Detailed plot of the SBC classification cls <- idclass(dataset, type="SBC", outplot="detail") cls$summary # Focus the detailed plot idclass(dataset, type="KHa", outplot="detail", plot.focus=c(1.5,1.5)) # Single series idclass(ts.data1, outplot="none")$summary# Create some data, where each column is a time series set.seed(1) dataset <- simID(100, 60, idi=1.15, cv2=0.3) idclass(dataset) # Detailed plot of the SBC classification cls <- idclass(dataset, type="SBC", outplot="detail") cls$summary # Focus the detailed plot idclass(dataset, type="KHa", outplot="detail", plot.focus=c(1.5,1.5)) # Single series idclass(ts.data1, outplot="none")$summary
Forecast intermittent demand time series by modelling them at multiple temporal aggregation levels and combining the forecasts, selecting between Croston's method, SBA, and SES at each level.
imapa( data, h = 10, w = NULL, minimumAL = 1, maximumAL = NULL, comb = c("mean", "median"), init.opt = c(TRUE, FALSE), paral = c(0, 1, 2), outplot = c(0, 1, 2, 3, 4), model.fit = NULL, na.rm = c(FALSE, TRUE), probs = NULL, qtype = 7, cl = NULL )imapa( data, h = 10, w = NULL, minimumAL = 1, maximumAL = NULL, comb = c("mean", "median"), init.opt = c(TRUE, FALSE), paral = c(0, 1, 2), outplot = c(0, 1, 2, 3, 4), model.fit = NULL, na.rm = c(FALSE, TRUE), probs = NULL, qtype = 7, cl = NULL )
data |
Intermittent demand time series. This can be a vector, a |
h |
Forecast horizon. When |
w |
Smoothing parameters for Croston's method and SBA. If |
minimumAL |
Lowest aggregation level to use. |
maximumAL |
Highest aggregation level to use. If |
comb |
Combination operator, |
init.opt |
If |
paral |
Use parallel processing: |
outplot |
Plot of the forecast:
All plots are also available afterwards with |
model.fit |
Optional input with model types and parameters. This can be the
|
na.rm |
If |
probs |
Probabilities of the quantiles of the demand over the lead time
|
qtype |
Type of empirical quantile calculation, passed to
|
cl |
Cluster to use when |
Temporal aggregation sums the series into non-overlapping buckets of several
periods. At higher aggregation levels there are fewer zeros, so the series becomes
easier to forecast, but the best level differs between series and is not known in
advance. iMAPA avoids this choice by using all levels from minimumAL to
maximumAL (Petropoulos and Kourentzes, 2015). At each level, the first
observations are dropped where needed, so that all buckets are complete; the
aggregated series is classified with the PKa scheme of idclass; and
Croston's method, SBA, or SES is fitted accordingly, with parameters optimised using
MAR. The forecast of each level is divided equally over the periods of a bucket, and
the forecasts of all levels are combined. Levels with fewer than four aggregated
observations, or fewer than two non-zero values, are not used.
The forecast is a demand rate, constant over the horizon. The in-sample forecast
frc.in of each level is produced at the aggregated frequency, so within each
bucket it is the forecast made at the start of the bucket.
An object of class imapa, which is a list containing:
frc.in |
In-sample demand rate. |
frc.out |
Out-of-sample demand rate. |
summary |
An array containing information for each aggregation level:
|
model.fit |
Parameters and initialisation values of the fitted model at each aggregation level, with aggregation level and model information. |
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.
The quantiles are calculated as described in crost, from the cumulative
errors over h periods. Because the in-sample forecasts of the aggregation
levels are made at the start of each bucket, rather than at every period, the
cumulative errors are calculated from forecasts made at every in-sample origin, using
the fitted models of each level with fixed parameters. Levels that do not yet have
enough observations at an origin are left out of the combination at that origin.
This requires forecasts from every origin and every level, so it is slower than the
other methods; paral can be used to speed it up. Unlike the other methods, the
cumulative cost functions MSCE and MACE are not offered, as temporal aggregation
already targets the demand over multiple periods.
Nikolaos Kourentzes, [email protected]
Petropoulos, F., and Kourentzes, N. (2015). Forecast combinations for intermittent demand. Journal of the Operational Research Society, 66(6), 914–924. doi:10.1057/jors.2014.62
# iMAPA with a plot of the combined forecast fit <- imapa(ts.data1, outplot=1) summary(fit) # Forecasts of each aggregation level and the models selected plot(fit, view="levels") plot(fit, view="selection.detail") # Fewer aggregation levels, combined with the median imapa(ts.data1, maximumAL=12, comb="median")$frc.out # Reuse the fitted models, for example on an updated series imapa(ts.data1, model.fit=fit)$frc.out # Quantiles of the demand over a lead time of 3 periods fit <- imapa(ts.data1, h=3, maximumAL=12, probs=c(0.9,0.95), outplot="leadtime") fit$lt$quantile # Parallel processing with a cluster cl <- parallel::makeCluster(2) imapa(ts.data1, paral=1, cl=cl)$frc.out parallel::stopCluster(cl)# iMAPA with a plot of the combined forecast fit <- imapa(ts.data1, outplot=1) summary(fit) # Forecasts of each aggregation level and the models selected plot(fit, view="levels") plot(fit, view="selection.detail") # Fewer aggregation levels, combined with the median imapa(ts.data1, maximumAL=12, comb="median")$frc.out # Reuse the fitted models, for example on an updated series imapa(ts.data1, model.fit=fit)$frc.out # Quantiles of the demand over a lead time of 3 periods fit <- imapa(ts.data1, h=3, maximumAL=12, probs=c(0.9,0.95), outplot="leadtime") fit$lt$quantile # Parallel processing with a cluster cl <- parallel::makeCluster(2) imapa(ts.data1, paral=1, cl=cl)$frc.out parallel::stopCluster(cl)
Calculate the empirical quantiles of the demand over the lead time from the cumulative in-sample forecast errors, either for a model fitted with the functions of the package, for any lead time and probabilities without refitting it, or for any forecast that is constant over the horizon.
lt.dist( data, frc.in = NULL, frc.out = NULL, h = NULL, probs = c(0.9, 0.95), qtype = 7 )lt.dist( data, frc.in = NULL, frc.out = NULL, h = NULL, probs = c(0.9, 0.95), qtype = 7 )
data |
A model fitted with |
frc.in |
In-sample forecasts, of the same length as |
frc.out |
Out-of-sample forecast from the end of the sample. Only the first
value is used. Not used when |
h |
Lead time, see the section "Lead time quantiles" in |
probs |
Probabilities of the quantiles. |
qtype |
Type of empirical quantile calculation, passed to
|
This is the calculation used by the forecasting functions of the package
when probs is provided. With a fitted model, the stored series and in-sample
forecasts are used, so the lead time and the probabilities can be changed without
optimising the model again. Note that the parameters of a model optimised with the
cost functions "msce" or "mace" depend on the horizon used when
fitting it. For iMAPA, the forecasts from each in-sample origin are calculated if
they were not calculated when fitting, which can take some time.
With a time series and forecasts produced otherwise, the forecast made at each
origin is assumed to be constant over the next h periods, as is the case for
all methods in the package, so that the cumulative forecast from origin t-1
is h*frc.in[t].
A list containing:
h |
Lead time. |
probs |
Probabilities. |
frc |
Cumulative forecast over the lead time. |
quantile |
Quantiles of the demand over the lead time, i.e., the order-up-to level or the reorder point. |
ss |
Safety stock, i.e., the quantiles minus the cumulative forecast. |
errors |
In-sample cumulative errors. |
origin |
Origin of each cumulative error, i.e., the period at the end of which
the forecast was made, so that the error covers periods |
n |
Number of cumulative errors. |
qtype |
Type of quantile calculation. |
Nikolaos Kourentzes, [email protected]
Saoud, P., Kourentzes, N., and Boylan, J. E. (2022). Approximations for the lead time variance: A forecasting and inventory evaluation. Omega, 110, 102614. doi:10.1016/j.omega.2022.102614
# Different lead times and probabilities for a fitted model, without refitting fit <- crost(ts.data1, type="sba") lt.dist(fit, h=3) lt.dist(fit, h=6, probs=0.99) # Same result as crost(ts.data1, h=3, probs=c(0.9,0.95))$lt fit <- crost(ts.data1, h=3) lt.dist(ts.data1, fit$frc.in, fit$frc.out, h=3) # A simple moving average of the last 12 periods as the forecast y <- as.numeric(ts.data1) frc <- c(rep(NA,12), as.numeric(stats::filter(y, rep(1/12,12), sides=1))[12:(length(y)-1)]) lt.dist(y, frc, mean(tail(y,12)), h=3, probs=0.95)# Different lead times and probabilities for a fitted model, without refitting fit <- crost(ts.data1, type="sba") lt.dist(fit, h=3) lt.dist(fit, h=6, probs=0.99) # Same result as crost(ts.data1, h=3, probs=c(0.9,0.95))$lt fit <- crost(ts.data1, h=3) lt.dist(ts.data1, fit$frc.in, fit$frc.out, h=3) # A simple moving average of the last 12 periods as the forecast y <- as.numeric(ts.data1) frc <- c(rep(NA,12), as.numeric(stats::filter(y, rep(1/12,12), sides=1))[12:(length(y)-1)]) lt.dist(y, frc, mean(tail(y,12)), h=3, probs=0.95)
Plot or print the categorisation of intermittent demand series
produced by idclass.
## S3 method for class 'idclass' plot(x, type = c("summary", "detail"), plot.focus = NULL, ...) ## S3 method for class 'idclass' print(x, ...)## S3 method for class 'idclass' plot(x, type = c("summary", "detail"), plot.focus = NULL, ...) ## S3 method for class 'idclass' print(x, ...)
x |
An object of class |
type |
Type of plot: |
plot.focus |
Only relevant to |
... |
Additional arguments passed to |
plot has no return value, and print returns x
invisibly.
Nikolaos Kourentzes, [email protected]
set.seed(1) cls <- idclass(simID(50, 60, idi=1.3, cv2=0.5), outplot="none") cls plot(cls) plot(cls, type="detail", main="Simulated series")set.seed(1) cls <- idclass(simID(50, 60, idi=1.3, cv2=0.5), outplot="none") cls plot(cls) plot(cls, type="detail", main="Simulated series")
Plot and summarise the forecasts produced by imapa.
## S3 method for class 'imapa' plot(x, view = 1, legend = TRUE, ...) ## S3 method for class 'imapa' print(x, ...) ## S3 method for class 'imapa' coef(object, ...) ## S3 method for class 'imapa' summary(object, ...) ## S3 method for class 'summary.imapa' print(x, ...)## S3 method for class 'imapa' plot(x, view = 1, legend = TRUE, ...) ## S3 method for class 'imapa' print(x, ...) ## S3 method for class 'imapa' coef(object, ...) ## S3 method for class 'imapa' summary(object, ...) ## S3 method for class 'summary.imapa' print(x, ...)
x, object
|
An object of class |
view |
The plot to produce:
|
legend |
If |
... |
Additional arguments passed to |
plot has no return value. summary returns an object of class
summary.imapa, and coef returns the model.fit of each
aggregation level.
Nikolaos Kourentzes, [email protected]
fit <- imapa(ts.data1, h=3, maximumAL=12) fit summary(fit) plot(fit) plot(fit, view="levels") plot(fit, view="selection") plot(fit, view="leadtime")fit <- imapa(ts.data1, h=3, maximumAL=12) fit summary(fit) plot(fit) plot(fit, view="levels") plot(fit, view="selection") plot(fit, view="leadtime")
Plot the forecasts produced by crost, tsb,
sexsm, and crost.ma, in two views: per period or over
the lead time.
## S3 method for class 'tsint' plot(x, view = c("period", "leadtime"), legend = TRUE, ...)## S3 method for class 'tsint' plot(x, view = c("period", "leadtime"), legend = TRUE, ...)
x |
An object of class |
view |
The view to plot:
|
legend |
If |
... |
Additional arguments passed to |
No return value, called for the plot.
Nikolaos Kourentzes, [email protected]
fit <- crost(ts.data1, h=3, type="sba", probs=c(0.9,0.95)) plot(fit) plot(fit, view="leadtime") plot(fit, view="leadtime", main="SBA", ylab="Demand over 3 periods") # The lead time view is also available without quantiles plot(tsb(ts.data1, h=6), view="leadtime")fit <- crost(ts.data1, h=3, type="sba", probs=c(0.9,0.95)) plot(fit) plot(fit, view="leadtime") plot(fit, view="leadtime", main="SBA", ylab="Demand over 3 periods") # The lead time view is also available without quantiles plot(tsb(ts.data1, h=6), view="leadtime")
Simple exponential smoothing (SES) with fixed or optimised smoothing parameter and initial value, using the cost functions of the package.
sexsm( 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 )sexsm( 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 parameter. If |
init |
Initial value. 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 |
SES makes no special treatment of periods with zero demand. It is a common
benchmark for intermittent demand, and it is used by imapa at
aggregation levels without zero demand. Its forecast is constant over the horizon.
The cost functions MAR and MSR were designed for methods that forecast a demand
rate, such as Croston's method and its variants, so their benefits may not carry
over to SES.
Unlike crost and tsb, the initial value of SES is the
forecast for the first period, so frc.in has no missing values.
An object of class tsint, which is a list containing:
model |
Type of model fitted. |
frc.in |
In-sample demand. |
frc.out |
Out-of-sample demand. |
alpha |
Smoothing parameter. |
initial |
Initialisation value. |
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, [email protected]
The references for the cost functions and the lead time quantiles are given in
crost.
Kourentzes, N. (2014). On intermittent demand model optimisation and selection. International Journal of Production Economics, 156, 180–190. doi:10.1016/j.ijpe.2014.06.007
crost, tsb, plot.tsint.
# SES with optimised parameter and initial value fit <- sexsm(ts.data1, outplot=TRUE) fit$alpha # Conventional cost function sexsm(ts.data1, cost="mse")$alpha # Fixed parameter and initial value sexsm(ts.data1, w=0.1, init="mean", init.opt=FALSE)$frc.out # Reuse the fitted model on an updated series fit <- sexsm(window(ts.data1, end=c(1985,12))) sexsm(ts.data1, model=fit)$frc.out # Quantiles of the demand over a lead time of 3 periods sexsm(ts.data1, h=3, probs=0.95)$lt# SES with optimised parameter and initial value fit <- sexsm(ts.data1, outplot=TRUE) fit$alpha # Conventional cost function sexsm(ts.data1, cost="mse")$alpha # Fixed parameter and initial value sexsm(ts.data1, w=0.1, init="mean", init.opt=FALSE)$frc.out # Reuse the fitted model on an updated series fit <- sexsm(window(ts.data1, end=c(1985,12))) sexsm(ts.data1, model=fit)$frc.out # Quantiles of the demand over a lead time of 3 periods sexsm(ts.data1, h=3, probs=0.95)$lt
Simulate intermittent demand time series, where demand occurrence follows a Bernoulli distribution and the non-zero demand a negative binomial distribution.
simID(n = 1, obs = 60, idi = 2, cv2 = 0.5, level = NULL)simID(n = 1, obs = 60, idi = 2, cv2 = 0.5, level = NULL)
n |
Number of time series to be generated. |
obs |
Number of observations of each series. |
idi |
Average inter-demand interval of each series. |
cv2 |
Squared coefficient of variation of the non-zero demand. |
level |
Mean level of the non-zero demand. If |
A data frame with each generated series as a column.
Fotios Petropoulos
Petropoulos, F., Makridakis, S., Assimakopoulos, V., and Nikolopoulos, K. (2014). 'Horses for courses' in demand forecasting. European Journal of Operational Research, 237(1), 152–163.
# 100 series of 60 observations dataset <- simID(100, 60, idi=1.15, cv2=0.3) dim(dataset) # More intermittent series with a fixed level dataset <- simID(10, 60, idi=3, cv2=0.5, level=20) plot(dataset[,1], type="h")# 100 series of 60 observations dataset <- simID(100, 60, idi=1.15, cv2=0.3) dim(dataset) # More intermittent series with a fixed level dataset <- simID(10, 60, idi=3, cv2=0.5, level=20) plot(dataset[,1], type="h")
Example monthly intermittent demand series with 84 observations.
ts.data1ts.data1
A ts object.
plot(ts.data1)plot(ts.data1)
Example monthly intermittent demand series with 24 observations.
ts.data2ts.data2
A ts object.
plot(ts.data2)plot(ts.data2)
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 )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, [email protected]
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. 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# 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
Print, summarise, and extract the parameters and in-sample forecasts of
the forecasts produced by crost, tsb,
sexsm, crost.ma, and imapa.
## S3 method for class 'tsint' print(x, ...) ## S3 method for class 'tsint' summary(object, ...) ## S3 method for class 'summary.tsint' print(x, ...) ## S3 method for class 'tsint' coef(object, ...) ## S3 method for class 'tsint' fitted(object, ...)## S3 method for class 'tsint' print(x, ...) ## S3 method for class 'tsint' summary(object, ...) ## S3 method for class 'summary.tsint' print(x, ...) ## S3 method for class 'tsint' coef(object, ...) ## S3 method for class 'tsint' fitted(object, ...)
x, object
|
An object of class |
... |
Unused. |
The summary reports the characteristics of the series, the parameters and
whether they were optimised, and the forecast. The in-sample value of the cost
function is reported only when something was optimised, as it is the criterion of
the optimisation. When lead time quantiles were requested, these are reported
together with the safety stock. The series is also classified according to the
PKa scheme of idclass.
summary returns an object of class summary.tsint. coef
returns the smoothing parameters, or the orders for crost.ma.
fitted returns the in-sample forecasts frc.in. If the series was a
ts object, these are returned as a ts object with the same time
index, unless NA values were removed with na.rm.
Nikolaos Kourentzes, [email protected]
fit <- crost(ts.data1, h=3, type="sba", probs=c(0.9,0.95)) fit summary(fit) coef(fit) head(fitted(fit))fit <- crost(ts.data1, h=3, type="sba", probs=c(0.9,0.95)) fit summary(fit) coef(fit) head(fitted(fit))