G05 Chapter Contents
G05 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG05PMF

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

G05PMF simulates from an exponential smoothing model, where the model uses either single exponential, double exponential or a Holt–Winters method.

## 2  Specification

 SUBROUTINE G05PMF ( MODE, N, ITYPE, P, PARAM, INIT, VAR, R, STATE, E, EN, X, IFAIL)
 INTEGER MODE, N, ITYPE, P, STATE(*), EN, IFAIL REAL (KIND=nag_wp) PARAM(*), INIT(*), VAR, R(*), E(EN), X(N)

## 3  Description

G05PMF returns $\left\{{x}_{t}:t=1,2,\dots ,n\right\}$, a realisation of a time series from an exponential smoothing model defined by one of five smoothing functions:
• Single Exponential Smoothing
 $xt = mt-1 + εt mt = α xt + 1-α mt-1$
• Brown Double Exponential Smoothing
 $xt = mt-1 + rt-1 α + εt mt = α xt + 1-α mt-1 rt = α mt - mt-1 + 1-α rt-1$
• Linear Holt Exponential Smoothing
 $xt = mt-1 + ϕrt-1 + εt mt = α xt + 1-α mt-1 + ϕ rt-1 rt = γ mt - mt-1 + 1-γ ϕ rt-1$
• Additive Holt–Winters Smoothing
 $xt = mt-1 + ϕrt-1 + st-1-p + εt mt = α xt - s t-p + 1-α m t-1 +ϕ r t-1 rt = γ mt - m t-1 + 1-γ ϕ rt-1 st = β xt - mt + 1-β s t-p$
• Multiplicative Holt–Winters Smoothing
 $xt = mt-1 + ϕrt-1 × s t-1-p + εt mt = α xt / s t-p + 1-α m t-1 +ϕ r t-1 rt = γ mt - m t-1 + 1-γ ϕ r t-1 st = β xt / mt + 1-β s t-p$
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 errors, ${\epsilon }_{t}$ are either drawn from a normal distribution with mean zero and variance ${\sigma }^{2}$ or randomly sampled, with replacement, from a user-supplied vector.

## 4  References

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

## 5  Parameters

1:     MODE – INTEGERInput
On entry: indicates if G05PMF is continuing from a previous call or, if not, how the initial values are computed.
${\mathbf{MODE}}=0$
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$
G05PMF continues from a previous call using values that are supplied in R. R is not updated.
${\mathbf{MODE}}=2$
G05PMF continues from a previous call using values that are supplied in R. R is updated.
Constraint: ${\mathbf{MODE}}=0$, $1$ or $2$.
2:     N – INTEGERInput
On entry: the number of terms of the time series being generated.
Constraint: ${\mathbf{N}}\ge 0$.
3:     ITYPE – INTEGERInput
On entry: the smoothing function.
${\mathbf{ITYPE}}=1$
Single exponential.
${\mathbf{ITYPE}}=2$
Brown's 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$.
4:     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$.
5:     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$ and any remaining elements of PARAM are not referenced.
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$.
6:     INIT($*$) – REAL (KIND=nag_wp) arrayInput
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 any 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 any 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(2+p\right)$ hold the values for ${s}_{-\mathit{j}}$, for $\mathit{j}=0,1,\dots ,p-1$. Any remaining elements of INIT are not referenced.
7:     VAR – REAL (KIND=nag_wp)Input
On entry: the variance, ${\sigma }^{2}$ of the Normal distribution used to generate the errors ${\epsilon }_{i}$. If ${\mathbf{VAR}}\le 0.0$ then Normally distributed errors are not used.
8:     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$ or $2$, R must contain the values as returned by a previous call to G05PMF, R need not be set otherwise.
On exit: if ${\mathbf{MODE}}=1$, R is unchanged. Otherwise, R contains the information on the current state of smoothing.
Constraint: if ${\mathbf{MODE}}=1$ or $2$, R must have been initialized by at least one call to G05PMF or G13AMF with ${\mathbf{MODE}}\ne 1$, and R must not have been changed since that call.
9:     STATE($*$) – INTEGER arrayCommunication Array
Note: the actual argument supplied must be the array STATE supplied to the initialization routines G05KFF or G05KGF.
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
10:   E(EN) – REAL (KIND=nag_wp) arrayInput
On entry: if ${\mathbf{EN}}>0$ and ${\mathbf{VAR}}\le 0.0$, a vector from which the errors, ${\epsilon }_{t}$ are randomly drawn, with replacement.
If ${\mathbf{EN}}\le 0$, E is not referenced.
11:   EN – INTEGERInput
On entry: if ${\mathbf{EN}}>0$, then the length of the vector E.
If both ${\mathbf{VAR}}\le 0.0$ and ${\mathbf{EN}}\le 0$ then ${\epsilon }_{\mathit{t}}=0.0$, for $\mathit{t}=1,2,\dots ,n$.
12:   X(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the generated time series, ${x}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,n$.
13:   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}}\ne 0$, $1$ or $2$.
${\mathbf{IFAIL}}=2$
On entry, ${\mathbf{ITYPE}}\ne 1$, $2$, $3$, $4$ or $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}}=8$
 On entry, ${\mathbf{MODE}}=1$ or $2$ and the array R has not been initialized correctly.
${\mathbf{IFAIL}}=9$
On entry, the array STATE has not been initialized correctly.
${\mathbf{IFAIL}}=12$
${\mathbf{ITYPE}}=5$ and model is unsuitable for multiplicative Holt–Winter.

Not applicable.

None.

## 9  Example

This example reads $11$ observations from a time series relating to the rate of the earth's rotation about its polar axis and fits an exponential smoothing model using G13AMF.
G05PMF is then called multiple times to obtain simulated forecast confidence intervals.

### 9.1  Program Text

Program Text (g05pmfe.f90)

### 9.2  Program Data

Program Data (g05pmfe.d)

### 9.3  Program Results

Program Results (g05pmfe.r)