NAG FL Interface
g13baf (multi_filter_arima)
1
Purpose
g13baf filters a time series by an ARIMA model.
2
Specification
Fortran Interface
Subroutine g13baf ( |
y, ny, mr, nmr, par, npar, cy, wa, nwa, b, nb, ifail) |
Integer, Intent (In) |
:: |
ny, mr(nmr), nmr, npar, nwa, nb |
Integer, Intent (Inout) |
:: |
ifail |
Real (Kind=nag_wp), Intent (In) |
:: |
y(ny), par(npar), cy |
Real (Kind=nag_wp), Intent (Out) |
:: |
wa(nwa), b(nb) |
|
C Header Interface
#include <nag.h>
void |
g13baf_ (const double y[], const Integer *ny, const Integer mr[], const Integer *nmr, const double par[], const Integer *npar, const double *cy, double wa[], const Integer *nwa, double b[], const Integer *nb, Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
g13baf_ (const double y[], const Integer &ny, const Integer mr[], const Integer &nmr, const double par[], const Integer &npar, const double &cy, double wa[], const Integer &nwa, double b[], const Integer &nb, Integer &ifail) |
}
|
The routine may be called by the names g13baf or nagf_tsa_multi_filter_arima.
3
Description
From a given series , a new series is calculated using a supplied (filtering) ARIMA model. This model will be one which has previously been fitted to a series with residuals . The equations defining in terms of are very similar to those by which is obtained from . The only dissimilarity is that no constant correction is applied after differencing. This is because the series is generally distinct from the series with which the model is associated, though may be related to . Whilst it is appropriate to apply the ARIMA model to so as to preserve the same relationship between and as exists between and , the constant term in the ARIMA model is inappropriate for . The consequence is that will not necessarily have zero mean.
The equations are precisely:
the appropriate differencing of
; both the seasonal and non-seasonal inverted autoregressive operations are then applied,
followed by the inverted moving average operations
Because the filtered series value
depends on present and past values
, there is a problem arising from ignorance of
which particularly affects calculation of the early values
, causing ‘transient errors’. The routine allows two possibilities.
-
(i)The equations (1), (2) and (3) are applied from successively later time points so that all terms on their right-hand sides are known, with being defined for . Equations (4) and (5) are then applied over the same range, taking any values on the right-hand side associated with previous time points to be zero.
This procedure may still however result in unacceptably large transient errors in early values of .
-
(ii)The unknown values are estimated by backforecasting. This requires that an ARIMA model distinct from that which has been supplied for filtering, should have been previously fitted to .
For efficiency, you are asked to supply both this ARIMA model for
and a limited number of backforecasts which are prefixed to the known values of
. Within the routine further backforecasts of
, and the series
,
,
in
(1),
(2) and
(3) are then easily calculated, and a set of linear equations solved for backforecasts of
for use in
(4) and
(5) in the case that
.
Even if the best model for
is not available, a very approximate guess such as
or
can help to reduce the transients substantially.
The backforecasts which need to be prefixed to
are of length
, where
and
are the non-seasonal and seasonal moving average orders and
the seasonal period for the ARIMA model of
. Thus you need not carry out the backforecasting exercise if
. Otherwise, the series
should be reversed to obtain
and
g13ajf
should be used to forecast
values,
. The ARIMA model used is that fitted to
(as a forward series) except that, if
is odd, the constant should be changed in sign (to allow, for example, for the fact that a forward upward trend is a reversed downward trend). The ARIMA model for
supplied to the filtering routine must however have the appropriate constant for the forward series.
The series is then supplied to the routine, and a corresponding set of values returned for .
4
References
Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day
5
Arguments
-
1:
– Real (Kind=nag_wp) array
Input
-
On entry: the
backforecasts, starting with backforecast at time
to backforecast at time
, followed by the time series starting at time
, where
. If there are no backforecasts, either because the ARIMA model for the time series is not known, or because it is known but has no moving average terms, then the time series starts at the beginning of
y.
-
2:
– Integer
Input
-
On entry: the total number of backforecasts and time series data points in array
y.
Constraint:
.
-
3:
– Integer array
Input
-
On entry: the orders vector for the filtering model, followed by the orders vector for the ARIMA model for the time series if the latter is known. The orders appear in the standard sequence
as given in the
G13 Chapter Introduction. If the ARIMA model for the time series is supplied, the routine will assume that the first
values of the array
y are backforecasts.
Constraints:
the filtering model is restricted in the following ways:
- , i.e., filtering by a model which contains only differencing terms is not permitted;
- , for ;
- if , ;
- if , ;
- .
the ARIMA model for the time series is restricted in the following ways:
- , for ;
- if , ;
- if , ;
- .
-
4:
– Integer
Input
-
On entry: the number of values specified in the array
mr. It takes the value
if no ARIMA model for the time series is supplied but otherwise it takes the value
. Thus
nmr acts as an indicator as to whether backforecasting can be carried out.
Constraint:
or .
-
5:
– Real (Kind=nag_wp) array
Input
-
On entry: the parameters of the filtering model, followed by the parameters of the ARIMA model for the time series, if supplied. Within each model the parameters are in the standard order of non-seasonal AR and MA followed by seasonal AR and MA.
-
6:
– Integer
Input
-
On entry: the total number of parameters held in array
par.
Constraints:
- if , ;
- if , .
Note: the first constraint (i.e.,
) on the orders of the filtering model, in argument
mr, ensures that
.
-
7:
– Real (Kind=nag_wp)
Input
-
On entry: if the ARIMA model is known (i.e.,
),
cy must specify the constant term of the ARIMA model for the time series. If this model is not known (i.e.,
),
cy is not used.
-
8:
– Real (Kind=nag_wp) array
Output
-
9:
– Integer
Input
-
These arguments are no longer accessed by g13baf. Workspace is provided internally by dynamic allocation instead.
-
10:
– Real (Kind=nag_wp) array
Output
-
On exit: the filtered output series. If the ARIMA model for the time series was known, and hence
backforecasts were supplied in
y, then
b contains
‘filtered’ backforecasts followed by the filtered series. Otherwise, the filtered series begins at the start of
b just as the original series began at the start of
y. In either case, if the value of the series at time
is held in
, then the filtered value at time
is held in
.
-
11:
– Integer
Input
-
On entry: the dimension of the array
b as declared in the (sub)program from which
g13baf is called. In addition to holding the returned filtered series,
b is also used as an intermediate work array if the ARIMA model for the time series was known.
Constraints:
- if , ;
- if , .
Where
- ;
- ;
- .
-
12:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or 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, the orders vector
mr is invalid.
-
On entry,
.
Constraint:
npar must be inconsistent with
mr.
-
On entry, and the minimum size .
Constraint: .
-
On entry, and the minimum size .
Constraint: if then , otherwise .
-
The orders vector for the filtering model is invalid.
-
The orders vector for the ARIMA model is invalid.
-
The initial values of the filtered series are indeterminate for the given models.
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
Accuracy and stability are high except when the MA parameters are close to the invertibility boundary.
8
Parallelism and Performance
g13baf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13baf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
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.
If an ARIMA model is supplied,
a local workspace array
of fixed
length is
allocated internally by
g13baf. The total size of
this array
amounts to
integer
elements, where
is the expression defined in the description of the argument
wa.
The time taken by
g13baf is approximately proportional to
with an appreciable fixed increase if an ARIMA model is supplied for the time series.
10
Example
This example reads a time series of length
. It reads the univariate ARIMA
model and the ARIMA filtering
model for the series. Two initial backforecasts are required and these are calculated by a call to
g13ajf
.
The backforecasts are inserted at the start of the series and
g13baf is called to perform the calculations.
10.1
Program Text
10.2
Program Data
10.3
Program Results