g13am performs exponential smoothing using either single exponential, double exponential or a Holt–Winters method.

Syntax

C#
public static void g13am(
	int mode,
	int itype,
	int p,
	double[] param,
	int n,
	double[] y,
	int k,
	double[] init,
	int nf,
	double[] fv,
	double[] fse,
	double[] yhat,
	double[] res,
	out double dv,
	out double ad,
	double[] r,
	out int ifail
)
Visual Basic
Public Shared Sub g13am ( _
	mode As Integer, _
	itype As Integer, _
	p As Integer, _
	param As Double(), _
	n As Integer, _
	y As Double(), _
	k As Integer, _
	init As Double(), _
	nf As Integer, _
	fv As Double(), _
	fse As Double(), _
	yhat As Double(), _
	res As Double(), _
	<OutAttribute> ByRef dv As Double, _
	<OutAttribute> ByRef ad As Double, _
	r As Double(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g13am(
	int mode, 
	int itype, 
	int p, 
	array<double>^ param, 
	int n, 
	array<double>^ y, 
	int k, 
	array<double>^ init, 
	int nf, 
	array<double>^ fv, 
	array<double>^ fse, 
	array<double>^ yhat, 
	array<double>^ res, 
	[OutAttribute] double% dv, 
	[OutAttribute] double% ad, 
	array<double>^ r, 
	[OutAttribute] int% ifail
)
F#
static member g13am : 
        mode : int * 
        itype : int * 
        p : int * 
        param : float[] * 
        n : int * 
        y : float[] * 
        k : int * 
        init : float[] * 
        nf : int * 
        fv : float[] * 
        fse : float[] * 
        yhat : float[] * 
        res : float[] * 
        dv : float byref * 
        ad : float byref * 
        r : float[] * 
        ifail : int byref -> unit 

Parameters

mode
Type: System..::..Int32
On entry: indicates if g13am is continuing from a previous call or, if not, how the initial values are computed.
mode=0
Required values for m0, r0 and s-j, for j=0,1,,p-1, are supplied in init.
mode=1
g13am continues from a previous call using values that are supplied in r.
mode=2
Required values for m0, r0 and s-j, for j=0,1,,p-1, are estimated using the first k observations.
Constraint: mode=0, 1 or 2.
itype
Type: System..::..Int32
On entry: the smoothing function.
itype=1
Single exponential.
itype=2
Brown 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]=ϕ.
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.
n
Type: System..::..Int32
On entry: the number of observations in the series.
Constraint: n0.
y
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: the time series.
k
Type: System..::..Int32
On entry: if mode=2, the number of observations used to initialize the smoothing.
If mode2, k is not referenced.
Constraints:
  • if mode=2 and itype=4 or 5, 2×pkn;
  • if mode=2 and itype=1, 2 or 3, 1kn.
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 the remaining elements of init are not referenced.
If itype=2 or 3, init[0]=m0 and init[1]=r0 and the remaining elements of init are not referenced.
If itype=4 or 5, init[0]=m0, init[1]=r0 and init[2] to init[p+1] hold the values for s-j, for j=0,1,,p-1. The remaining elements of init are not referenced.
On exit: if mode1, the values used to initialize the smoothing. These are in the same order as described above.
nf
Type: System..::..Int32
On entry: the number of forecasts required beyond the end of the series. Note, the one step ahead forecast is always produced.
Constraint: nf0.
fv
Type: array<System..::..Double>[]()[][]
An array of size [nf]
On exit: y^t+f, for f=1,2,,nf, the next nf step forecasts. Where t=n, if mode1, else t is the total number of smoothed and forecast values already produced.
fse
Type: array<System..::..Double>[]()[][]
An array of size [nf]
On exit: the forecast standard errors for the values given in fv.
yhat
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: y^t+1, for t=1,2,,n, the one step ahead forecast values, with yhat[i-1] being the one step ahead forecast of y[i-2].
res
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the residuals, yt+1-y^t+1, for t=1,2,,n.
dv
Type: System..::..Double%
On exit: the square root of the mean deviation.
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, r must contain the values as returned by a previous call to g05pm or g13am, r need not be set otherwise.
If 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 mode=1, r must have been initialized by at least one previous call to g05pm or g13am with mode1, and r should not have been changed since the last call to g05pm or g13am.
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

Exponential smoothing is a relatively simple method of short term forecasting for a time series. g13am 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 yt, for t=1,2,,n, the five smoothing functions are defined by the following:
  • Single Exponential Smoothing
    mt=αyt+1-αmt-1y^t+f=mtvary^t+f=varεt1+f-1α2
  • Brown Double Exponential Smoothing
    mt=αyt+1-αmt-1rt=αmt-mt-1+1-αrt-1y^t+f=mt+f-1+1/αrtvary^t+f=varεt1+ i=0 f-1 2α+i-1α22
  • Linear Holt Smoothing
    mt=αyt+1-αmt-1+ϕrt-1rt=γmt-mt-1+1-γϕrt-1y^t+f=mt+ i=1 f ϕirtvary^t+f=varεt1+ i=1 f-1 α+αγϕϕi-1ϕ-12
  • Additive Holt–Winters Smoothing
    mt=αyt-st-p+1-αmt-1+ϕrt-1rt=γmt-mt-1+1-γϕrt-1st=βyt-mt+1-βst-py^t+f=mt+ i=1 f ϕirt+st-pvary^t+f=varεt1+ i=1 f-1 ψi2ψi=0if ​ifα+αγϕϕi-1ϕ-1if ​i mod p0α+αγϕϕi-1ϕ-1+β1-αotherwise
  • Multiplicative Holt–Winters Smoothing
    mt=αyt/st-p+1-αmt-1+ϕrt-1rt=γmt-mt-1+1-γϕrt-1st=βyt/mt+1-βst-py^t+f=mt+ i=1 f ϕirt×st-pvary^t+f=varεt i=0 j=0 p-1 ψj+ipst+fst+f-j2
    and ψ is defined as in the additive Holt–Winters smoothing,
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 f-step ahead forecasts are given by y^t+f and their variances by vary^t+f. The term varεt is estimated as the mean deviation.
The parameters, α, β and γ 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, ϕ, which acts as a trend dampener. For 0.0<ϕ<1.0 the trend is dampened and for ϕ>1.0 the forecast function has an exponential trend, ϕ=0.0 removes the trend term from the forecast function and ϕ=1.0 does not dampen the trend.
For all methods, values for α, β, γ and ψ 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 α can be obtained by fitting an ARIMA0,1,1 model (see g13be). For Brown's double exponential smoothing and linear Holt smoothing with no dampening, (i.e., ϕ=1.0), suitable values for α and γ can be obtained by fitting an ARIMA0,2,2 model. Similarly, the linear Holt method, with ϕ1.0, can be expressed as an ARIMA1,2,2 model and the additive Holt–Winters, with no dampening, (ϕ=1.0), can be expressed as a seasonal ARIMA model with order p of the form ARIMA0,1,p+10,1,0. There is no similar procedure for obtaining parameter values for the multiplicative Holt–Winters method, or the additive Holt–Winters method with ϕ1.0. In these cases parameters could be selected by minimizing a measure of fit using one of the nonlinear optimization methods in E04 class.
In addition to values for α, β, γ and ψ, initial values, m0, r0 and s-j, for j=0,1,,p-1, are required to start the smoothing process. You can either supply these or they can be calculated by g13am from the first k observations. For single exponential smoothing the mean of the observations is used to estimate m0. 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,,k as the independent variable. The intercept is then used to estimate m0 and the slope to estimate r0. 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 r0 and the mean of the p intercepts is used as the estimate of m0. The seasonal parameters s-j, for j=0,1,,p-1, are estimated as the p intercepts – m0. A similar approach is adopted for the multiplicative Holt–Winter's method.
One step ahead forecasts, y^t+1 are supplied along with the residuals computed as yt+1-y^t+1. In addition, two measures of fit are provided. The mean absolute deviation,
1n t=1 n yt-y^t
and the square root of the mean deviation
1n t=1 n yt-y^t2.

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,mode<0,
ormode>2.
ifail=2
On entry,itype<1,
oritype>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=6
A multiplicative Holt–Winters model cannot be used with the supplied data.
ifail=7
On entry, mode=2 and k<1 or k>n.
On entry, mode=2, itype=4 or 5 and k<2×p.
ifail=9
On entry,nf<0.
ifail=16
On entry, mode=1 and the array r has not been initialized correctly.
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

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.
See also the method document for g05pm.

Example

This example smooths a time series relating to the rate of the earth's rotation about its polar axis.

Example program (C#): g13ame.cs

Example program data: g13ame.d

Example program results: g13ame.r

See Also