g05ph 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 g05ph.


public static void g05ph(
	int mode,
	int n,
	double xmean,
	int ip,
	double[] phi,
	int iq,
	double[] theta,
	double avar,
	double[] r,
	G05..::..G05State g05state,
	out double var,
	double[] x,
	out int ifail
Visual Basic
Public Shared Sub g05ph ( _
	mode As Integer, _
	n As Integer, _
	xmean As Double, _
	ip As Integer, _
	phi As Double(), _
	iq As Integer, _
	theta As Double(), _
	avar As Double, _
	r As Double(), _
	g05state As G05..::..G05State, _
	<OutAttribute> ByRef var As Double, _
	x As Double(), _
	<OutAttribute> ByRef ifail As Integer _
Visual C++
static void g05ph(
	int mode, 
	int n, 
	double xmean, 
	int ip, 
	array<double>^ phi, 
	int iq, 
	array<double>^ theta, 
	double avar, 
	array<double>^ r, 
	G05..::..G05State^ g05state, 
	[OutAttribute] double% var, 
	array<double>^ x, 
	[OutAttribute] int% ifail
static member g05ph : 
        mode : int * 
        n : int * 
        xmean : float * 
        ip : int * 
        phi : float[] * 
        iq : int * 
        theta : float[] * 
        avar : float * 
        r : float[] * 
        g05state : G05..::..G05State * 
        var : float byref * 
        x : float[] * 
        ifail : int byref -> unit 


Type: System..::..Int32
On entry: a code for selecting the operation to be performed by the method.
Set up reference vector only.
Generate terms in the time series using reference vector set up in a prior call to g05ph.
Set up reference vector and generate terms in the time series.
Constraint: mode=0, 1 or 2.
Type: System..::..Int32
On entry: n, the number of observations to be generated.
Constraint: n0.
Type: System..::..Double
On entry: the mean of the time series.
Type: System..::..Int32
On entry: p, the number of autoregressive coefficients supplied.
Constraint: ip0.
Type: array<System..::..Double>[]()[][]
An array of size [ip]
On entry: the autoregressive coefficients of the model, ϕ1,ϕ2,,ϕp.
Type: System..::..Int32
On entry: q, the number of moving average coefficients supplied.
Constraint: iq0.
Type: array<System..::..Double>[]()[][]
An array of size [iq]
On entry: the moving average coefficients of the model, θ1,θ2,,θq.
Type: System..::..Double
On entry: σ2, the variance of the Normal perturbations.
Constraint: avar0.0.
Type: array<System..::..Double>[]()[][]
An array of size [lr]
On entry: if mode=1, the reference vector from the previous call to g05ph.
On exit: the reference vector.
Type: NagLibrary..::..G05..::..G05State
An Object of type G05.G05State.
Type: System..::..Double%
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.
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: contains the next n observations from the time series.
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).


Let the vector xt, denote a time series which is assumed to follow an autoregressive moving average (ARMA) model of the form:
where εt, is a residual series of independent random perturbations assumed to be Normally distributed with zero mean and variance σ2. The parameters ϕi, for i=1,2,,p, are called the autoregressive (AR) parameters, and θj, for j=1,2,,q, the moving average (MA) parameters. The parameters in the model are thus the p ϕ values, the q θ values, the mean μ and the residual variance σ2.
g05ph sets up a reference vector containing initial values corresponding to a stationary position using the method described in Tunnicliffe–Wilson (1979). The method can then return a realization of x1,x2,,xn. On a successful exit, the recent history is updated and saved in the reference vector r so that g05ph may be called again to generate a realization of xn+1,xn+2,, etc. See the description of the parameter mode in [Parameters] for details.
One of the initialization methods (G05KFF not in this release) (for a repeatable sequence if computed sequentially) or (G05KGF not in this release) (for a non-repeatable sequence) must be called prior to the first call to g05ph.


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

Error Indicators and Warnings

Errors or warnings detected by the method:
On entry, mode0, 1 or 2.
On entry, n<0.
On entry, ip<0.
phi does not define a stationary autoregressive process.
On entry, iq<0.
On entry, avar<0.0.
Either r has been corrupted or the value of ip or iq is not the same as when r was set up in a previous call to g05ph with mode=0 or 2.
On entry, lr<ip+iq+6+maxip,iq+1.
On entry,state vector was not initialized or has been corrupted.
An error occured, see message report.
Negative dimension for array value
Invalid Parameters value


Any errors in the reference vector's initial values should be very much smaller than the error term; see Tunnicliffe–Wilson (1979).

Parallelism and Performance


Further Comments

The time taken by g05ph is essentially of order ip2.
The ARMA model for a time series can also be written as:
  • xn is the observed value of the time series at time n,
  • NA is the number of autoregressive parameters, Ai,
  • NB is the number of moving average parameters, Bi,
  • E is the mean of the time series,
  • at is a series of independent random Standard Normal perturbations.
This is related to the form given in [Description] by:
  • B12=σ2,
  • Bi+1=-θiσ=-θiB1,  i=1,2,,q,
  • NB=q+1,
  • E=μ,
  • Ai=ϕi,  i=1,2,,p,
  • NA=p.


See Also