G13 Chapter Contents
G13 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG13AMF

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.

## 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 ${y}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,n$, the five smoothing functions are defined by the following:
• Single Exponential Smoothing
 $mt = α yt + 1-α mt-1 y^t+f = mt var y^t+f = varεt 1+ f-1 α2$
• Brown Double Exponential Smoothing
 $mt = α yt + 1-α mt-1 rt = α mt - mt-1 + 1-α rt-1 y^ t+f = mt + f-1 + 1 / α rt var y^ t+f = varεt 1+ ∑ i=1 f-1 2α+ i-1 α2 2$
• Linear Holt Smoothing
 $mt = α yt + 1-α mt-1 + ϕ rt-1 rt = γ mt - mt-1 + 1-γ ϕ rt-1 y^ t+f = mt + ∑ i=1 f ϕi rt var y^ t+f = var εt 1+ ∑ i=1 f-1 α + α γ ϕ ϕi-1 ϕ-1 2$
• Multiplicative Holt–Winters Smoothing
 $mt = α yt / s t-p + 1-α m t-1 +ϕ r t-1 rt = γ mt - m t-1 + 1-γ ϕ r t-1 st = β yt / mt + 1-β s t-p y^ t+f = mt + ∑ i=1 f ϕi rt × s t-p var y^ t+f = var εt ∑ i=0 ∞ ∑ j=0 p-1 ψ j+ip s t+f s t+f-j 2$
and $\psi$ is defined as in the additive Holt–Winters smoothing,
where ${m}_{t}$ is the mean, ${r}_{t}$ is the trend and ${s}_{t}$ is the seasonal component at time $t$ with $p$ being the seasonal order. The $f$-step ahead forecasts are given by ${\stackrel{^}{y}}_{t+f}$ and their variances by $\mathrm{var}\left({\stackrel{^}{y}}_{t+f}\right)$. The term $\mathrm{var}\left({\epsilon }_{t}\right)$ is estimated as the mean deviation.
The parameters, $\alpha$, $\beta$ and $\gamma$ 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, $\varphi$, which acts as a trend dampener. For $0.0<\varphi <1.0$ the trend is dampened and for $\varphi >1.0$ the forecast function has an exponential trend, $\varphi =0.0$ removes the trend term from the forecast function and $\varphi =1.0$ does not dampen the trend.
For all methods, values for $\alpha$, $\beta$, $\gamma$ and $\psi$ 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 $\alpha$ can be obtained by fitting an $\mathrm{ARIMA}\left(0,1,1\right)$ model (see G13BEF). For Brown's double exponential smoothing and linear Holt smoothing with no dampening, (i.e., $\varphi =1.0$), suitable values for $\alpha$ and $\gamma$ can be obtained by fitting an $\mathrm{ARIMA}\left(0,2,2\right)$ model. Similarly, the linear Holt method, with $\varphi \ne 1.0$, can be expressed as an $\mathrm{ARIMA}\left(1,2,2\right)$ model and the additive Holt–Winters, with no dampening, ($\varphi =1.0$), can be expressed as a seasonal ARIMA model with order $p$ of the form $\mathrm{ARIMA}\left(0,1,p+1\right)\left(0,1,0\right)$. There is no similar procedure for obtaining parameter values for the multiplicative Holt–Winters method, or the additive Holt–Winters method with $\varphi \ne 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 $\alpha$, $\beta$, $\gamma$ and $\psi$, initial values, ${m}_{0}$, ${r}_{0}$ and ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,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 ${m}_{0}$. 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,\dots ,k$ as the independent variable. The intercept is then used to estimate ${m}_{0}$ and the slope to estimate ${r}_{0}$. 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 ${r}_{0}$ and the mean of the $p$ intercepts is used as the estimate of ${m}_{0}$. The seasonal parameters ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, are estimated as the $p$ intercepts – ${m}_{0}$. A similar approach is adopted for the multiplicative Holt–Winter's method.
One step ahead forecasts, ${\stackrel{^}{y}}_{t+1}$ are supplied along with the residuals computed as $\left({y}_{t+1}-{\stackrel{^}{y}}_{t+1}\right)$. 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.
${\mathbf{MODE}}=0$
Required values for ${m}_{0}$, ${r}_{0}$ and ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, are supplied in INIT.
${\mathbf{MODE}}=1$
G13AMF continues from a previous call using values that are supplied in R.
${\mathbf{MODE}}=2$
Required values for ${m}_{0}$, ${r}_{0}$ and ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, are estimated using the first $k$ observations.
Constraint: ${\mathbf{MODE}}=0$, $1$ or $2$.
2:     ITYPE – INTEGERInput
On entry: the smoothing function.
${\mathbf{ITYPE}}=1$
Single exponential.
${\mathbf{ITYPE}}=2$
Brown double exponential.
${\mathbf{ITYPE}}=3$
Linear Holt.
${\mathbf{ITYPE}}=4$
${\mathbf{ITYPE}}=5$
Multiplicative Holt–Winters.
Constraint: ${\mathbf{ITYPE}}=1$, $2$, $3$, $4$ or $5$.
3:     P – INTEGERInput
On entry: if ${\mathbf{ITYPE}}=4$ or $5$, the seasonal order, $p$, otherwise P is not referenced.
Constraint: if ${\mathbf{ITYPE}}=4$ or $5$, ${\mathbf{P}}>1$.
4:     PARAM($*$) – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array PARAM must be at least $1$ if ${\mathbf{ITYPE}}=1$ or $2$, $3$ if ${\mathbf{ITYPE}}=3$ and at least $4$ if ${\mathbf{ITYPE}}=4$ or $5$.
On entry: the smoothing parameters.
If ${\mathbf{ITYPE}}=1$ or $2$, ${\mathbf{PARAM}}\left(1\right)=\alpha$ and any remaining elements of PARAM are not referenced.
If ${\mathbf{ITYPE}}=3$, ${\mathbf{PARAM}}\left(1\right)=\alpha$, ${\mathbf{PARAM}}\left(2\right)=\gamma$, ${\mathbf{PARAM}}\left(3\right)=\varphi$ and any remaining elements of PARAM are not referenced.
If ${\mathbf{ITYPE}}=4$ or $5$, ${\mathbf{PARAM}}\left(1\right)=\alpha$, ${\mathbf{PARAM}}\left(2\right)=\gamma$, ${\mathbf{PARAM}}\left(3\right)=\beta$ and ${\mathbf{PARAM}}\left(4\right)=\varphi$.
Constraints:
• if ${\mathbf{ITYPE}}=1$, $0.0\le \alpha \le 1.0$;
• if ${\mathbf{ITYPE}}=2$, $0.0<\alpha \le 1.0$;
• if ${\mathbf{ITYPE}}=3$, $0.0\le \alpha \le 1.0$ and $0.0\le \gamma \le 1.0$ and $\varphi \ge 0.0$;
• if ${\mathbf{ITYPE}}=4$ or $5$, $0.0\le \alpha \le 1.0$ and $0.0\le \gamma \le 1.0$ and $0.0\le \beta \le 1.0$ and $\varphi \ge 0.0$.
5:     N – INTEGERInput
On entry: the number of observations in the series.
Constraint: ${\mathbf{N}}\ge 0$.
6:     Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the time series.
7:     K – INTEGERInput
On entry: if ${\mathbf{MODE}}=2$, the number of observations used to initialize the smoothing.
If ${\mathbf{MODE}}\ne 2$, K is not referenced.
Constraints:
• if ${\mathbf{MODE}}=2$ and ${\mathbf{ITYPE}}=4$ or $5$, $2×{\mathbf{P}}\le {\mathbf{K}}\le {\mathbf{N}}$;
• if ${\mathbf{MODE}}=2$ and ${\mathbf{ITYPE}}=1$, $2$ or $3$, $1\le {\mathbf{K}}\le {\mathbf{N}}$.
8:     INIT($*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the dimension of the array INIT must be at least $1$ if ${\mathbf{ITYPE}}=1$, $2$ if ${\mathbf{ITYPE}}=2$ or $3$ and at least $2+{\mathbf{P}}$ if ${\mathbf{ITYPE}}=4$ or $5$.
On entry: if ${\mathbf{MODE}}=0$, the initial values for ${m}_{0}$, ${r}_{0}$ and ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$, used to initialize the smoothing.
If ${\mathbf{ITYPE}}=1$, ${\mathbf{INIT}}\left(1\right)={m}_{0}$ and the remaining elements of INIT are not referenced.
If ${\mathbf{ITYPE}}=2$ or $3$, ${\mathbf{INIT}}\left(1\right)={m}_{0}$ and ${\mathbf{INIT}}\left(2\right)={r}_{0}$ and the remaining elements of INIT are not referenced.
If ${\mathbf{ITYPE}}=4$ or $5$, ${\mathbf{INIT}}\left(1\right)={m}_{0}$, ${\mathbf{INIT}}\left(2\right)={r}_{0}$ and ${\mathbf{INIT}}\left(3\right)$ to ${\mathbf{INIT}}\left(p+2\right)$ hold the values for ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$. The remaining elements of INIT are not referenced.
On exit: if ${\mathbf{MODE}}\ne 1$, 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: ${\mathbf{NF}}\ge 0$.
10:   FV(NF) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\stackrel{^}{y}}_{t+\mathit{f}}$, for $\mathit{f}=1,2,\dots ,{\mathbf{NF}}$, the next NF step forecasts. Where $t={\mathbf{N}}$, if ${\mathbf{MODE}}\ne 1$, 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: ${\stackrel{^}{y}}_{\mathit{t}+1}$, for $\mathit{t}=1,2,\dots ,{\mathbf{N}}$, the one step ahead forecast values, with ${\mathbf{YHAT}}\left(i\right)$ being the one step ahead forecast of ${\mathbf{Y}}\left(i-1\right)$.
13:   RES(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the residuals, $\left({y}_{\mathit{t}+1}-{\stackrel{^}{y}}_{\mathit{t}+1}\right)$, for $\mathit{t}=1,2,\dots ,{\mathbf{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 ${\mathbf{ITYPE}}=1$, $2$ or $3$ and at least $13+{\mathbf{P}}$ if ${\mathbf{ITYPE}}=4$ or $5$.
On entry: if ${\mathbf{MODE}}=1$, R must contain the values as returned by a previous call to G05PMF or G13AMF, R need not be set otherwise.
If ${\mathbf{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 ${\mathbf{MODE}}=1$, R must have been initialized by at least one previous call to G05PMF or G13AMF with ${\mathbf{MODE}}\ne 1$, 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\text{​ 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\text{​ 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 $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

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

## 7  Accuracy

Not applicable.

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.

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