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)

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)Φ(Bs)(Wtμ) = θ(B)Θ(Bs)εt
ϕ(B)Φ(Bs)(Wt-μ)=θ(B)Θ(Bs)εt
(1)
where WtWt, for t = 1,2,,nt=1,2,,n, denotes a time series and εtεt, for t = 1,2,,nt=1,2,,n, is a residual series assumed to be normally distributed with zero mean and variance σ2σ2 ( > 0>0). The εtεt's are also assumed to be uncorrelated. Here μμ is the overall mean term, ss is the seasonal period and BB is the backward shift operator such that BrWt = WtrBrWt=Wt-r. The polynomials in (1) are defined as follows:
φ(B) = 1φ1Bφ2B2φpBp
ϕ(B)=1-ϕ1B-ϕ2B2--ϕpBp
is the non-seasonal autoregressive (AR) operator;
θ (B) = 1θ1Bθ2B2θqBq
θ (B)= 1-θ1B-θ2B2--θqBq
is the non-seasonal moving average (MA) operator;
Φ(Bs) = 1Φ1BsΦ2B2sΦPBPs
Φ(Bs)=1-Φ1Bs-Φ2B2s--ΦPBPs
is the seasonal AR operator; and
Θ (Bs) = 1Θ1BsΘ2B2sΘQBQs
Θ (Bs)= 1-Θ1Bs-Θ2B2s--ΘQBQs
is the seasonal MA operator. The model (1) is assumed to be stationary, that is the zeros of φ(B)ϕ(B) and Φ(Bs)Φ(Bs) are assumed to lie outside the unit circle. The model (1) is also assumed to be invertible, that is the zeros of θ(B)θ(B) and Θ(Bs)Θ(Bs) are assumed to lie outside the unit circle. When both Φ(Bs)Φ(Bs) and Θ(Bs)Θ(Bs) are absent from the model, that is when P = Q = 0P=Q=0, then the model is said to be non-seasonal.
The estimated residual autocorrelation coefficient at lag ll, lr^l, is computed as:
l = (t = l + 1n(ε̂tlε)(ε̂tε))/(t = 1n(ε̂tε)2),  l = 1,2,
r^l=t=l+1n(ε^t-l-ε-)(ε^t-ε-) t=1n (ε^t-ε-) 2 ,  l=1,2,
where ε̂tε^t denotes an estimate of the ttth residual, εtεt, and ε = t = 1nε̂t / nε-=t=1nε^t/n. A portmanteau statistic, Q(m)Q(m), is calculated from the formula (see Box and Ljung (1978)):
m
Q(m) = n(n + 2)l2 / (nl)
l = 1
Q(m)=n(n+2)l=1mr^l2/(n-l)
where mm denotes the number of residual autocorrelations computed. (Advice on the choice of mm is given in Section [Choice of ].) Under the hypothesis of model adequacy, Q(m)Q(m) has an asymptotic χ2χ2-distribution on mpqPQm-p-q-P-Q degrees of freedom. Let T = (1,2,,m)r^T=(r^1,r^2,,r^m) then the variance-covariance matrix of r^ is given by:
Var() = [ImX(XTX)1XT] / n.
Var(r^)=[Im-X(XTX)-1XT]/n.
The construction of the matrix XX is discussed in McLeod (1978). (Note that the mean, μμ, and the residual variance, σ2σ2, play no part in calculating Var()Var(r^) 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:     v(n) – double array
n, the dimension of the array, must satisfy the constraint n3n3.
v(t)vt must contain an estimate of εtεt, for t = 1,2,,nt=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 exr(icount(1) + 1)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: vv must contain at least two distinct elements.
2:     mr(77) – int64int32nag_int array
The orders vector (pp, dd, qq, PP, DD, QQ, ss) as supplied to nag_tsa_uni_arima_estim (g13ae) or nag_tsa_uni_arima_estim_easy (g13af).
Constraints:
  • p,q,P,Q,s0p,q,P,Q,s0;
  • p + q + P + Q > 0p+q+P+Q>0;
  • if s = 0s=0, then P = 0P=0 and Q = 0Q=0.
3:     m – int64int32nag_int scalar
The value of mm, the number of residual autocorrelations to be computed. See Section [Choice of ] for advice on the value of m.
Constraint: npar < m < nnpar<m<n.
4:     par(npar) – double array
npar, the dimension of the array, must satisfy the constraint npar = mr(1) + mr(3) + mr(4) + mr(6)npar=mr1+mr3+mr4+mr6.
The parameter estimates in the order φ1,φ2,,φpϕ1,ϕ2,,ϕp, θ1,θ2,,θqθ1,θ2,,θq, Φ1,Φ2,,ΦPΦ1,Φ2,,ΦP, Θ1,Θ2,,ΘQΘ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.
nn, 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 icount(2)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: n3n3.
2:     npar – int64int32nag_int scalar
Default: The dimension of the array par.
The total number of φϕ, θθ, ΦΦ and ΘΘ parameters, i.e., npar = p + q + P + Qnpar=p+q+P+Q.
Constraint: npar = mr(1) + mr(3) + mr(4) + mr(6)npar=mr1+mr3+mr4+mr6.

Input Parameters Omitted from the MATLAB Interface

ldrcm iw liw work lwork

Output Parameters

1:     r(m) – double array
An estimate of the residual autocorrelation coefficient at lag ll, for l = 1,2,,ml=1,2,,m. If ifail = 3ifail=3 on exit then all elements of r are set to zero.
2:     rcm(ldrcm,m) – double array
ldrcmmldrcmm.
The estimated standard errors and correlations of the elements in the array r. The correlation between r(i)ri and r(j)rj is returned as rcm(i,j)rcmij except that if i = ji=j then rcm(i,j)rcmij contains the standard error of r(i)ri. If on exit, ifail5ifail5, then all off-diagonal elements of rcm are set to zero and all diagonal elements are set to 1 / sqrt(n)1/n.
3:     chi – double scalar
The value of the portmanteau statistic, Q(m)Q(m). If ifail = 3ifail=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 = 3ifail=3 on exit, siglev is returned as one.
6:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 = 1ifail=1
On entry,mr(1) < 0mr1<0,
ormr(3) < 0mr3<0,
ormr(4) < 0mr4<0,
ormr(6) < 0mr6<0,
ormr(7) < 0mr7<0,
ormr(7) = 0mr7=0 and either mr(4) > 0mr4>0 or mr(6) > 0mr6>0,
ormr(1) = mr(3) = mr(4) = mr(6) = 0mr1=mr3=mr4=mr6=0,
ormnparmnpar,
ormnmn,
orn < 3n<3,
ornparmr(1) + mr(3) + mr(4) + mr(6)nparmr1+mr3+mr4+mr6,
orldrcm < mldrcm<m,
orliw is too small,
orlwork is too small.
  ifail = 2ifail=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 = 3ifail=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 = 4ifail=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 parameters are undefined.
  ifail = 5ifail=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 / sqrt(n)1/n. All other output quantities will be correct.
  ifail = 6ifail=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 / sqrt(n)1/n.

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, mm.

Choice of m

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

Approximate Standard Errors

When ifail = 5ifail=5 or 66 all the standard errors in rcm are set to 1 / sqrt(n)1/n. This is the asymptotic standard error of lr^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 Section [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

function nag_tsa_uni_arima_resid_example
v = [19.62746933753217;
     -5.309287748702281;
     9.798293298952524;
     15.24123763096101;
     -9.169280254619032;
     16.11067630246432;
     15.39291433217872;
     -5.450004312837414;
     -27.6205284052683;
     -18.13061645026666;
     5.720197603730954;
     -13.08812421913039;
     -22.71514540998739;
     -14.92555865550874;
     4.693009266513346;
     33.54056385487841;
     19.71375888111006;
     -27.33603163811242;
     32.12310786592178;
     -11.76808232386082;
     1.152380086683287;
     -1.775570325352465;
     23.68209327485152;
     -10.62375411730706;
     13.96192179999122;
     -5.272654385984258;
     -28.78678842222793;
     -20.65731709475202;
     -2.255525918186007];
mr = [int64(1);1;2;0;0;0;0];
m = int64(10);
par = [-0.05429075588805302;
     -0.5547824600332715;
     -0.6734171925737445];
ishow = int64(1);
[r, rcm, chi, idf, siglev, ifail] = nag_tsa_uni_arima_resid(v, mr, m, par, ishow)
 
 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

r =

    0.0199
   -0.0401
   -0.0191
    0.0683
   -0.1427
   -0.0456
   -0.2048
   -0.1082
   -0.0007
   -0.0581


rcm =

  Columns 1 through 9

    0.0067    0.9986    0.2512    0.5337   -0.4515   -0.0672    0.3230   -0.1352   -0.1394
    0.9986    0.1252    0.3019    0.5451   -0.4251   -0.0920    0.3193   -0.1175   -0.1466
    0.2512    0.3019    0.1277    0.3989    0.3692   -0.4447   -0.0019    0.2821   -0.1538
    0.5337    0.5451    0.3989    0.1503    0.0587    0.2843   -0.1867   -0.0770    0.1658
   -0.4515   -0.4251    0.3692    0.0587    0.1683    0.0854    0.0939   -0.1056   -0.0041
   -0.0672   -0.0920   -0.4447    0.2843    0.0854    0.1682    0.0602    0.1049   -0.0975
    0.3230    0.3193   -0.0019   -0.1867    0.0939    0.0602    0.1777    0.0123    0.0538
   -0.1352   -0.1175    0.2821   -0.0770   -0.1056    0.1049    0.0123    0.1793    0.0320
   -0.1394   -0.1466   -0.1538    0.1658   -0.0041   -0.0975    0.0538    0.0320    0.1809
    0.1652    0.1576   -0.1015   -0.0401    0.0717   -0.0157   -0.0375    0.0305    0.0080

  Column 10

    0.1652
    0.1576
   -0.1015
   -0.0401
    0.0717
   -0.0157
   -0.0375
    0.0305
    0.0080
    0.1835


chi =

    3.4654


idf =

                    7


siglev =

    0.8389


ifail =

                    0


function g13as_example
v = [19.62746933753217;
     -5.309287748702281;
     9.798293298952524;
     15.24123763096101;
     -9.169280254619032;
     16.11067630246432;
     15.39291433217872;
     -5.450004312837414;
     -27.6205284052683;
     -18.13061645026666;
     5.720197603730954;
     -13.08812421913039;
     -22.71514540998739;
     -14.92555865550874;
     4.693009266513346;
     33.54056385487841;
     19.71375888111006;
     -27.33603163811242;
     32.12310786592178;
     -11.76808232386082;
     1.152380086683287;
     -1.775570325352465;
     23.68209327485152;
     -10.62375411730706;
     13.96192179999122;
     -5.272654385984258;
     -28.78678842222793;
     -20.65731709475202;
     -2.255525918186007];
mr = [int64(1);1;2;0;0;0;0];
m = int64(10);
par = [-0.05429075588805302;
     -0.5547824600332715;
     -0.6734171925737445];
ishow = int64(1);
[r, rcm, chi, idf, siglev, ifail] = g13as(v, mr, m, par, ishow)
 
 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

r =

    0.0199
   -0.0401
   -0.0191
    0.0683
   -0.1427
   -0.0456
   -0.2048
   -0.1082
   -0.0007
   -0.0581


rcm =

  Columns 1 through 9

    0.0067    0.9986    0.2512    0.5337   -0.4515   -0.0672    0.3230   -0.1352   -0.1394
    0.9986    0.1252    0.3019    0.5451   -0.4251   -0.0920    0.3193   -0.1175   -0.1466
    0.2512    0.3019    0.1277    0.3989    0.3692   -0.4447   -0.0019    0.2821   -0.1538
    0.5337    0.5451    0.3989    0.1503    0.0587    0.2843   -0.1867   -0.0770    0.1658
   -0.4515   -0.4251    0.3692    0.0587    0.1683    0.0854    0.0939   -0.1056   -0.0041
   -0.0672   -0.0920   -0.4447    0.2843    0.0854    0.1682    0.0602    0.1049   -0.0975
    0.3230    0.3193   -0.0019   -0.1867    0.0939    0.0602    0.1777    0.0123    0.0538
   -0.1352   -0.1175    0.2821   -0.0770   -0.1056    0.1049    0.0123    0.1793    0.0320
   -0.1394   -0.1466   -0.1538    0.1658   -0.0041   -0.0975    0.0538    0.0320    0.1809
    0.1652    0.1576   -0.1015   -0.0401    0.0717   -0.0157   -0.0375    0.0305    0.0080

  Column 10

    0.1652
    0.1576
   -0.1015
   -0.0401
    0.0717
   -0.0157
   -0.0375
    0.0305
    0.0080
    0.1835


chi =

    3.4654


idf =

                    7


siglev =

    0.8389


ifail =

                    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–2013