NAG FL Interface
g13amf (uni_​smooth_​exp)

1 Purpose

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

2 Specification

Fortran Interface
Subroutine g13amf ( mode, itype, p, param, n, y, k, init, nf, fv, fse, yhat, res, dv, ad, r, ifail)
Integer, Intent (In) :: mode, itype, p, n, k, nf
Integer, Intent (Inout) :: ifail
Real (Kind=nag_wp), Intent (In) :: param(*), y(n)
Real (Kind=nag_wp), Intent (Inout) :: init(*), r(*)
Real (Kind=nag_wp), Intent (Out) :: fv(nf), fse(nf), yhat(n), res(n), dv, ad
C Header Interface
#include <nag.h>
void  g13amf_ (const Integer *mode, const Integer *itype, const Integer *p, const double param[], const Integer *n, const double y[], const Integer *k, double init[], const Integer *nf, double fv[], double fse[], double yhat[], double res[], double *dv, double *ad, double r[], Integer *ifail)
The routine may be called by the names g13amf or nagf_tsa_uni_smooth_exp.

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 Arguments

1: mode Integer Input
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 Integer Input
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 Integer Input
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) array Input
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 Integer Input
On entry: the number of observations in the series.
Constraint: n0.
6: yn Real (Kind=nag_wp) array Input
On entry: the time series.
7: k Integer Input
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) array Input/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 Integer Input
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: fvnf Real (Kind=nag_wp) array Output
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: fsenf Real (Kind=nag_wp) array Output
On exit: the forecast standard errors for the values given in fv.
12: yhatn Real (Kind=nag_wp) array Output
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: resn Real (Kind=nag_wp) array Output
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) array Input/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 Integer Input/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface 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 argument, 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=value.
Constraint: mode=0, 1 or 2.
ifail=2
On entry, itype=value.
Constraint: itype=1, 2, 3, 4 or 5.
ifail=3
On entry, p=value.
Constraint: if itype=4 or 5, p>1.
ifail=4
On entry, paramvalue=value.
Constraint: 0.0paramvalue1.0.
On entry, paramvalue=value.
Constraint: if itype=2, 0.0<paramvalue1.0.
On entry, paramvalue=value.
Constraint: paramvalue0.0.
ifail=5
On entry, n=value.
Constraint: n0.
ifail=6
A multiplicative Holt–Winters model cannot be used with the supplied data.
ifail=7
On entry, k=value, 2×p=value.
Constraint: if mode=2 and itype=4 or 5, 2×pk.
On entry, k=value and n=value.
Constraint: if mode=2 and itype=4 or 5, 1kn.
ifail=9
On entry, nf=value.
Constraint: nf0.
ifail=16
On entry, the array r has not been initialized correctly.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

Not applicable.

8 Parallelism and Performance

g13amf is not threaded in any implementation.

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

10 Example

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

10.1 Program Text

Program Text (g13amfe.f90)

10.2 Program Data

Program Data (g13amfe.d)

10.3 Program Results

Program Results (g13amfe.r)