hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_tsa_uni_arima_resid (g13as)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_tsa_uni_arima_resid (g13as) is a diagnostic checking function suitable for use after fitting a Box–Jenkins ARMA model to a univariate time series using nag_tsa_uni_arima_estim (g13ae) or nag_tsa_uni_arima_estim_easy (g13af). The residual autocorrelation function is returned along with an estimate of its asymptotic standard errors and correlations. Also, nag_tsa_uni_arima_resid (g13as) calculates the Box–Ljung portmanteau statistic and its significance level for testing model adequacy.

Syntax

[r, rcm, chi, idf, siglev, ifail] = g13as(v, mr, m, par, ishow, 'n', n, 'npar', npar)
[r, rcm, chi, idf, siglev, ifail] = nag_tsa_uni_arima_resid(v, mr, m, par, ishow, 'n', n, 'npar', npar)

Description

Consider the univariate multiplicative autoregressive-moving average model
ϕBΦBsWt-μ=θBΘBsεt (1)
where Wt, for t=1,2,,n, denotes a time series and εt, for t=1,2,,n, is a residual series assumed to be normally distributed with zero mean and variance σ2 (>0). The εt's are also assumed to be uncorrelated. Here μ is the overall mean term, s is the seasonal period and B is the backward shift operator such that BrWt=Wt-r. The polynomials in (1) are defined as follows:
ϕB=1-ϕ1B-ϕ2B2--ϕpBp  
is the non-seasonal autoregressive (AR) operator;
θ B= 1-θ1B-θ2B2--θqBq  
is the non-seasonal moving average (MA) operator;
ΦBs=1-Φ1Bs-Φ2B2s--ΦPBPs  
is the seasonal AR operator; and
Θ Bs= 1-Θ1Bs-Θ2B2s--ΘQBQs  
is the seasonal MA operator. The model (1) is assumed to be stationary, that is the zeros of ϕB and ΦBs are assumed to lie outside the unit circle. The model (1) is also assumed to be invertible, that is the zeros of θB and ΘBs are assumed to lie outside the unit circle. When both ΦBs and ΘBs are absent from the model, that is when P=Q=0, then the model is said to be non-seasonal.
The estimated residual autocorrelation coefficient at lag l, r^l, is computed as:
r^l=t=l+1nε^t-l-ε-ε^t-ε- t=1n ε^t-ε- 2 ,  l=1,2,  
where ε^t denotes an estimate of the tth residual, εt, and ε-=t=1nε^t/n. A portmanteau statistic, Qm, is calculated from the formula (see Box and Ljung (1978)):
Qm=nn+2l=1mr^l2/n-l  
where m denotes the number of residual autocorrelations computed. (Advice on the choice of m is given in Choice of .) Under the hypothesis of model adequacy, Qm has an asymptotic χ2-distribution on m-p-q-P-Q degrees of freedom. Let r^T=r^1,r^2,,r^m then the variance-covariance matrix of r^ is given by:
Varr^=Im-XXTX-1XT/n.  
The construction of the matrix X is discussed in McLeod (1978). (Note that the mean, μ, and the residual variance, σ2, play no part in calculating Varr^ and therefore are not required as input to nag_tsa_uni_arima_resid (g13as).)
Note:  for additive models with fixed parameter values (i.e., fitted by nag_tsa_multi_varma_estimate (g13dd)) nag_tsa_multi_varma_diag (g13ds) should be used instead of nag_tsa_uni_arima_resid (g13as).

References

Box G E P and Ljung G M (1978) On a measure of lack of fit in time series models Biometrika 65 297–303
McLeod A I (1978) On the distribution of the residual autocorrelations in Box–Jenkins models J. Roy. Statist. Soc. Ser. B 40 296–302

Parameters

Compulsory Input Parameters

1:     vn – double array
vt must contain an estimate of εt, for t=1,2,,n.
If nag_tsa_uni_arima_resid (g13as) is used following a call to nag_tsa_uni_arima_estim (g13ae) then the actual argument v must be exricount1+1 as returned by nag_tsa_uni_arima_estim (g13ae).
If nag_tsa_uni_arima_resid (g13as) is used following a call to nag_tsa_uni_arima_estim_easy (g13af) then the actual argument v must be res as returned by nag_tsa_uni_arima_estim_easy (g13af).
Constraint: v must contain at least two distinct elements.
2:     mr7 int64int32nag_int array
The orders vector (p, d, q, P, D, Q, s) as supplied to nag_tsa_uni_arima_estim (g13ae) or nag_tsa_uni_arima_estim_easy (g13af).
Constraints:
  • p,q,P,Q,s0;
  • p+q+P+Q>0;
  • if s=0, then P=0 and Q=0.
3:     m int64int32nag_int scalar
The value of m, the number of residual autocorrelations to be computed. See Choice of for advice on the value of m.
Constraint: npar<m<n.
4:     parnpar – double array
The parameter estimates in the order ϕ1,ϕ2,,ϕp, θ1,θ2,,θq, Φ1,Φ2,,ΦP, Θ1,Θ2,,ΘQ only.
Constraint: the elements in par must satisfy the stationarity and invertibility conditions.
5:     ishow int64int32nag_int scalar
Must be nonzero if the residual autocorrelations, their standard errors and the portmanteau statistics are to be printed and zero otherwise.
These quantities are available also as output variables in r, rcm, chi, idf and siglev.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the array v.
n, the number of observations in the residual series.
If nag_tsa_uni_arima_resid (g13as) is used following a call to nag_tsa_uni_arima_estim (g13ae), then n must be the value icount2 returned by nag_tsa_uni_arima_estim (g13ae).
If nag_tsa_uni_arima_resid (g13as) is used following a call to nag_tsa_uni_arima_estim_easy (g13af), then n must be the value nres returned by nag_tsa_uni_arima_estim_easy (g13af).
Constraint: n3.
2:     npar int64int32nag_int scalar
Default: the dimension of the array par.
The total number of ϕ, θ, Φ and Θ parameters, i.e., npar=p+q+P+Q.
Constraint: npar=mr1+mr3+mr4+mr6.

Output Parameters

1:     rm – double array
An estimate of the residual autocorrelation coefficient at lag l, for l=1,2,,m. If ifail=3 on exit then all elements of r are set to zero.
2:     rcmldrcmm – double array
The estimated standard errors and correlations of the elements in the array r. The correlation between ri and rj is returned as rcmij except that if i=j then rcmij contains the standard error of ri. If on exit, ifail5, then all off-diagonal elements of rcm are set to zero and all diagonal elements are set to 1/n.
3:     chi – double scalar
The value of the portmanteau statistic, Qm. If ifail=3 on exit then chi is returned as zero.
4:     idf int64int32nag_int scalar
The number of degrees of freedom of chi.
5:     siglev – double scalar
The significance level of chi based on idf degrees of freedom. If ifail=3 on exit, siglev is returned as one.
6:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Note: nag_tsa_uni_arima_resid (g13as) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

   ifail=1
On entry,mr1<0,
ormr3<0,
ormr4<0,
ormr6<0,
ormr7<0,
ormr7=0 and either mr4>0 or mr6>0,
ormr1=mr3=mr4=mr6=0,
ormnpar,
ormn,
orn<3,
ornparmr1+mr3+mr4+mr6,
orldrcm<m,
orliw is too small,
orlwork is too small.
   ifail=2
On entry, the autoregressive (or moving average) parameters are extremely close to or outside the stationarity (or invertibility) region. To proceed, you must supply different parameter estimates in the array par.
W  ifail=3
On entry, the residuals are practically identical giving zero (or near zero) variance. In this case chi is set to zero and siglev to one and all the elements of r are set to zero.
   ifail=4
This is an unlikely exit brought about by an excessive number of iterations being needed to evaluate the zeros of the AR or MA polynomials. All output arguments are undefined.
   ifail=5
On entry, one or more of the AR operators has a factor in common with one or more of the MA operators. To proceed, this common factor must be deleted from the model. In this case, the off-diagonal elements of rcm are returned as zero and the diagonal elements set to 1/n. All other output quantities will be correct.
   ifail=6
This is an unlikely exit. At least one of the diagonal elements of rcm was found to be either negative or zero. In this case all off-diagonal elements of rcm are returned as zero and all diagonal elements of rcm set to 1/n.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

The computations are believed to be stable.

Further Comments

Timing

The time taken by nag_tsa_uni_arima_resid (g13as) depends upon the number of residual autocorrelations to be computed, m.

Choice of m

The number of residual autocorrelations to be computed, m should be chosen to ensure that when the ARMA model (1) is written as either an infinite order autoregressive process:
Wt-μ=j=1πjWt-j-μ+εt  
or as an infinite order moving average process:
Wt-μ=j= 1ψjεt-j+εt  
then the two sequences π1,π2, and ψ1,ψ2, are such that πj and ψj are approximately zero for j>m. An overestimate of m is therefore preferable to an under-estimate of m. In many instances the choice m=10 will suffice. In practice, to be on the safe side, you should try setting m=20.

Approximate Standard Errors

When ifail=5 or 6 all the standard errors in rcm are set to 1/n. This is the asymptotic standard error of r^l when all the autoregressive and moving average parameters are assumed to be known rather than estimated.

Alternative Applications

nag_tsa_uni_arima_resid (g13as) may be used for diagnostic checking of suitable univariate ARMA models, as described in Description, fitted by nag_tsa_multi_inputmod_estim (g13be) or nag_tsa_multi_varma_estimate (g13dd). Great care must be taken in obtaining the input values for nag_tsa_uni_arima_resid (g13as) from the output values from nag_tsa_multi_inputmod_estim (g13be) or nag_tsa_multi_varma_estimate (g13dd).

Example

This example fits an ARIMA1,1,2 model to a series of 30 observations. 10 residual autocorrelations are computed.
function g13as_example


fprintf('g13as example results\n\n');

% data
x = [-217 -177 -166 -136 -110  -95  -64  -37  -14  -25 ...
      -51  -62  -73  -88 -113 -120  -83  -33  -19   21 ...
       17   44   44   78   88  122  126  114   85   64];
n = int64(numel(x));

% orders
mr = [int64(1);1;2;0;0;0;0];

% sizes
c   = 0;

% Initial estimates
par = [0; 0; 0];

% Fit ARIMA model
[par, c, s, ndf, sd, cm, st, nst, itc, isf, res, nres, ifail] = ...
  g13af( ...
         mr, par, c, x);

% Perform diagnostic checks
m     = int64(10);
ishow = int64(1);

[r, rcm, chi, idf, siglev, ifail] = ...
  g13as( ...
         res, mr, m, par, ishow, 'n', nres);


g13as example results

 RESIDUAL AUTOCORRELATION FUNCTION
 ---------------------------------

 LAG  K      1      2      3      4      5      6      7
 R(K)      0.020 -0.040 -0.019  0.068 -0.143 -0.046 -0.205
 ST.ERROR  0.007  0.125  0.128  0.150  0.168  0.168  0.178
 ---------------------------------------------------------
 LAG  K      8      9     10
 R(K)     -0.108 -0.001 -0.058
 ST.ERROR  0.179  0.181  0.183
 ---------------------------------------------------------

 BOX - LJUNG PORTMANTEAU STATISTIC =      3.465
                SIGNIFICANCE LEVEL =      0.839
 (BASED ON   7 DEGREES OF FREEDOM)

 VALUE OF IFAIL PARAMETER ON EXIT FROM G13ASF =   0

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015