NAG Library Routine Document
G13DDF
1 Purpose
G13DDF fits a vector autoregressive moving average (VARMA) model to an observed vector of time series using the method of Maximum Likelihood (ML). Standard errors of parameter estimates are computed along with their appropriate correlation matrix. The routine also calculates estimates of the residual series.
2 Specification
SUBROUTINE G13DDF ( 
K, N, IP, IQ, MEAN, PAR, NPAR, QQ, KMAX, W, PARHLD, EXACT, IPRINT, CGETOL, MAXCAL, ISHOW, NITER, RLOGL, V, G, CM, LDCM, IFAIL) 
INTEGER 
K, N, IP, IQ, NPAR, KMAX, IPRINT, MAXCAL, ISHOW, NITER, LDCM, IFAIL 
REAL (KIND=nag_wp) 
PAR(NPAR), QQ(KMAX,K), W(KMAX,N), CGETOL, RLOGL, V(KMAX,N), G(NPAR), CM(LDCM,NPAR) 
LOGICAL 
MEAN, PARHLD(NPAR), EXACT 

3 Description
Let
${W}_{\mathit{t}}={\left({w}_{1\mathit{t}},{w}_{2\mathit{t}},\dots ,{w}_{\mathit{k}\mathit{t}}\right)}^{\mathrm{T}}$, for
$\mathit{t}=1,2,\dots ,n$, denote a vector of
$k$ time series which is assumed to follow a multivariate ARMA model of the form
where
${\epsilon}_{\mathit{t}}={\left({\epsilon}_{1\mathit{t}},{\epsilon}_{2\mathit{t}},\dots ,{\epsilon}_{k\mathit{t}}\right)}^{\mathrm{T}}$, for
$\mathit{t}=1,2,\dots ,n$, is a vector of
$k$ residual series assumed to be Normally distributed with zero mean and positive definite covariance matrix
$\Sigma $. The components of
${\epsilon}_{t}$ are assumed to be uncorrelated at nonsimultaneous lags. The
${\varphi}_{i}$ and
${\theta}_{j}$ are
$k$ by
$k$ matrices of parameters.
$\left\{{\varphi}_{\mathit{i}}\right\}$, for
$\mathit{i}=1,2,\dots ,p$, are called the autoregressive (AR) parameter matrices, and
$\left\{{\theta}_{\mathit{i}}\right\}$, for
$\mathit{i}=1,2,\dots ,q$, the moving average (MA) parameter matrices. The parameters in the model are thus the
$p$ (
$k$ by
$k$)
$\varphi $matrices, the
$q$ (
$k$ by
$k$)
$\theta $matrices, the mean vector,
$\mu $, and the residual error covariance matrix
$\Sigma $. Let
where
$I$ denotes the
$k$ by
$k$ identity matrix.
The ARMA model
(1) is said to be stationary if the eigenvalues of
$A\left(\varphi \right)$ lie inside the unit circle. Similarly, the ARMA model
(1) is said to be invertible if the eigenvalues of
$B\left(\theta \right)$ lie inside the unit circle.
The method of computing the exact likelihood function (using a Kalman filter algorithm) is discussed in
Shea (1987). A quasiNewton algorithm (see
Gill and Murray (1972)) is then used to search for the maximum of the loglikelihood function. Stationarity and invertibility are enforced on the model using the reparameterisation discussed in
Ansley and Kohn (1986). Conditional on the maximum likelihood estimates being equal to their true values the estimates of the residual series are uncorrelated with zero mean and constant variance
$\Sigma $.
You have the option of setting a parameter (
EXACT to .FALSE.) so that G13DDF calculates conditional maximum likelihood estimates (conditional on
${W}_{0}={W}_{1}=\cdots ={W}_{1p}={\epsilon}_{0}={\epsilon}_{1}=\cdots =\phantom{\rule{0ex}{0ex}}{\epsilon}_{1q}=0$). This may be useful if the exact maximum likelihood estimates are close to the boundary of the invertibility region.
You also have the option (see
Section 5) of requesting G13DDF to constrain elements of the
$\varphi $ and
$\theta $ matrices and
$\mu $ vector to have prespecified values.
4 References
Ansley C F and Kohn R (1986) A note on reparameterising a vector autoregressive moving average model to enforce stationarity J. Statist. Comput. Simulation 24 99–106
Gill P E and Murray W (1972) QuasiNewton methods for unconstrained optimization J. Inst. Math. Appl. 9 91–108
Shea B L (1987) Estimation of multivariate time series J. Time Ser. Anal. 8 95–110
5 Parameters
 1: K – INTEGERInput
On entry: $k$, the number of observed time series.
Constraint:
${\mathbf{K}}\ge 1$.
 2: N – INTEGERInput
On entry: $n$, the number of observations in each time series.
 3: IP – INTEGERInput
On entry: $p$, the number of AR parameter matrices.
Constraint:
${\mathbf{IP}}\ge 0$.
 4: IQ – INTEGERInput
On entry: $q$, the number of MA parameter matrices.
Constraint:
${\mathbf{IQ}}\ge 0$.
${\mathbf{IP}}={\mathbf{IQ}}=0$ is not permitted.
 5: MEAN – LOGICALInput
On entry: ${\mathbf{MEAN}}=\mathrm{.TRUE.}$, if components of $\mu $ have been estimated and ${\mathbf{MEAN}}=\mathrm{.FALSE.}$, if all elements of $\mu $ are to be taken as zero.
Constraint:
${\mathbf{MEAN}}=\mathrm{.TRUE.}$ or $\mathrm{.FALSE.}$.
 6: PAR(NPAR) – REAL (KIND=nag_wp) arrayInput/Output
On entry: initial parameter estimates read in row by row in the order
${\varphi}_{1},{\varphi}_{2},\dots ,{\varphi}_{p}$,
${\theta}_{1},{\theta}_{2},\dots ,{\theta}_{q},\mu $.
Thus,
 if ${\mathbf{IP}}>0$,
${\mathbf{PAR}}\left(\left(\mathit{l}1\right)\times k\times k+\left(\mathit{i}1\right)\times k+\mathit{j}\right)$ must be set equal to an initial estimate of the $\left(\mathit{i},\mathit{j}\right)$th element of ${\varphi}_{\mathit{l}}$, for $\mathit{l}=1,2,\dots ,p$, $\mathit{i}=1,2,\dots ,k$ and $\mathit{j}=1,2,\dots ,k$;
 if ${\mathbf{IQ}}>0$, ${\mathbf{PAR}}\left(p\times k\times k+\left(l1\right)\times k\times k+\left(i1\right)\times k+j\right)$ must be set equal to an initial estimate of the $\left(i,j\right)$th element of ${\theta}_{l}$, $l=1,2,\dots ,q$ and $i,j=1,2,\dots ,k$;
 if ${\mathbf{MEAN}}=\mathrm{.TRUE.}$, ${\mathbf{PAR}}\left(\left(p+q\right)\times k\times k+i\right)$ should be set equal to an initial estimate of the $i$th component of $\mu $ ($\mu \left(i\right)$). (If you set ${\mathbf{PAR}}\left(\left(p+q\right)\times k\times k+i\right)$ to $0.0$ then G13DDF will calculate the mean of the $i$th series and use this as an initial estimate of $\mu \left(i\right)$.)
The first
$p\times k\times k$ elements of
PAR must satisfy the stationarity condition and the next
$q\times k\times k$ elements of
PAR must satisfy the invertibility condition.
If in doubt set all elements of
PAR to
$0.0$.
On exit: if
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${\mathbf{IFAIL}}\ge {\mathbf{4}}$ then all the elements of
PAR will be overwritten by the latest estimates of the corresponding ARMA parameters.
 7: NPAR – INTEGERInput
On entry: the dimension of the arrays
PAR,
PARHLD and
G and the second dimension of the array
CM as declared in the (sub)program from which G13DDF is called.
NPAR is the number of initial parameter estimates.
Constraints:
 if ${\mathbf{MEAN}}=\mathrm{.FALSE.}$, NPAR must be set equal to $\left(p+q\right)\times k\times k$;
 if ${\mathbf{MEAN}}=\mathrm{.TRUE.}$, NPAR must be set equal to $\left(p+q\right)\times k\times k+k$.
The total number of observations $\left(n\times k\right)$ must exceed the total number of parameters in the model (${\mathbf{NPAR}}+k\left(k+1\right)/2$).
 8: QQ(KMAX,K) – REAL (KIND=nag_wp) arrayInput/Output
On entry:
${\mathbf{QQ}}\left(\mathit{i},\mathit{j}\right)$ must be set equal to an initial estimate of the
$\left(\mathit{i},\mathit{j}\right)$th element of
$\Sigma $. The lower triangle only is needed.
QQ must be positive definite. It is strongly recommended that on entry the elements of
QQ are of the same order of magnitude as at the solution point. If you set
${\mathbf{QQ}}\left(\mathit{i},\mathit{j}\right)=0.0$, for
$\mathit{i}=1,2,\dots ,k$ and
$\mathit{j}=1,2,\dots ,i$, then G13DDF will calculate the covariance matrix between the
$k$ time series and use this as an initial estimate of
$\Sigma $.
On exit: if ${\mathbf{IFAIL}}={\mathbf{0}}$ or ${\mathbf{IFAIL}}\ge {\mathbf{4}}$ then ${\mathbf{QQ}}\left(i,j\right)$ will contain the latest estimate of the $\left(i,j\right)$th element of $\Sigma $. The lower triangle only is returned.
 9: KMAX – INTEGERInput
On entry: the first dimension of the arrays
QQ,
W and
V as declared in the (sub)program from which G13DDF is called.
Constraint:
${\mathbf{KMAX}}\ge {\mathbf{K}}$.
 10: W(KMAX,N) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{W}}\left(\mathit{i},\mathit{t}\right)$ must be set equal to the $\mathit{i}$th component of ${W}_{\mathit{t}}$, for $\mathit{i}=1,2,\dots ,k$ and $\mathit{t}=1,2,\dots ,n$.
 11: PARHLD(NPAR) – LOGICAL arrayInput
On entry:
${\mathbf{PARHLD}}\left(\mathit{i}\right)$ must be set to .TRUE. if
${\mathbf{PAR}}\left(\mathit{i}\right)$ is to be held constant at its input value and .FALSE. if
${\mathbf{PAR}}\left(\mathit{i}\right)$ is a free parameter, for
$\mathit{i}=1,2,\dots ,{\mathbf{NPAR}}$.
If in doubt try setting all elements of
PARHLD to .FALSE..
 12: EXACT – LOGICALInput
On entry: must be set equal to .TRUE. if you wish G13DDF to compute exact maximum likelihood estimates.
EXACT must be set equal to .FALSE. if only conditional likelihood estimates are required.
 13: IPRINT – INTEGERInput
On entry: the frequency with which the automatic monitoring routine is to be called.
 ${\mathbf{IPRINT}}>0$
 The ML search procedure is monitored once every IPRINT iterations and just before exit from the search routine.
 ${\mathbf{IPRINT}}=0$
 The search routine is monitored once at the final point.
 ${\mathbf{IPRINT}}<0$
 The search routine is not monitored at all.
 14: CGETOL – REAL (KIND=nag_wp)Input
On entry: the accuracy to which the solution in
PAR and
QQ is required.
If
CGETOL is set to
${10}^{l}$ and on exit
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${\mathbf{IFAIL}}\ge {\mathbf{6}}$, then all the elements in
PAR and
QQ should be accurate to approximately
$l$ decimal places. For most practical purposes the value
${10}^{4}$ should suffice. You should be wary of setting
CGETOL too small since the convergence criteria may then have become too strict for the machine to handle.
If
CGETOL has been set to a value which is less than the
machine precision,
$\epsilon $, then G13DDF will use the value
$10.0\times \sqrt{\epsilon}$ instead.
 15: MAXCAL – INTEGERInput
On entry: the maximum number of likelihood evaluations to be permitted by the search procedure.
Suggested value:
${\mathbf{MAXCAL}}=40\times {\mathbf{NPAR}}\times \left({\mathbf{NPAR}}+5\right)$.
Constraint:
${\mathbf{MAXCAL}}\ge 1$.
 16: ISHOW – INTEGERInput
On entry: specifies which of the following two quantities are to be printed.
(i) 
table of maximum likelihood estimates and their standard errors (as returned in the output arrays PAR, QQ and CM); 
(ii) 
table of residual series (as returned in the output array V). 
 ${\mathbf{ISHOW}}=0$
 None of the above are printed.
 ${\mathbf{ISHOW}}=1$
 (i) only is printed.
 ${\mathbf{ISHOW}}=2$
 (i) and (ii) are printed.
Constraint:
$0\le {\mathbf{ISHOW}}\le 2$.
 17: NITER – INTEGEROutput
On exit: if
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${\mathbf{IFAIL}}\ge {\mathbf{4}}$ then
NITER contains the number of iterations performed by the search routine.
 18: RLOGL – REAL (KIND=nag_wp)Output
On exit: if
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${\mathbf{IFAIL}}\ge {\mathbf{4}}$ then
RLOGL contains the value of the loglikelihood function corresponding to the final point held in
PAR and
QQ.
 19: V(KMAX,N) – REAL (KIND=nag_wp) arrayOutput
On exit: if
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${\mathbf{IFAIL}}\ge {\mathbf{4}}$ then
${\mathbf{V}}\left(\mathit{i},\mathit{t}\right)$ will contain an estimate of the
$\mathit{i}$th component of
${\epsilon}_{\mathit{t}}$, for
$\mathit{i}=1,2,\dots ,k$ and
$\mathit{t}=1,2,\dots ,n$, corresponding to the final point held in
PAR and
QQ.
 20: G(NPAR) – REAL (KIND=nag_wp) arrayOutput
On exit: if
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${\mathbf{IFAIL}}\ge {\mathbf{4}}$ then
${\mathbf{G}}\left(i\right)$ will contain the estimated first derivative of the loglikelihood function with respect to the
$i$th element in the array
PAR. If the gradient cannot be computed then all the elements of
G are returned as zero.
 21: CM(LDCM,NPAR) – REAL (KIND=nag_wp) arrayOutput
On exit: if
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${\mathbf{IFAIL}}\ge {\mathbf{4}}$ then
${\mathbf{CM}}\left(i,j\right)$ will contain an estimate of the correlation coefficient between the
$i$th and
$j$th elements in the
PAR array for
$1\le i\le {\mathbf{NPAR}}$,
$1\le j\le {\mathbf{NPAR}}$. If
$i=j$, then
${\mathbf{CM}}\left(i,j\right)$ will contain the estimated standard error of
${\mathbf{PAR}}\left(i\right)$. If the
$l$th component of
PAR has been held constant, i.e.,
${\mathbf{PARHLD}}\left(l\right)$ was set to .TRUE., then the
$l$th row and column of
CM will be set to zero. If the second derivative matrix cannot be computed then all the elements of
CM are returned as zero.
 22: LDCM – INTEGERInput
On entry: the first dimension of the array
CM as declared in the (sub)program from which G13DDF is called.
Constraint:
${\mathbf{LDCM}}\ge {\mathbf{NPAR}}$.
 23: IFAIL – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if
${\mathbf{IFAIL}}\ne {\mathbf{0}}$ on exit, the recommended value is
$1$.
When the value $\mathbf{1}\text{ or}1$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${{\mathbf{1}}}$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Note: G13DDF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$
On entry,  ${\mathbf{K}}<1$, 
or  ${\mathbf{IP}}<0$, 
or  ${\mathbf{IQ}}<0$, 
or  ${\mathbf{IP}}={\mathbf{IQ}}=0$, 
or  ${\mathbf{NPAR}}\ne \left({\mathbf{IP}}+{\mathbf{IQ}}\right)\times {\mathbf{K}}\times {\mathbf{K}}+\Delta \times {\mathbf{K}}$, where $\Delta =1$ if ${\mathbf{MEAN}}=\mathrm{.TRUE.}$ or $\Delta =0$ if ${\mathbf{MEAN}}=\mathrm{.FALSE.}$, 
or  ${\mathbf{N}}\times {\mathbf{K}}\le {\mathbf{NPAR}}+{\mathbf{K}}\times \left({\mathbf{K}}+1\right)/2$, 
or  ${\mathbf{KMAX}}<{\mathbf{K}}$, 
or  ${\mathbf{MAXCAL}}<1$, 
or  ${\mathbf{ISHOW}}<0$, 
or  ${\mathbf{ISHOW}}>2$, 
or  ${\mathbf{LDCM}}<{\mathbf{NPAR}}$, 
 ${\mathbf{IFAIL}}=2$
On entry, either the initial estimate of $\Sigma $ is not positive definite, or the initial estimates of the AR parameters are such that the model is nonstationary, or the initial estimates of the MA parameters are such that the model is noninvertible. To proceed, you must try a different starting point.
 ${\mathbf{IFAIL}}=3$
The routine cannot compute a sufficiently accurate estimate of the gradient vector at the usersupplied starting point. This usually occurs if either the initial parameter estimates are very close to the ML parameter estimates, or you have supplied a very poor estimate of $\Sigma $ or the starting point is very close to the boundary of the stationarity or invertibility region. To proceed, you must try a different starting point.
 ${\mathbf{IFAIL}}=4$
There have been
MAXCAL loglikelihood evaluations made in the routine. If steady increases in the loglikelihood function were monitored up to the point where this exit occurred, then the exit probably simply occurred because
MAXCAL was set too small, so the calculations should be restarted from the final point held in
PAR and
QQ. This type of exit may also indicate that there is no maximum to the likelihood surface. Output quantities (as described in
Section 5) are computed at the final point held in
PAR and
QQ, except that if
G or
CM cannot be computed, in which case they are set to zero.
 ${\mathbf{IFAIL}}=5$
The conditions for a solution have not all been met, but a point at which the loglikelihood took a larger value could not be found.
Provided that the estimated first derivatives are sufficiently small, and that the estimated condition number of the second derivative (Hessian) matrix, as printed when ${\mathbf{IPRINT}}\ge 0$, is not too large, this error exit may simply mean that, although it has not been possible to satisfy the specified requirements, the algorithm has in fact found the solution as far as the accuracy of the machine permits.
Such a condition can arise, for instance, if
CGETOL has been set so small that rounding error in evaluating the likelihood function makes attainment of the convergence conditions impossible.
If the estimated condition number at the final point is large, it could be that the final point is a solution but that the smallest eigenvalue of the Hessian matrix is so close to zero at the solution that it is not possible to recognize it as a solution. Output quantities (as described in
Section 5) are computed at the final point held in
PAR and
QQ, except that if
G or
CM cannot be computed, in which case they are set to zero.
 ${\mathbf{IFAIL}}=6$
The ML solution is so close to the boundary of either the stationarity region or the invertibility region that G13DDF cannot evaluate the Hessian matrix. The elements of
CM will then be set to zero on exit. The elements of
G will also be set to zero. All other output quantities will be correct.
 ${\mathbf{IFAIL}}=7$
This is an unlikely exit, which could occur in
E04XAA, which computes an estimate of the second derivative matrix and the gradient vector at the solution point. Either the Hessian matrix was found to be too illconditioned to be evaluated accurately or the gradient vector could not be computed to an acceptable degree of accuracy. In this case the elements of
CM will be set to zero on exit as will the elements of
G. All other output quantities will be correct.
 ${\mathbf{IFAIL}}=8$
The second derivative matrix at the solution point is not positive definite. In this case the elements of
CM will be set to zero on exit. All other output quantities will be correct.
 ${\mathbf{IFAIL}}=999$

Internal memory allocation failed.
7 Accuracy
On exit from G13DDF, if
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${\mathbf{IFAIL}}\ge {\mathbf{6}}$ and
CGETOL has been set to
${10}^{l}$, then all the parameters should be accurate to approximately
$l$ decimal places. If
CGETOL was set equal to a value less than the
machine precision,
$\epsilon $, then all the parameters should be accurate to approximately
$10.0\times \sqrt{\epsilon}$.
If
${\mathbf{IFAIL}}={\mathbf{4}}$ on exit (i.e.,
MAXCAL likelihood evaluations have been made but the convergence conditions of the search routine have not been satisfied), then the elements in
PAR and
QQ may still be good approximations to the ML estimates. Inspection of the elements of
G may help you determine whether this is likely.
Let $r=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{IP}},{\mathbf{IQ}}\right)$ and $s={\mathbf{NPAR}}+{\mathbf{K}}\times \left({\mathbf{K}}+1\right)/2$. Local workspace arrays of fixed lengths are allocated internally by G13DDF. The total size of these arrays amounts to $s+{\mathbf{K}}\times r+52$ integer elements and $2\times {s}^{2}+s\times \left(s1\right)/2+15\times s+{{\mathbf{K}}}^{2}\times \left(2\times {\mathbf{IP}}+{\mathbf{IQ}}+{\left(r+3\right)}^{2}\right)+{\mathbf{K}}\times \left(2\times {r}^{2}+2\times \phantom{\rule{0ex}{0ex}}r+3\times {\mathbf{N}}+4\right)+10$ real elements.
The number of iterations required depends upon the number of parameters in the model and the distance of the usersupplied starting point from the solution.
If the solution lies on the boundary of the admissibility region (stationarity and invertibility region) then G13DDF may get into difficulty and exit with
${\mathbf{IFAIL}}={\mathbf{5}}$. If this exit occurs you are advised to either try a different starting point or a different setting for
EXACT. If this still continues to occur then you are urged to try fitting a more parsimonious model.
You are advised to try and avoid fitting models with an excessive number of parameters since overparameterisation can cause the maximization problem to become illconditioned.
The standardized estimates of the residual series
${\epsilon}_{t}$ (denoted by
${\hat{e}}_{t}$) can easily be calculated by forming the Cholesky decomposition of
$\Sigma $, e.g.,
$G{G}^{\mathrm{T}}$ and setting
${\hat{e}}_{t}={G}^{1}{\hat{\epsilon}}_{t}$.
F07FDF (DPOTRF) may be used to calculate the array
G. The components of
${\hat{e}}_{t}$ which are now uncorrelated at
all lags can sometimes be more easily interpreted.
If your time series model provides a good fit to the data then the residual series should be approximately white noise, i.e., exhibit no serial crosscorrelation. An examination of the residual crosscorrelation matrices should confirm whether this is likely to be so. You are advised to call
G13DSF to provide information for diagnostic checking.
G13DSF returns the residual crosscorrelation matrices along with their asymptotic standard errors.
G13DSF also computes a portmanteau statistic and its asymptotic significance level for testing model adequacy. If
${\mathbf{IFAIL}}={\mathbf{0}}$ or
$5\le {\mathbf{IFAIL}}\le 8$ on exit from G13DDF then the quantities output
K,
N,
V,
KMAX,
IP,
IQ,
PAR,
PARHLD, and
QQ will be suitable for input to
G13DSF.
9 Example
This example shows how to fit a bivariate AR(1) model to two series each of length $48$. $\mu $ will be estimated and ${\varphi}_{1}\left(2,1\right)$ will be constrained to be zero.
9.1 Program Text
Program Text (g13ddfe.f90)
9.2 Program Data
Program Data (g13ddfe.d)
9.3 Program Results
Program Results (g13ddfe.r)