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

Syntax

C#
public static void g05pm(
	int mode,
	int n,
	int itype,
	int p,
	double[] param,
	double[] init,
	double var,
	double[] r,
	G05..::..G05State g05state,
	double[] e,
	int en,
	double[] x,
	out int ifail
)
Visual Basic
Public Shared Sub g05pm ( _
	mode As Integer, _
	n As Integer, _
	itype As Integer, _
	p As Integer, _
	param As Double(), _
	init As Double(), _
	var As Double, _
	r As Double(), _
	g05state As G05..::..G05State, _
	e As Double(), _
	en As Integer, _
	x As Double(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g05pm(
	int mode, 
	int n, 
	int itype, 
	int p, 
	array<double>^ param, 
	array<double>^ init, 
	double var, 
	array<double>^ r, 
	G05..::..G05State^ g05state, 
	array<double>^ e, 
	int en, 
	array<double>^ x, 
	[OutAttribute] int% ifail
)
F#
static member g05pm : 
        mode : int * 
        n : int * 
        itype : int * 
        p : int * 
        param : float[] * 
        init : float[] * 
        var : float * 
        r : float[] * 
        g05state : G05..::..G05State * 
        e : float[] * 
        en : int * 
        x : float[] * 
        ifail : int byref -> unit 

Parameters

mode
Type: System..::..Int32
On entry: indicates if g05pm 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
g05pm continues from a previous call using values that are supplied in r. r is not updated.
mode=2
g05pm continues from a previous call using values that are supplied in r. r is updated.
Constraint: mode=0, 1 or 2.
n
Type: System..::..Int32
On entry: the number of terms of the time series being generated.
Constraint: n0.
itype
Type: System..::..Int32
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.
p
Type: System..::..Int32
On entry: if itype=4 or 5, the seasonal order, p, otherwise p is not referenced.
Constraint: if itype=4 or 5, p>1.
param
Type: array<System..::..Double>[]()[][]
An array of size [_lparam]
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, param[0]=α and any remaining elements of param are not referenced.
If itype=3, param[0]=α, param[1]=γ, param[2]=ϕ and any remaining elements of param are not referenced.
If itype=4 or 5, param[0]=α, param[1]=γ, param[2]=β and param[3]=ϕ 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.
init
Type: array<System..::..Double>[]()[][]
An array of size [_linit]
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, init[0]=m0 and any remaining elements of init are not referenced.
If itype=2 or 3, init[0]=m0 and init[1]=r0 and any remaining elements of init are not referenced.
If itype=4 or 5, init[0]=m0, init[1]=r0 and init[2] to init[2+p-1] hold the values for s-j, for j=0,1,,p-1. Any remaining elements of init are not referenced.
var
Type: System..::..Double
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.
r
Type: array<System..::..Double>[]()[][]
An array of size [_lr]
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 g05pm, 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 g05pm or g13am with mode1, and r must not have been changed since that call.
g05state
Type: NagLibrary..::..G05..::..G05State
An Object of type G05.G05State.
e
Type: array<System..::..Double>[]()[][]
An array of size [en]
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.
en
Type: System..::..Int32
On entry: if en>0, then the length of the vector e.
If both var0.0 and en0 then εt=0.0, for t=1,2,,n.
x
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the generated time series, xt, for t=1,2,,n.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

Description

g05pm returns xt:t=1,2,,n, a realization of a time series from an exponential smoothing model defined by one of five smoothing functions:
  • Single Exponential Smoothing
    xt=mt-1+εtmt=αxt+1-αmt-1
  • Brown Double Exponential Smoothing
    xt=mt-1+rt-1α+εtmt=αxt+1-αmt-1rt=αmt-mt-1+1-αrt-1
  • Linear Holt Exponential Smoothing
    xt=mt-1+ϕrt-1+εtmt=αxt+1-αmt-1+ϕrt-1rt=γmt-mt-1+1-γϕrt-1
  • Additive Holt–Winters Smoothing
    xt=mt-1+ϕrt-1+st-1-p+εtmt=αxt-st-p+1-αmt-1+ϕrt-1rt=γmt-mt-1+1-γϕrt-1st=βxt-mt+1-βst-p
  • Multiplicative Holt–Winters Smoothing
    xt=mt-1+ϕrt-1×st-1-p+εtmt=αxt/st-p+1-αmt-1+ϕrt-1rt=γmt-mt-1+1-γϕrt-1st=βxt/mt+1-βst-p
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.

References

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

Error Indicators and Warnings

Errors or warnings detected by the method:
ifail=1
On entry, mode0, 1 or 2.
ifail=2
On entry, itype1, 2, 3, 4 or 5.
ifail=3
On entry,itype=4 or 5 and p<2.
ifail=4
On entry, at least one of α, β or γ>0.0 or >1.0.
On entry, itype=2 and α=0.0.
On entry, ϕ<0.0.
ifail=5
On entry,n<0.
ifail=8
On entry,mode=1 or 2 and the array r has not been initialized correctly.
ifail=9
On entry, the array state has not been initialized correctly.
ifail=12
itype=5 and model is unsuitable for multiplicative Holt–Winter.
ifail=-9000
An error occured, see message report.
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

Not applicable.

Parallelism and Performance

None.

Further Comments

None.

Example

g05pm is then called multiple times to obtain simulated forecast confidence intervals.

Example program (C#): g05pme.cs

Example program data: g05pme.d

Example program results: g05pme.r

See Also