hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_tsa_uni_smooth_exp (g13am)

Purpose

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

Syntax

[init, fv, fse, yhat, res, dv, ad, r, ifail] = g13am(mode, itype, p, param, y, k, init, nf, r, 'n', n)
[init, fv, fse, yhat, res, dv, ad, r, ifail] = nag_tsa_uni_smooth_exp(mode, itype, p, param, y, k, init, nf, r, 'n', n)

Description

Exponential smoothing is a relatively simple method of short term forecasting for a time series. nag_tsa_uni_smooth_exp (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 ytyt, for t = 1,2,,nt=1,2,,n, the five smoothing functions are defined by the following:
mt = α yt / s t-p + ( 1-α ) ( m t-1 +ϕ r t-1 ) rt = γ ( mt - m t-1 ) + ( 1-γ ) ϕ r t-1 st = β yt / mt + ( 1-β ) s t-p y^ t+f = ( mt + i=1 f ϕi rt ) × s t-p var( y^ t+f ) = var( εt ) ( i=0 j=0 p-1 ( ψ j+ip s t+f s t+f-j ) 2 )
and ψψ is defined as in the additive Holt–Winters smoothing, where mtmt is the mean, rtrt is the trend and stst is the seasonal component at time tt with pp being the seasonal order. The ff-step ahead forecasts are given by t + fy^t+f and their variances by var(t + f) var( y^ t+f ) . The term var(εt) 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.10.1 to 0.30.3. The linear Holt and two Holt–Winters smoothers include an additional parameter, φϕ, which acts as a trend dampener. For 0.0 < φ < 1.00.0<ϕ<1.0 the trend is dampened and for φ > 1.0ϕ>1.0 the forecast function has an exponential trend, φ = 0.0ϕ=0.0 removes the trend term from the forecast function and φ = 1.0ϕ=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 ARIMA(0,1,1)ARIMA(0,1,1) model (see nag_tsa_multi_inputmod_estim (g13be)). For Brown's double exponential smoothing and linear Holt smoothing with no dampening, (i.e., φ = 1.0ϕ=1.0), suitable values for αα and γγ can be obtained by fitting an ARIMA(0,2,2)ARIMA(0,2,2) model. Similarly, the linear Holt method, with φ1.0ϕ1.0, can be expressed as an ARIMA(1,2,2)ARIMA(1,2,2) model and the additive Holt–Winters, with no dampening, (φ = 1.0ϕ=1.0), can be expressed as a seasonal ARIMA model with order pp of the form ARIMA(0,1,p + 1)(0,1,0)ARIMA(0,1,p+1)(0,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ϕ1.0. In these cases parameters could be selected by minimizing a measure of fit using one of the nonlinear optimization functions in Chapter E04.
In addition to values for αα, ββ, γγ and ψψ, initial values, m0m0, r0r0 and sjs-j, for j = 0,1,,p1j=0,1,,p-1, are required to start the smoothing process. You can either supply these or they can be calculated by nag_tsa_uni_smooth_exp (g13am) from the first kk observations. For single exponential smoothing the mean of the observations is used to estimate m0m0. 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,,k1,2,,k as the independent variable. The intercept is then used to estimate m0m0 and the slope to estimate r0r0. 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 pp seasonal groupings. The slope gives an estimate for r0r0 and the mean of the pp intercepts is used as the estimate of m0m0. The seasonal parameters sjs-j, for j = 0,1,,p1j=0,1,,p-1, are estimated as the pp intercepts – m0m0. A similar approach is adopted for the multiplicative Holt–Winter's method.
One step ahead forecasts, t + 1 y^ t+1  are supplied along with the residuals computed as (yt + 1t + 1) ( yt+1 - y^ t+1 ) . In addition, two measures of fit are provided. The mean absolute deviation,
n
1/n |ytt|
t = 1
1 n t=1 n | yt - y^ t |
and the square root of the mean deviation
sqrt( 1/n t = 1n (ytt)2 ) .
1 n t=1 n ( yt - y^ t ) 2 .

References

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

Parameters

Compulsory Input Parameters

1:     mode – int64int32nag_int scalar
Indicates if nag_tsa_uni_smooth_exp (g13am) is continuing from a previous call or, if not, how the initial values are computed.
mode = 0mode=0
Required values for m0m0, r0r0 and sjs-j, for j = 0,1,,p1j=0,1,,p-1, are supplied in init.
mode = 1mode=1
nag_tsa_uni_smooth_exp (g13am) continues from a previous call using values that are supplied in r.
mode = 2mode=2
Required values for m0m0, r0r0 and sjs-j, for j = 0,1,,p1j=0,1,,p-1, are estimated using the first kk observations.
Constraint: mode = 0mode=0, 11 or 22.
2:     itype – int64int32nag_int scalar
The smoothing function.
itype = 1itype=1
Single exponential.
itype = 2itype=2
Brown double exponential.
itype = 3itype=3
Linear Holt.
itype = 4itype=4
Additive Holt–Winters.
itype = 5itype=5
Multiplicative Holt–Winters.
Constraint: itype = 1itype=1, 22, 33, 44 or 55.
3:     p – int64int32nag_int scalar
If itype = 4itype=4 or 55, the seasonal order, pp, otherwise p is not referenced.
Constraint: if itype = 4itype=4 or 55, p > 1p>1.
4:     param( : :) – double array
Note: the dimension of the array param must be at least 11 if itype = 1itype=1 or 22, 33 if itype = 3itype=3 and at least 44 if itype = 4itype=4 or 55.
The smoothing parameters.
If itype = 1itype=1 or 22, param(1) = αparam1=α and any remaining elements of param are not referenced.
If itype = 3itype=3, param(1) = αparam1=α, param(2) = γparam2=γ, param(3) = φparam3=ϕ and any remaining elements of param are not referenced.
If itype = 4itype=4 or 55, param(1) = αparam1=α, param(2) = γparam2=γ, param(3) = βparam3=β and param(4) = φparam4=ϕ.
Constraints:
  • if itype = 1itype=1, 0.0α1.00.0α1.0;
  • if itype = 2itype=2, 0.0 < α1.00.0<α1.0;
  • if itype = 3itype=3, 0.0α1.00.0α1.0 and 0.0γ1.00.0γ1.0 and φ0.0ϕ0.0;
  • if itype = 4itype=4 or 55, 0.0α1.00.0α1.0 and 0.0γ1.00.0γ1.0 and 0.0β1.00.0β1.0 and φ0.0ϕ0.0.
5:     y(n) – double array
n, the dimension of the array, must satisfy the constraint n0n0.
The time series.
6:     k – int64int32nag_int scalar
If mode = 2mode=2, the number of observations used to initialize the smoothing.
If mode2mode2, k is not referenced.
Constraints:
  • if mode = 2mode=2 and itype = 4itype=4 or 55, 2 × pkn2×pkn;
  • if mode = 2mode=2 and itype = 1itype=1, 22 or 33, 1kn1kn.
7:     init( : :) – double array
Note: the dimension of the array init must be at least 11 if itype = 1itype=1, 22 if itype = 2itype=2 or 33 and at least 2 + p2+p if itype = 4itype=4 or 55.
If mode = 0mode=0, the initial values for m0m0, r0r0 and sjs-j, for j = 0,1,,p1j=0,1,,p-1, used to initialize the smoothing.
If itype = 1itype=1, init(1) = m0init1=m0 and the remaining elements of init are not referenced.
If itype = 2itype=2 or 33, init(1) = m0init1=m0 and init(2) = r0init2=r0 and the remaining elements of init are not referenced.
If itype = 4itype=4 or 55, init(1) = m0init1=m0, init(2) = r0init2=r0 and init(3)init3 to init(p + 2)initp+2 hold the values for sjs-j, for j = 0,1,,p1j=0,1,,p-1. The remaining elements of init are not referenced.
8:     nf – int64int32nag_int scalar
The number of forecasts required beyond the end of the series. Note, the one step ahead forecast is always produced.
Constraint: nf0nf0.
9:     r( : :) – double array
Note: the dimension of the array r must be at least 1313 if itype = 1itype=1, 22 or 33 and at least 13 + p13+p if itype = 4itype=4 or 55.
If mode = 1mode=1, r must contain the values as returned by a previous call to nag_rand_times_smooth_exp (g05pm) or nag_tsa_uni_smooth_exp (g13am), r need not be set otherwise.
If itype = 1itype=1, 22 or 33, only the first 1313 elements of r are referenced, otherwise the first 13 + p13+p elements are referenced.
Constraint: if mode = 1mode=1, r must have been initialized by at least one previous call to nag_rand_times_smooth_exp (g05pm) or nag_tsa_uni_smooth_exp (g13am) with mode1mode1, and r should not have been changed since the last call to nag_rand_times_smooth_exp (g05pm) or nag_tsa_uni_smooth_exp (g13am).

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array y.
The number of observations in the series.
Constraint: n0n0.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     init( : :) – double array
Note: the dimension of the array init must be at least 11 if itype = 1itype=1, 22 if itype = 2itype=2 or 33 and at least 2 + p2+p if itype = 4itype=4 or 55.
If mode1mode1, the values used to initialize the smoothing. These are in the same order as described above.
2:     fv(nf) – double array
t + fy^t+f, for f = 1,2,,nff=1,2,,nf, the next nf step forecasts. Where t = nt=n, if mode1mode1, else tt is the total number of smoothed and forecast values already produced.
3:     fse(nf) – double array
The forecast standard errors for the values given in fv.
4:     yhat(n) – double array
t + 1y^t+1, for t = 1,2,,nt=1,2,,n, the one step ahead forecast values, with yhat(i)yhati being the one step ahead forecast of y(i1)yi-1.
5:     res(n) – double array
The residuals, (yt + 1t + 1) ( yt+1 - y^ t+1 ) , for t = 1,2,,nt=1,2,,n.
6:     dv – double scalar
The square root of the mean deviation.
7:     ad – double scalar
The mean absolute deviation.
8:     r( : :) – double array
Note: the dimension of the array r must be at least 1313 if itype = 1itype=1, 22 or 33 and at least 13 + p13+p if itype = 4itype=4 or 55.
The information on the current state of the smoothing.
9:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,mode < 0mode<0,
ormode > 2mode>2.
  ifail = 2ifail=2
On entry,itype < 1itype<1,
oritype > 5itype>5.
  ifail = 3ifail=3
On entry,itype = 4itype=4 or 55 and p < 2p<2.
  ifail = 4ifail=4
On entry, at least one of αα, ββ or γ < 0.0γ<0.0 or > 1.0>1.0.
On entry, itype = 2itype=2 and α = 0.0α=0.0.
On entry, φ < 0.0ϕ<0.0.
  ifail = 5ifail=5
On entry,n < 0n<0.
  ifail = 6ifail=6
A multiplicative Holt–Winters model cannot be used with the supplied data.
  ifail = 7ifail=7
On entry, mode = 2mode=2 and k < 1k<1 or k > nk>n.
On entry, mode = 2mode=2, itype = 4itype=4 or 55 and k < 2 × pk<2×p.
  ifail = 9ifail=9
On entry,nf < 0nf<0.
  ifail = 16ifail=16
On entry, mode = 1mode=1 and the array r has not been initialized correctly.

Accuracy

Not applicable.

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 function document for nag_rand_times_smooth_exp (g05pm).

Example

function nag_tsa_uni_smooth_exp_example
mode = int64(2);
itype = int64(3);
p = int64(0);
param = [0.01;
     1;
     1];
y = [180;
     135;
     213;
     181;
     148;
     204;
     228;
     225;
     198;
     200;
     187];
k = int64(11);
init = [-1.666051209955092e-47;
     4.853144920788553e-270];
nf = int64(5);
r = [1.910201800633982e-313;
     -1.601103737937077e-47;
     -1.678629904873684e-47;
     -4.300360784598706e-39;
     -0.09138826798201372;
     -1.668172686220112e-47;
     2.572155976556066e-306;
     -1.601102994801293e-47;
     4.940656458412465e-324;
     2.514055054265363e-306;
     -4.296977237061931e-39;
     2.514055056853075e-306;
     -4.300811189660317e-39];
[initOut, fv, fse, yhat, res, dv, ad, rOut, ifail] = ...
    nag_tsa_uni_smooth_exp(mode, itype, p, param, y, k, init, nf, r)
 

initOut =

  168.0182
    3.8000


fv =

  213.8545
  217.6851
  221.5157
  225.3462
  229.1768


fse =

   25.4733
   25.4784
   25.4899
   25.5102
   25.5420


yhat =

  171.8182
  175.7818
  178.8480
  183.0050
  186.7805
  189.8003
  193.4920
  197.7318
  202.1719
  206.2559
  210.2565


res =

    8.1818
  -40.7818
   34.1520
   -2.0050
  -38.7805
   14.1997
   34.5080
   27.2682
   -4.1719
   -6.2559
  -23.2565


dv =

   25.4733


ad =

   21.2328


rOut =

   1.0e+03 *

    2.4680
         0
    0.0000
    0.0010
         0
    0.0010
         0
    7.1378
    0.2336
    0.2100
    0.0038
    0.0110
         0


ifail =

                    0


function g13am_example
mode = int64(2);
itype = int64(3);
p = int64(0);
param = [0.01;
     1;
     1];
y = [180;
     135;
     213;
     181;
     148;
     204;
     228;
     225;
     198;
     200;
     187];
k = int64(11);
init = [-1.666051209955092e-47;
     4.853144920788553e-270];
nf = int64(5);
r = [1.910201800633982e-313;
     -1.601103737937077e-47;
     -1.678629904873684e-47;
     -4.300360784598706e-39;
     -0.09138826798201372;
     -1.668172686220112e-47;
     2.572155976556066e-306;
     -1.601102994801293e-47;
     4.940656458412465e-324;
     2.514055054265363e-306;
     -4.296977237061931e-39;
     2.514055056853075e-306;
     -4.300811189660317e-39];
[initOut, fv, fse, yhat, res, dv, ad, rOut, ifail] = g13am(mode, itype, p, param, y, k, init, nf, r)
 

initOut =

  168.0182
    3.8000


fv =

  213.8545
  217.6851
  221.5157
  225.3462
  229.1768


fse =

   25.4733
   25.4784
   25.4899
   25.5102
   25.5420


yhat =

  171.8182
  175.7818
  178.8480
  183.0050
  186.7805
  189.8003
  193.4920
  197.7318
  202.1719
  206.2559
  210.2565


res =

    8.1818
  -40.7818
   34.1520
   -2.0050
  -38.7805
   14.1997
   34.5080
   27.2682
   -4.1719
   -6.2559
  -23.2565


dv =

   25.4733


ad =

   21.2328


rOut =

   1.0e+03 *

    2.4680
         0
    0.0000
    0.0010
         0
    0.0010
         0
    7.1378
    0.2336
    0.2100
    0.0038
    0.0110
         0


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013