NAG Library Function Document
nag_rngs_arma_time_series (g05pac)
1 Purpose
nag_rngs_arma_time_series (g05pac) generates a realization of a univariate time series from an autoregressive moving average (ARMA) model. The realization may be continued or a new realization generated at subsequent calls to nag_rngs_arma_time_series (g05pac).
2 Specification
| #include <nag.h> |
| #include <nagg05.h> |
| void |
nag_rngs_arma_time_series (Integer mode,
double xmean,
Integer p,
const double phi[],
Integer q,
const double theta[],
double avar,
double *var,
Integer n,
double x[],
Integer igen,
Integer iseed[],
double r[],
NagError *fail) |
|
3 Description
Let the vector
, denote a time series which is assumed to follow an autoregressive moving average (ARMA) model of the form:
where
, is a residual series of independent random perturbations assumed to be Normally distributed with zero mean and variance
. The parameters
, for
, are called the autoregressive (AR) parameters, and
, for
, the moving average (MA) parameters. The parameters in the model are thus the
values, the
values, the mean
and the residual variance
.
nag_rngs_arma_time_series (g05pac) sets up a reference vector containing initial values corresponding to a stationary position using the method described in
Tunnicliffe–Wilson (1979). The function can then return a realization of
. On a successful exit, the recent history is updated and saved in the reference vector
r so that nag_rngs_arma_time_series (g05pac) may be called again to generate a realization of
, etc. See the description of the argument
mode in
Section 5 for details.
One of the initialization functions
nag_rngs_init_repeatable (g05kbc) (for a repeatable sequence if computed sequentially) or
nag_rngs_init_nonrepeatable (g05kcc) (for a non-repeatable sequence) must be called prior to the first call to nag_rngs_arma_time_series (g05pac).
4 References
Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley
Tunnicliffe–Wilson G (1979) Some efficient computational procedures for high order ARMA models J. Statist. Comput. Simulation 8 301–309
5 Arguments
- 1:
mode – IntegerInput
On entry: a code for selecting the operation to be performed by the function.
- Set up reference vector only.
- Generate terms in the time series using reference vector set up in a prior call to nag_rngs_arma_time_series (g05pac).
- Set up reference vector and generate terms in the time series.
Constraint:
, or .
- 2:
xmean – doubleInput
On entry: the mean of the time series.
- 3:
p – IntegerInput
On entry:
, the number of autoregressive coefficients supplied.
Constraint:
.
- 4:
phi[p] – const doubleInput
On entry: the autoregressive coefficients of the model, .
- 5:
q – IntegerInput
On entry:
, the number of moving average coefficients supplied.
Constraint:
.
- 6:
theta[q] – const doubleInput
On entry: the moving average coefficients of the model, .
- 7:
avar – doubleInput
On entry: , the variance of the Normal perturbations.
Constraint:
.
- 8:
var – double *Output
On exit: the proportion of the variance of a term in the series that is due to the moving-average (error) terms in the model. The smaller this is, the nearer is the model to non-stationarity.
- 9:
n – IntegerInput
On entry:
, the number of observations to be generated.
Constraint:
.
- 10:
x[n] – doubleOutput
On exit: contains the next observations from the time series.
- 11:
igen – IntegerInput
-
On entry: must contain the identification number for the generator to be used to return a pseudorandom number and should remain unchanged following initialization by a prior call to
nag_rngs_init_repeatable (g05kbc) or
nag_rngs_init_nonrepeatable (g05kcc).
- 12:
iseed[] – IntegerCommunication Array
-
On entry: contains values which define the current state of the selected generator.
On exit: contains updated values defining the new state of the selected generator.
- 13:
r[] – doubleCommunication Array
-
Note: the dimension,
dim, of the array
r
must be at least
.
On entry: if , the reference vector from the previous call to nag_rngs_arma_time_series (g05pac).
On exit: the reference vector.
- 14:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
6 Error Indicators and Warnings
- NE_BAD_PARAM
On entry, argument had an illegal value.
- NE_INT
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
- NE_REAL
On entry, .
Constraint: .
- NE_STATIONARY_AR
phi does not define a stationary autoregressive process.
7 Accuracy
The errors in the initialization process should be very much smaller than the error term; see
Tunnicliffe–Wilson (1979).
The time taken by nag_rngs_arma_time_series (g05pac) is essentially of order .
Note: nag_rngs_init_repeatable (g05kbc) and
nag_rngs_init_nonrepeatable (g05kcc) must be used with care if this function is used as well. The reference vector, as mentioned before, contains a copy of the recent history of the series. This will not be altered properly by calls to any of the above functions. A call to
nag_rngs_init_repeatable (g05kbc) or
nag_rngs_init_nonrepeatable (g05kcc) should be followed by a call to nag_rngs_arma_time_series (g05pac) with
to re-initialize the time series reference vector in use. To maintain repeatability with
nag_rngs_init_repeatable (g05kbc), the calls to nag_rngs_arma_time_series (g05pac) should be performed in the same order and at the same point or points in the simulation every time
nag_rngs_init_repeatable (g05kbc) is used. When the generator state is saved and restored using the arguments
igen and
iseed, the time series reference vector must be saved and restored as well.
The ARMA model for a time series can also be written as:
where
- is the observed value of the time series at time ,
- is the number of autoregressive arguments, ,
- is the number of moving average arguments, ,
- is the mean of the time series,
and
- is a series of independent random Standard Normal perturbations.
This is related to the form given in
Section 3 by:
- ,
- ,
- ,
- ,
- ,
- .
9 Example
This example calls nag_rngs_arma_time_series (g05pac) to set up the reference vector for an autoregressive model after initialization by
nag_rngs_init_repeatable (g05kbc). The model is given by
where
is a series of independent random Normal perturbations with variance
. nag_rngs_arma_time_series (g05pac) is then called to generate a sample of ten observations, which are printed.
9.1 Program Text
Program Text (g05pace.c)
9.2 Program Data
None.
9.3 Program Results
Program Results (g05pace.r)