NAG FL Interface
g05pmf (times_​smooth_​exp)

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

Fortran Interface
Subroutine g05pmf ( mode, n, itype, p, param, init, var, r, state, e, en, x, ifail)
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)
C Header Interface
#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.

3 Description

g05pmf returns xt:t=1,2,,n, a realization of a time series from an exponential smoothing model defined by one of five smoothing functions: 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 errors, εt are either drawn from a normal distribution with mean zero and variance σ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 Arguments

1: mode Integer Input
On entry: indicates if g05pmf is continuing from a previous call or, if not, how the initial values are computed.
mode=0
Values for m0, r0 and s-j, for j=0,1,,p-1, are supplied in init.
mode=1
g05pmf continues from a previous call using values that are supplied in r. r is not updated.
mode=2
g05pmf continues from a previous call using values that are supplied in r. r is updated.
Constraint: mode=0, 1 or 2.
2: n Integer Input
On entry: the number of terms of the time series being generated.
Constraint: n0.
3: itype Integer Input
On entry: the smoothing function.
itype=1
Single exponential.
itype=2
Brown's double exponential.
itype=3
Linear Holt.
itype=4
Additive Holt–Winters.
itype=5
Multiplicative Holt–Winters.
Constraint: itype=1, 2, 3, 4 or 5.
4: 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.
5: 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=ϕ and any remaining elements of param are not referenced.
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.
6: init* Real (Kind=nag_wp) array Input
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 any remaining elements of init are not referenced.
If itype=2 or 3, init1=m0 and init2=r0 and any remaining elements of init are not referenced.
If itype=4 or 5, init1=m0, init2=r0 and init3 to init2+p hold the values for s-j, for j=0,1,,p-1. Any remaining elements of init are not referenced.
7: var Real (Kind=nag_wp) Input
On entry: the variance, σ2 of the Normal distribution used to generate the errors εi. If var0.0 then Normally distributed errors are not used.
8: 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 or 2, r must contain the values as returned by a previous call to g05pmf, r need not be set otherwise.
On exit: if mode=1, r is unchanged. Otherwise, r contains the information on the current state of smoothing.
Constraint: if mode=1 or 2, r must have been initialized by at least one call to g05pmf or g13amf with mode1, and r must not have been changed since that call.
9: state* 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: een Real (Kind=nag_wp) array Input
On entry: if en>0 and var0.0, a vector from which the errors, εt are randomly drawn, with replacement.
If en0, e is not referenced.
11: en Integer Input
On entry: if en>0, the length of the vector e.
If both var0.0 and en0 then εt=0.0, for t=1,2,,n.
12: xn Real (Kind=nag_wp) array Output
On exit: the generated time series, xt, for t=1,2,,n.
13: 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 -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, n=value.
Constraint: n0.
ifail=3
On entry, itype=value.
Constraint: itype=1, 2, 3, 4 or 5.
ifail=4
On entry, p=value.
Constraint: if itype=4 or 5, p2.
ifail=5
On entry, paramvalue=value.
Constraint: 0parami1.
On entry, paramvalue=value.
Constraint: if itype=2, 0<parami1.
On entry, paramvalue=value.
Constraint: parami0.
ifail=8
On entry, some of the elements of the array r have been corrupted or have not been initialized.
ifail=9
On entry, state vector has been corrupted or not initialized.
ifail=12
Model unsuitable for multiplicative Holt–Winter, try a different set of parameters.
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

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.

9 Further Comments

None.

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

10.1 Program Text

Program Text (g05pmfe.f90)

10.2 Program Data

Program Data (g05pmfe.d)

10.3 Program Results

Program Results (g05pmfe.r)
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 100 150 200 250 300 350 0 5 10 15 20 25 30 35 Data Time Example Program Exponential Smoothing (95% confidence intervals (CIs) are shown) gnuplot_plot_1 observed gnuplot_plot_2 smoothed gnuplot_plot_3 forecast gnuplot_plot_4 estimated CI gnuplot_plot_5 gnuplot_plot_6 simulated CI gnuplot_plot_7 gnuplot_plot_8 bootstrapped CI gnuplot_plot_9