NAG FL Interface
g05phf (times_arma)
1
Purpose
g05phf 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 g05phf.
2
Specification
Fortran Interface
Subroutine g05phf ( |
mode, n, xmean, ip, phi, iq, theta, avar, r, lr, state, var, x, ifail) |
Integer, Intent (In) |
:: |
mode, n, ip, iq, lr |
Integer, Intent (Inout) |
:: |
state(*), ifail |
Real (Kind=nag_wp), Intent (In) |
:: |
xmean, phi(ip), theta(iq), avar |
Real (Kind=nag_wp), Intent (Inout) |
:: |
r(lr) |
Real (Kind=nag_wp), Intent (Out) |
:: |
var, x(n) |
|
C Header Interface
#include <nag.h>
void |
g05phf_ (const Integer *mode, const Integer *n, const double *xmean, const Integer *ip, const double phi[], const Integer *iq, const double theta[], const double *avar, double r[], const Integer *lr, Integer state[], double *var, double x[], Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
g05phf_ (const Integer &mode, const Integer &n, const double &xmean, const Integer &ip, const double phi[], const Integer &iq, const double theta[], const double &avar, double r[], const Integer &lr, Integer state[], double &var, double x[], Integer &ifail) |
}
|
The routine may be called by the names g05phf or nagf_rand_times_arma.
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
.
g05phf sets up a reference vector containing initial values corresponding to a stationary position using the method described in
Tunnicliffe–Wilson (1979). The routine can then return a realization of
. On a successful exit, the recent history is updated and saved in the reference vector
r so that
g05phf 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 routines
g05kff (for a repeatable sequence if computed sequentially) or
g05kgf (for a non-repeatable sequence) must be called prior to the first call to
g05phf.
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:
– Integer
Input
-
On entry: a code for selecting the operation to be performed by the routine.
- Set up reference vector only.
- Generate terms in the time series using reference vector set up in a prior call to g05phf.
- Set up reference vector and generate terms in the time series.
Constraint:
, or .
-
2:
– Integer
Input
-
On entry: , the number of observations to be generated.
Constraint:
.
-
3:
– Real (Kind=nag_wp)
Input
-
On entry: the mean of the time series.
-
4:
– Integer
Input
-
On entry: , the number of autoregressive coefficients supplied.
Constraint:
.
-
5:
– Real (Kind=nag_wp) array
Input
-
On entry: the autoregressive coefficients of the model, .
-
6:
– Integer
Input
-
On entry: , the number of moving average coefficients supplied.
Constraint:
.
-
7:
– Real (Kind=nag_wp) array
Input
-
On entry: the moving average coefficients of the model, .
-
8:
– Real (Kind=nag_wp)
Input
-
On entry: , the variance of the Normal perturbations.
Constraint:
.
-
9:
– Real (Kind=nag_wp) array
Communication Array
-
On entry: if , the reference vector from the previous call to g05phf.
On exit: the reference vector.
-
10:
– Integer
Input
-
On entry: the dimension of the array
r as declared in the (sub)program from which
g05phf is called.
Constraint:
.
-
11:
– Integer array
Communication Array
Note: the actual argument supplied
must be the array
state supplied to the initialization routines
g05kff or
g05kgf.
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
-
12:
– Real (Kind=nag_wp)
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.
-
13:
– Real (Kind=nag_wp) array
Output
-
On exit: contains the next observations from the time series.
-
14:
– 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, .
Constraint: .
-
On entry, .
Constraint: .
-
On entry, the AR parameters are outside the stationarity region.
-
On entry, .
Constraint: .
-
On entry, .
Constraint: .
-
ip or
iq is not the same as when
r was set up in a previous call.
Previous value of
and
.
Previous value of
and
.
Reference vector
r has been corrupted or not initialized correctly.
-
On entry,
lr is not large enough,
: minimum length required
.
-
On entry,
state vector has been corrupted or not initialized.
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
Any errors in the reference vector's initial values should be very much smaller than the error term; see
Tunnicliffe–Wilson (1979).
8
Parallelism and Performance
g05phf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
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.
The time taken by g05phf is essentially of order .
Note: The reference vector,
r, contains a copy of the recent history of the series. If attempting to re-initialize the series by calling
g05kff or
g05kgf a call to
g05phf with
must also be made. In the repeatable case the calls to
g05phf should be performed in the same order (at the same point(s) in simulation) every time
g05kff is used. When the generator state is saved and restored using the argument
state, 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 parameters, ,
- is the number of moving average parameters, ,
- is the mean of the time series,
and
- is a series of independent random Standard Normal perturbations.
This is the form used in
g05phf.
This is related to the form given in
Section 3 by:
- ,
- ,
- ,
- ,
- ,
- .
10
Example
This example generates values for an autoregressive model given by
where
is a series of independent random Normal perturbations with variance
. The random number generators are initialized by
g05kff and then
g05phf is called to initialize a reference vector and generate a sample of ten observations.
10.1
Program Text
10.2
Program Data
10.3
Program Results