NAG FL Interface
g13amf (uni_smooth_exp)
1
Purpose
g13amf performs exponential smoothing using either single exponential, double exponential or a Holt–Winters method.
2
Specification
Fortran Interface
Subroutine g13amf ( |
mode, itype, p, param, n, y, k, init, nf, fv, fse, yhat, res, dv, ad, r, ifail) |
Integer, Intent (In) |
:: |
mode, itype, p, n, k, nf |
Integer, Intent (Inout) |
:: |
ifail |
Real (Kind=nag_wp), Intent (In) |
:: |
param(*), y(n) |
Real (Kind=nag_wp), Intent (Inout) |
:: |
init(*), r(*) |
Real (Kind=nag_wp), Intent (Out) |
:: |
fv(nf), fse(nf), yhat(n), res(n), dv, ad |
|
C Header Interface
#include <nag.h>
void |
g13amf_ (const Integer *mode, const Integer *itype, const Integer *p, const double param[], const Integer *n, const double y[], const Integer *k, double init[], const Integer *nf, double fv[], double fse[], double yhat[], double res[], double *dv, double *ad, double r[], Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
g13amf_ (const Integer &mode, const Integer &itype, const Integer &p, const double param[], const Integer &n, const double y[], const Integer &k, double init[], const Integer &nf, double fv[], double fse[], double yhat[], double res[], double &dv, double &ad, double r[], Integer &ifail) |
}
|
The routine may be called by the names g13amf or nagf_tsa_uni_smooth_exp.
3
Description
Exponential smoothing is a relatively simple method of short term forecasting for a time series. g13amf 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
, for
, the five smoothing functions are defined by the following:
- Single Exponential Smoothing
- Brown Double Exponential Smoothing
- Linear Holt Smoothing
- Additive Holt–Winters Smoothing
- Multiplicative Holt–Winters Smoothing
and is defined as in the additive Holt–Winters smoothing,
where
is the mean,
is the trend and
is the seasonal component at time
with
being the seasonal order. The
-step ahead forecasts are given by
and their variances by
. The term
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 to . The linear Holt and two Holt–Winters smoothers include an additional parameter, , which acts as a trend dampener. For the trend is dampened and for the forecast function has an exponential trend, removes the trend term from the forecast function and 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
model (see
g13bef). For Brown's double exponential smoothing and linear Holt smoothing with no dampening, (i.e.,
), suitable values for
and
can be obtained by fitting an
model. Similarly, the linear Holt method, with
, can be expressed as an
model and the additive Holt–Winters, with no dampening, (
), can be expressed as a seasonal ARIMA model with order
of the form
. There is no similar procedure for obtaining parameter values for the multiplicative Holt–Winters method, or the additive Holt–Winters method with
. In these cases parameters could be selected by minimizing a measure of fit using one of the nonlinear optimization routines in
Chapter E04.
In addition to values for , , and , initial values, , and , for , are required to start the smoothing process. You can either supply these or they can be calculated by g13amf from the first observations. For single exponential smoothing the mean of the observations is used to estimate . 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 as the independent variable. The intercept is then used to estimate and the slope to estimate . 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 seasonal groupings. The slope gives an estimate for and the mean of the intercepts is used as the estimate of . The seasonal parameters , for , are estimated as the intercepts – . A similar approach is adopted for the multiplicative Holt–Winter's method.
One step ahead forecasts,
are supplied along with the residuals computed as
. In addition, two measures of fit are provided. The mean absolute deviation,
and the square root of the mean deviation
4
References
Chatfield C (1980) The Analysis of Time Series Chapman and Hall
5
Arguments
-
1:
– Integer
Input
-
On entry: indicates if
g13amf is continuing from a previous call or, if not, how the initial values are computed.
- Required values for , and
, for , are supplied in init.
- g13amf continues from a previous call using values that are supplied in r.
- Required values for , and
, for , are estimated using the first observations.
Constraint:
, or .
-
2:
– Integer
Input
-
On entry: the smoothing function.
- Single exponential.
- Brown double exponential.
- Linear Holt.
- Additive Holt–Winters.
- Multiplicative Holt–Winters.
Constraint:
, , , or .
-
3:
– Integer
Input
-
On entry: if
or
, the seasonal order,
, otherwise
p is not referenced.
Constraint:
if or , .
-
4:
– Real (Kind=nag_wp) array
Input
Note: the dimension of the array
param
must be at least
if
or
,
if
and at least
if
or
.
On entry: the smoothing parameters.
If
or
,
and any remaining elements of
param are not referenced.
If
,
,
,
and any remaining elements of
param are not referenced.
If or , , , and .
Constraints:
- if , ;
- if , ;
- if , and and ;
- if or , and and and .
-
5:
– Integer
Input
-
On entry: the number of observations in the series.
Constraint:
.
-
6:
– Real (Kind=nag_wp) array
Input
-
On entry: the time series.
-
7:
– Integer
Input
-
On entry: if
, the number of observations used to initialize the smoothing.
If
,
k is not referenced.
Constraints:
- if and or , ;
- if and , or , .
-
8:
– Real (Kind=nag_wp) array
Input/Output
Note: the dimension of the array
init
must be at least
if
,
if
or
and at least
if
or
.
On entry: if
, the initial values for
,
and
, for
, used to initialize the smoothing.
If
,
and the remaining elements of
init are not referenced.
If
or
,
and
and the remaining elements of
init are not referenced.
If
or
,
,
and
to
hold the values for
, for
. The remaining elements of
init are not referenced.
On exit: if , the values used to initialize the smoothing. These are in the same order as described above.
-
9:
– Integer
Input
-
On entry: the number of forecasts required beyond the end of the series. Note, the one step ahead forecast is always produced.
Constraint:
.
-
10:
– Real (Kind=nag_wp) array
Output
-
On exit:
, for
, the next
nf step forecasts. Where
, if
, else
is the total number of smoothed and forecast values already produced.
-
11:
– Real (Kind=nag_wp) array
Output
-
On exit: the forecast standard errors for the values given in
fv.
-
12:
– Real (Kind=nag_wp) array
Output
-
On exit: , for , the one step ahead forecast values, with being the one step ahead forecast of .
-
13:
– Real (Kind=nag_wp) array
Output
-
On exit: the residuals,
, for .
-
14:
– Real (Kind=nag_wp)
Output
-
On exit: the square root of the mean deviation.
-
15:
– Real (Kind=nag_wp)
Output
-
On exit: the mean absolute deviation.
-
16:
– Real (Kind=nag_wp) array
Input/Output
Note: the dimension of the array
r
must be at least
if
,
or
and at least
if
or
.
On entry: if
,
r must contain the values as returned by a previous call to
g05pmf or
g13amf,
r need not be set otherwise.
If
,
or
, only the first
elements of
r are referenced, otherwise the first
elements are referenced.
On exit: the information on the current state of the smoothing.
Constraint:
if
,
r must have been initialized by at least one previous call to
g05pmf or
g13amf with
, and
r should not have been changed since the last call to
g05pmf or
g13amf.
-
17:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, .
Constraint: , or .
-
On entry, .
Constraint: , , , or .
-
On entry, .
Constraint: if or , .
-
On entry, .
Constraint: .
On entry, .
Constraint: if , .
On entry, .
Constraint: .
-
On entry, .
Constraint: .
-
A multiplicative Holt–Winters model cannot be used with the supplied data.
-
On entry, , .
Constraint: if and or , .
On entry, and .
Constraint: if and or , .
-
On entry, .
Constraint: .
-
On entry, the array
r has not been initialized correctly.
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.
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.
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
g13amf is not threaded in any implementation.
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 routine document for
g05pmf.
10
Example
This example smooths a time series relating to the rate of the earth's rotation about its polar axis.
10.1
Program Text
10.2
Program Data
10.3
Program Results