# NAG FL Interfaceg05pmf (times_​smooth_​exp)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine g05pmf ( mode, n, p, init, var, r, e, en, x,
 Integer, Intent (In) :: mode, n, itype, p, en Integer, Intent (Inout) :: state(*), ifail Real (Kind=nag_wp), Intent (In) :: param(*), init(*), var, e(en) Real (Kind=nag_wp), Intent (Inout) :: r(*) Real (Kind=nag_wp), Intent (Out) :: x(n)
#include <nag.h>
 void g05pmf_ (const Integer *mode, const Integer *n, const Integer *itype, const Integer *p, const double param[], const double init[], const double *var, double r[], Integer state[], const double e[], const Integer *en, double x[], Integer *ifail)
The routine may be called by the names g05pmf or nagf_rand_times_smooth_exp.

## 3Description

g05pmf returns $\left\{{x}_{t}:t=1,2,\dots ,n\right\}$, a realization 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$
 $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.

## 4References

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

## 5Arguments

1: $\mathbf{mode}$Integer Input
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: $\mathbf{n}$Integer Input
On entry: the number of terms of the time series being generated.
Constraint: ${\mathbf{n}}\ge 0$.
3: $\mathbf{itype}$Integer Input
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: $\mathbf{p}$Integer Input
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: $\mathbf{param}\left(*\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{init}\left(*\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{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: $\mathbf{r}\left(*\right)$Real (Kind=nag_wp) array Communication Array
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: $\mathbf{state}\left(*\right)$Integer array Communication 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: $\mathbf{e}\left({\mathbf{en}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{en}$Integer Input
On entry: if ${\mathbf{en}}>0$, 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: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the generated time series, ${x}_{\mathit{t}}$, for $\mathit{t}=1,2,\dots ,n$.
13: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{mode}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{mode}}=0$, $1$ or $2$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 0$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{itype}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{itype}}=1$, $2$, $3$, $4$ or $5$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{p}}=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{itype}}=4$ or $5$, ${\mathbf{p}}\ge 2$.
${\mathbf{ifail}}=5$
On entry, ${\mathbf{param}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$.
Constraint: $0\le {\mathbf{param}}\left(i\right)\le 1$.
On entry, ${\mathbf{param}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$.
Constraint: if ${\mathbf{itype}}=2$, $0<{\mathbf{param}}\left(i\right)\le 1$.
On entry, ${\mathbf{param}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{param}}\left(i\right)\ge 0$.
${\mathbf{ifail}}=8$
On entry, some of the elements of the array r have been corrupted or have not been initialized.
${\mathbf{ifail}}=9$
On entry, state vector has been corrupted or not initialized.
${\mathbf{ifail}}=12$
Model unsuitable for multiplicative Holt–Winter, try a different set of parameters.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

g05pmf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

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.

### 10.1Program Text

Program Text (g05pmfe.f90)

### 10.2Program Data

Program Data (g05pmfe.d)

### 10.3Program Results

Program Results (g05pmfe.r)