Package {tsintermittent}


Type: Package
Title: Intermittent Time Series Forecasting
Version: 2.0
Date: 2026-11-08
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.
LazyData: yes
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
Depends: R (≥ 4.1.0)
Imports: generics, graphics, grDevices, parallel, stats, utils
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
VignetteBuilder: knitr
Encoding: UTF-8
Config/testthat/edition: 3
URL: https://kourentzes.com/forecasting/2014/06/23/intermittent-demand-forecasting-package-for-r/, https://github.com/trnnick/tsintermittent
BugReports: https://github.com/trnnick/tsintermittent/issues
Config/roxygen2/version: 8.1.1
NeedsCompilation: no
Packaged: 2026-11-13 14:22:24 UTC; nikos
Author: Nikolaos Kourentzes ORCID iD [cre, aut], Fotios Petropoulos ORCID iD [ctb]
Maintainer: Nikolaos Kourentzes <nikolaos@kourentzes.com>
Repository: CRAN
Date/Publication: 2026-11-14 12:30:02 UTC

tsintermittent: Intermittent Time Series Forecasting

Description

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.

Forecasting methods

Lead time quantiles

Methods for fitted models

Classification

Utilities and data

See vignette("tsintermittent") for an introduction.

Author(s)

Maintainer: Nikolaos Kourentzes nikolaos@kourentzes.com (ORCID)

Authors:

Other contributors:

References

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

See Also

Useful links:


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.

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

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


Croston decomposition

Description

Decompose an intermittent demand time series into the non-zero demand and the intervals between demands, as used by Croston's method.

Usage

crost.decomp(data, init = c("naive", "mean"))

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.

init

Initial value for the intervals. This can be:

  • a numeric value;

  • "naive": the first interval is the number of periods from the start of the series to the first demand;

  • "mean": the first interval is the mean of all in-sample intervals.

Value

A list containing:

demand

Non-zero demand vector.

interval

Intervals vector.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

See Also

crost.

Examples

crost.decomp(ts.data1)

# The first interval replaced by the mean interval
crost.decomp(ts.data1, init="mean")$interval


Croston-style moving averages and variants

Description

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.

Usage

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
)

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

Moving average orders. If w == NULL then the orders are optimised. If w is a single value, then the same order is used for both the demand and the intervals. If two values are provided, then the second is used for the intervals.

nop

Number of model parameters, used only if they are optimised. 1 uses the same order for the demand and the intervals, while 2 uses separate orders.

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

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.

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 orders, variant, and cost function are used, without optimisation, to produce forecasts for data.

Details

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.

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.

order

Moving average orders for demand and interval.

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

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

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

References

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

See Also

crost, plot.tsint.

Examples

# 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 multiple intermittent demand series

Description

Forecast all columns of a data frame or matrix of intermittent demand series with a single call.

Usage

data.frc(
  data.in,
  method = c("crost", "crost.ma", "tsb", "sexsm", "imapa", "auto"),
  ...
)

Arguments

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: "crost", "crost.ma", "tsb", "sexsm", "imapa", or "auto". The latter selects between Croston's method, SBA, and SES for each series, using the PKa classification of idclass.

...

Additional inputs passed to the forecasting functions, for example h, cost, probs, or outplot. See the documentation of the individual functions for the options. With method="auto", only the inputs accepted by both crost and sexsm are used, except nop, which is used only by crost.

Details

With method="auto", series that cannot be classified, because they have fewer than two non-zero values, are forecasted with SES.

Value

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, lapply(out, "[[", "frc.in").

lt.out

Only when probs is provided. Data frame containing the quantiles of the demand over the lead time of all time series. The safety stock and the other lead time results of each series are in its lt element of out.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

See Also

crost, tsb, sexsm, crost.ma, imapa, idclass.

Examples

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


Forecast from a fitted intermittent demand model

Description

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.

Usage

## S3 method for class 'tsint'
forecast(object, h = NULL, newdata = NULL, ...)

Arguments

object

A fitted model, of class tsint.

h

Forecast horizon. If NULL, the horizon of the fitted model is used.

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 crost. If NULL, the forecasts are produced from the end of the series the model was fitted to.

...

Unused.

Details

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:

Value

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.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

See Also

lt.dist, crost.

Examples

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


Time series categorisation for intermittent demand

Description

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.

Usage

idclass(
  data,
  type = c("PKa", "SBC", "KHa", "KH", "PK"),
  a.in = NULL,
  outplot = c("summary", "detail", "none"),
  plot.focus = NULL
)

Arguments

data

Time series dataset, where each column is a series. Alternatively, this can be a single series.

type

Type of categorisation:

  • "SBC": Syntetos-Boylan-Croston;

  • "KH": Kostenko-Hyndman (exact);

  • "KHa": Kostenko-Hyndman (approximate);

  • "PK": Petropoulos-Kourentzes (exact);

  • "PKa": Petropoulos-Kourentzes (approximate).

The exact schemes are computationally expensive, as SBA is optimised for each series, unless a.in is provided.

a.in

Vector of SBA interval smoothing parameters, one for each series. This is used by the exact categorisations "KH" and "PK". If NULL, the parameters are optimised internally using MAR as the cost function.

outplot

Plot of the categorisation:

  • "summary": simplified plot that reports the number of series in each class and the cut-off points;

  • "detail": scatterplot of the average inter-demand interval (p) and the squared coefficient of variation of the non-zero demand (CV^2), with the areas of each class shaded;

  • "none": no plot.

Both plots are also available afterwards with plot, see plot.idclass.

plot.focus

Only relevant to outplot == "detail". A vector of two elements, the maximum p and CV^2 to plot, so that the scatterplot can be focused on the area separating the classes, for example c(1.5,1.5). If NULL, the maximums are defined from the dataset.

Details

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.

Value

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 "PK" and "PKa" types.

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.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

References

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.

See Also

plot.idclass, imapa, data.frc.

Examples

# 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


iMAPA: MAPA for intermittent demand

Description

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.

Usage

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
)

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 for Croston's method and SBA. 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. SES is always optimised.

minimumAL

Lowest aggregation level to use.

maximumAL

Highest aggregation level to use. If NULL, the larger of the maximum inter-demand interval of the series and its sampling frequency is used, e.g., at least 12 for monthly data. The frequency is taken from ts objects only, so for other inputs the maximum interval is used. The periods before the first demand count as an interval, as in crost.decomp. If the result is lower than minimumAL, then minimumAL is used. Aggregation levels with fewer than four aggregated observations are not used, whatever the value of maximumAL.

comb

Combination operator, "mean" or "median".

init.opt

If TRUE, the initial values of Croston's method and SBA are optimised. This does not affect SES.

paral

Use parallel processing: 0 for no, 1 for yes using an initialised cluster provided in cl, and 2 for yes, initialising a cluster with all available cores. The workers load the installed package, so it must be installed at the same version as the one in use; this is checked, and an error is given otherwise. In particular, parallel processing does not work when the package is loaded with devtools::load_all().

outplot

Plot of the forecast:

  • 0 or FALSE: no plot;

  • 1, TRUE, or "period": time series and combined forecast;

  • 2 or "levels": time series and the forecasts of all aggregation levels;

  • 3 or "selection": summary of the models selected;

  • 4 or "selection.detail": detailed plot of the models selected, with the classification of the series at each aggregation level;

  • "leadtime": the lead time view, see plot.tsint.

All plots are also available afterwards with plot.imapa.

model.fit

Optional input with model types and parameters. This can be the model.fit output of this function, or a model previously fitted with this function, in which case its combination operator is also used, unless comb is given. If used, it overrides other model settings, and no classification or optimisation is performed. This can be used to apply a fitted model to new data, for example when new observations become available. The same is available with forecast.tsint.

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.

cl

Cluster to use when paral=1, created with parallel::makeCluster. If NULL, a cluster named cl in the global environment is used, for compatibility with earlier versions.

Details

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.

Value

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: AL, the aggregation level; n, the number of observations of the aggregated series; p, the average inter-demand interval; cv2, the squared coefficient of variation of the non-zero demand; model, the selected model, where 1 is Croston, 2 is SBA, and 3 is SES; and use, which is 0 if the aggregation level is not used.

model.fit

Parameters and initialisation values of the fitted model at each aggregation level, with aggregation level and model information.

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.

Lead time quantiles

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.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

References

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

See Also

plot.imapa, idclass, crost.

Examples

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



Empirical quantiles of the demand over the lead time

Description

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.

Usage

lt.dist(
  data,
  frc.in = NULL,
  frc.out = NULL,
  h = NULL,
  probs = c(0.9, 0.95),
  qtype = 7
)

Arguments

data

A model fitted with crost, tsb, sexsm, crost.ma, or imapa. Alternatively, a time series, which can be a vector, a ts object, or a data frame, in which case only the first column is used.

frc.in

In-sample forecasts, of the same length as data, where frc.in[t] is the forecast for period t made at the end of period t-1. Periods without a forecast should be NA. Not used when data is a fitted model.

frc.out

Out-of-sample forecast from the end of the sample. Only the first value is used. Not used when data is a fitted model.

h

Lead time, see the section "Lead time quantiles" in crost. When data is a fitted model, its horizon is used if h is NULL.

probs

Probabilities of the quantiles.

qtype

Type of empirical quantile calculation, passed to quantile.

Details

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

Value

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 origin+1 to origin+h. Origin 0 is the start of the sample. Periods are counted from the first observation, also for ts objects.

n

Number of cumulative errors.

qtype

Type of quantile calculation.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

References

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

See Also

crost, forecast.tsint.

Examples

# 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 and print intermittent demand categorisation

Description

Plot or print the categorisation of intermittent demand series produced by idclass.

Usage

## S3 method for class 'idclass'
plot(x, type = c("summary", "detail"), plot.focus = NULL, ...)

## S3 method for class 'idclass'
print(x, ...)

Arguments

x

An object of class idclass.

type

Type of plot: "summary" for a simplified plot that reports the number of series in each class and the cut-off points, or "detail" for a scatterplot of the series.

plot.focus

Only relevant to type == "detail". A vector of two elements, the maximum p and CV^2 to plot. If NULL, the maximums are defined from the dataset.

...

Additional arguments passed to plot, for example main.

Value

plot has no return value, and print returns x invisibly.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

See Also

idclass.

Examples

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 iMAPA forecasts

Description

Plot and summarise the forecasts produced by imapa.

Usage

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

Arguments

x, object

An object of class imapa.

view

The plot to produce:

  • 1 or "period": time series and combined forecast;

  • 2 or "levels": time series and the forecasts of all aggregation levels;

  • 3 or "selection": summary of the models selected;

  • 4 or "selection.detail": detailed plot of the models selected, with the classification of the series at each aggregation level;

  • "leadtime": the lead time view, as described in plot.tsint. If the forecasts from each in-sample origin were not calculated by imapa, they are calculated here, which can take some time.

legend

If TRUE, a legend is added when it is needed.

...

Additional arguments passed to plot, for example main. For print and summary, unused.

Value

plot has no return value. summary returns an object of class summary.imapa, and coef returns the model.fit of each aggregation level.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

See Also

imapa.

Examples

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 intermittent demand forecasts

Description

Plot the forecasts produced by crost, tsb, sexsm, and crost.ma, in two views: per period or over the lead time.

Usage

## S3 method for class 'tsint'
plot(x, view = c("period", "leadtime"), legend = TRUE, ...)

Arguments

x

An object of class tsint.

view

The view to plot:

  • "period": the series, with the in-sample and out-of-sample demand rate. When lead time quantiles are available, each quantile is shown divided by the lead time, spread over the forecast horizon. This places the quantile next to the forecast, but it is not a per-period quantile.

  • "leadtime": the rolling cumulative demand over windows of h periods, plotted at the end of each window, and the cumulative forecasts made at the start of each window. When lead time quantiles are available, the in-sample cumulative forecasts plus the empirical error quantiles are shown as well, and the cumulative forecast and quantiles for the next h periods are marked at the end of the forecast horizon. This is the view in which the predictive distribution is defined. It needs h of at least 1.

legend

If TRUE, a legend is added when it is needed.

...

Additional arguments passed to plot, for example main, xlab, ylab, and ylim.

Value

No return value, called for the plot.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

See Also

crost, plot.imapa.

Examples

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


Objects exported from other packages

Description

These objects are imported from other packages. Follow the links below to see their documentation.

generics

forecast()


Simple exponential smoothing

Description

Simple exponential smoothing (SES) with fixed or optimised smoothing parameter and initial value, using the cost functions of the package.

Usage

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
)

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 parameter. If w == NULL then the parameter is optimised.

init

Initial value. This can be:

  • a numeric value for the initial level;

  • "naive": the initial level is the first observation;

  • "mean": the initial level is the mean of the series.

If init.opt == TRUE, this is the starting value 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

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.

Value

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

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.

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

See Also

crost, tsb, plot.tsint.

Examples

# 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


Simulator for intermittent demand series

Description

Simulate intermittent demand time series, where demand occurrence follows a Bernoulli distribution and the non-zero demand a negative binomial distribution.

Usage

simID(n = 1, obs = 60, idi = 2, cv2 = 0.5, level = NULL)

Arguments

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 NULL, then a random level in [10,100] is selected for each series.

Value

A data frame with each generated series as a column.

Author(s)

Fotios Petropoulos

References

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.

See Also

idclass, data.frc.

Examples

# 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 intermittent demand series - 'ts.data1'

Description

Example monthly intermittent demand series with 84 observations.

Usage

ts.data1

Format

A ts object.

Examples

plot(ts.data1)

Example intermittent demand series - 'ts.data2'

Description

Example monthly intermittent demand series with 24 observations.

Usage

ts.data2

Format

A ts object.

Examples

plot(ts.data2)

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.

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


Methods for intermittent demand forecasts

Description

Print, summarise, and extract the parameters and in-sample forecasts of the forecasts produced by crost, tsb, sexsm, crost.ma, and imapa.

Usage

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

Arguments

x, object

An object of class tsint.

...

Unused.

Details

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.

Value

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.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

See Also

plot.tsint.

Examples

fit <- crost(ts.data1, h=3, type="sba", probs=c(0.9,0.95))
fit
summary(fit)
coef(fit)
head(fitted(fit))