G13AMF (PDF version)
G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G13AMF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

G13AMF performs exponential smoothing using either single exponential, double exponential or a Holt–Winters method.

2  Specification

SUBROUTINE G13AMF ( MODE, ITYPE, P, PARAM, N, Y, K, INIT, NF, FV, FSE, YHAT, RES, DV, AD, R, IFAIL)
INTEGER  MODE, ITYPE, P, N, K, NF, IFAIL
REAL (KIND=nag_wp)  PARAM(*), Y(N), INIT(*), FV(NF), FSE(NF), YHAT(N), RES(N), DV, AD, R(*)

3  Description

Exponential smoothing is a relatively simple method of short term forecasting for a time series. G13AMF provides five types of exponential smoothing; single exponential, Brown's double exponential, linear Holt (also called double exponential smoothing in some references), additive Holt–Winters and multiplicative Holt–Winters. The choice of smoothing method used depends on the characteristics of the time series. If the mean of the series is only slowly changing then single exponential smoothing may be suitable. If there is a trend in the time series, which itself may be slowly changing, then double exponential smoothing may be suitable. If there is a seasonal component to the time series, e.g., daily or monthly data, then one of the two Holt–Winters methods may be suitable.
For a time series yt, for t=1,2,,n, the five smoothing functions are defined by the following: where mt is the mean, rt is the trend and st is the seasonal component at time t with p being the seasonal order. The f-step ahead forecasts are given by y^t+f and their variances by var y^ t+f . The term var εt  is estimated as the mean deviation.
The parameters, α, β and γ control the amount of smoothing. The nearer these parameters are to one, the greater the emphasis on the current data point. Generally these parameters take values in the range 0.1 to 0.3. The linear Holt and two Holt–Winters smoothers include an additional parameter, ϕ, which acts as a trend dampener. For 0.0<ϕ<1.0 the trend is dampened and for ϕ>1.0 the forecast function has an exponential trend, ϕ=0.0 removes the trend term from the forecast function and ϕ=1.0 does not dampen the trend.
For all methods, values for α, β, γ and ψ can be chosen by trying different values and then visually comparing the results by plotting the fitted values along side the original data. Alternatively, for single exponential smoothing a suitable value for α can be obtained by fitting an ARIMA0,1,1 model (see G13BEF). For Brown's double exponential smoothing and linear Holt smoothing with no dampening, (i.e., ϕ=1.0), suitable values for α and γ can be obtained by fitting an ARIMA0,2,2 model. Similarly, the linear Holt method, with ϕ1.0, can be expressed as an ARIMA1,2,2 model and the additive Holt–Winters, with no dampening, (ϕ=1.0), can be expressed as a seasonal ARIMA model with order p of the form ARIMA0,1,p+10,1,0. There is no similar procedure for obtaining parameter values for the multiplicative Holt–Winters method, or the additive Holt–Winters method with ϕ1.0. In these cases parameters could be selected by minimizing a measure of fit using one of the nonlinear optimization routines in Chapter E04.
In addition to values for α, β, γ and ψ, initial values, m0, r0 and s-j, for j=0,1,,p-1, are required to start the smoothing process. You can either supply these or they can be calculated by G13AMF from the first k observations. For single exponential smoothing the mean of the observations is used to estimate m0. For Brown double exponential smoothing and linear Holt smoothing, a simple linear regression is carried out with the series as the dependent variable and the sequence 1,2,,k as the independent variable. The intercept is then used to estimate m0 and the slope to estimate r0. In the case of the additive Holt–Winters method, the same regression is carried out, but a separate intercept is used for each of the p seasonal groupings. The slope gives an estimate for r0 and the mean of the p intercepts is used as the estimate of m0. The seasonal parameters s-j, for j=0,1,,p-1, are estimated as the p intercepts – m0. A similar approach is adopted for the multiplicative Holt–Winter's method.
One step ahead forecasts, y^ t+1  are supplied along with the residuals computed as yt+1 - y^ t+1 . In addition, two measures of fit are provided. The mean absolute deviation,
1 n t=1 n yt - y^ t
and the square root of the mean deviation
1 n t=1 n yt - y^ t 2 .

4  References

Chatfield C (1980) The Analysis of Time Series Chapman and Hall

5  Parameters

1:     MODE – INTEGERInput
On entry: indicates if G13AMF is continuing from a previous call or, if not, how the initial values are computed.
MODE=0
Required values for m0, r0 and s-j, for j=0,1,,p-1, are supplied in INIT.
MODE=1
G13AMF continues from a previous call using values that are supplied in R.
MODE=2
Required values for m0, r0 and s-j, for j=0,1,,p-1, are estimated using the first k observations.
Constraint: MODE=0, 1 or 2.
2:     ITYPE – INTEGERInput
On entry: the smoothing function.
ITYPE=1
Single exponential.
ITYPE=2
Brown double exponential.
ITYPE=3
Linear Holt.
ITYPE=4
Additive Holt–Winters.
ITYPE=5
Multiplicative Holt–Winters.
Constraint: ITYPE=1, 2, 3, 4 or 5.
3:     P – INTEGERInput
On entry: if ITYPE=4 or 5, the seasonal order, p, otherwise P is not referenced.
Constraint: if ITYPE=4 or 5, P>1.
4:     PARAM(*) – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array PARAM must be at least 1 if ITYPE=1 or 2, 3 if ITYPE=3 and at least 4 if ITYPE=4 or 5.
On entry: the smoothing parameters.
If ITYPE=1 or 2, PARAM1=α and any remaining elements of PARAM are not referenced.
If ITYPE=3, PARAM1=α, PARAM2=γ, PARAM3=ϕ and any remaining elements of PARAM are not referenced.
If ITYPE=4 or 5, PARAM1=α, PARAM2=γ, PARAM3=β and PARAM4=ϕ.
Constraints:
  • if ITYPE=1, 0.0α1.0;
  • if ITYPE=2, 0.0<α1.0;
  • if ITYPE=3, 0.0α1.0 and 0.0γ1.0 and ϕ0.0;
  • if ITYPE=4 or 5, 0.0α1.0 and 0.0γ1.0 and 0.0β1.0 and ϕ0.0.
5:     N – INTEGERInput
On entry: the number of observations in the series.
Constraint: N0.
6:     Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the time series.
7:     K – INTEGERInput
On entry: if MODE=2, the number of observations used to initialize the smoothing.
If MODE2, K is not referenced.
Constraints:
  • if MODE=2 and ITYPE=4 or 5, 2×PKN;
  • if MODE=2 and ITYPE=1, 2 or 3, 1KN.
8:     INIT(*) – REAL (KIND=nag_wp) arrayInput/Output
Note: the dimension of the array INIT must be at least 1 if ITYPE=1, 2 if ITYPE=2 or 3 and at least 2+P if ITYPE=4 or 5.
On entry: if MODE=0, the initial values for m0, r0 and s-j, for j=0,1,,p-1, used to initialize the smoothing.
If ITYPE=1, INIT1=m0 and the remaining elements of INIT are not referenced.
If ITYPE=2 or 3, INIT1=m0 and INIT2=r0 and the remaining elements of INIT are not referenced.
If ITYPE=4 or 5, INIT1=m0, INIT2=r0 and INIT3 to INITp+2 hold the values for s-j, for j=0,1,,p-1. The remaining elements of INIT are not referenced.
On exit: if MODE1, the values used to initialize the smoothing. These are in the same order as described above.
9:     NF – INTEGERInput
On entry: the number of forecasts required beyond the end of the series. Note, the one step ahead forecast is always produced.
Constraint: NF0.
10:   FV(NF) – REAL (KIND=nag_wp) arrayOutput
On exit: y^t+f, for f=1,2,,NF, the next NF step forecasts. Where t=N, if MODE1, else t is the total number of smoothed and forecast values already produced.
11:   FSE(NF) – REAL (KIND=nag_wp) arrayOutput
On exit: the forecast standard errors for the values given in FV.
12:   YHAT(N) – REAL (KIND=nag_wp) arrayOutput
On exit: y^t+1, for t=1,2,,N, the one step ahead forecast values, with YHATi being the one step ahead forecast of Yi-1.
13:   RES(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the residuals, yt+1 - y^ t+1 , for t=1,2,,N.
14:   DV – REAL (KIND=nag_wp)Output
On exit: the square root of the mean deviation.
On exit: the mean absolute deviation.
16:   R(*) – REAL (KIND=nag_wp) arrayInput/Output
Note: the dimension of the array R must be at least 13 if ITYPE=1, 2 or 3 and at least 13+P if ITYPE=4 or 5.
On entry: if MODE=1, R must contain the values as returned by a previous call to G05PMF or G13AMF, R need not be set otherwise.
If ITYPE=1, 2 or 3, only the first 13 elements of R are referenced, otherwise the first 13+p elements are referenced.
On exit: the information on the current state of the smoothing.
Constraint: if MODE=1, R must have been initialized by at least one previous call to G05PMF or G13AMF with MODE1, and R should not have been changed since the last call to G05PMF or G13AMF.
17:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,MODE<0,
orMODE>2.
IFAIL=2
On entry,ITYPE<1,
orITYPE>5.
IFAIL=3
On entry,ITYPE=4 or 5 and P<2.
IFAIL=4
On entry, at least one of α, β or γ<0.0 or >1.0.
On entry, ITYPE=2 and α=0.0.
On entry, ϕ<0.0.
IFAIL=5
On entry,N<0.
IFAIL=6
A multiplicative Holt–Winters model cannot be used with the supplied data.
IFAIL=7
On entry, MODE=2 and K<1 or K>N.
On entry, MODE=2, ITYPE=4 or 5 and K<2×P.
IFAIL=9
On entry,NF<0.
IFAIL=16
On entry, MODE=1 and the array R has not been initialized correctly.

7  Accuracy

Not applicable.

8  Further Comments

Single exponential, Brown's double exponential and linear Holt smoothing methods are stable, whereas the two Holt–Winters methods can be affected by poor initial values for the seasonal components.
See also the routine document for G05PMF.

9  Example

This example smooths a time series relating to the rate of the earth's rotation about its polar axis.

9.1  Program Text

Program Text (g13amfe.f90)

9.2  Program Data

Program Data (g13amfe.d)

9.3  Program Results

Program Results (g13amfe.r)


G13AMF (PDF version)
G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012