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_autocorr_part (g13ac)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_tsa_uni_autocorr_part (g13ac) calculates partial autocorrelation coefficients given a set of autocorrelation coefficients. It also calculates the predictor error variance ratios for increasing order of finite lag autoregressive predictor, and the autoregressive parameters associated with the predictor of maximum order.

Syntax

[p, v, ar, nvl, ifail] = g13ac(r, nl, 'nk', nk)
[p, v, ar, nvl, ifail] = nag_tsa_uni_autocorr_part(r, nl, 'nk', nk)

Description

The data consist of values of autocorrelation coefficients r1,r2,,rK, relating to lags 1,2,,K. These will generally (but not necessarily) be sample values such as may be obtained from a time series xt using nag_tsa_uni_autocorr (g13ab).
The partial autocorrelation coefficient at lag l may be identified with the parameter pl,l in the autoregression
xt = cl + pl,1 xt-1 + pl,2 xt-2 ++ pl,l xt-l + el,t  
where el,t is the predictor error.
The first subscript l of pl,l and el,t emphasizes the fact that the parameters will in general alter as further terms are introduced into the equation (i.e., as l is increased).
The parameters are determined from the autocorrelation coefficients by the Yule–Walker equations
ri = pl,1 ri-1 + pl,2 ri-2 ++ pl,l ri-l ,   i=1,2,,l  
taking rj=rj when j<0, and r0=1.
The predictor error variance ratio vl=varel,t/varxt is defined by
vl = 1- pl,1 r1 - pl,2 r2 -- pl,l rl .  
The above sets of equations are solved by a recursive method (the Durbin–Levinson algorithm). The recursive cycle applied for l=1,2,,L-1, where L is the number of partial autocorrelation coefficients required, is initialized by setting p1,1=r1 and v1=1-r12.
Then
p l + 1 , l + 1 = r l + 1 - p l , 1 r l - p l , 2 r l - 1 - - p l , l r 1 / v l p l + 1 , j = p l , j - p l + 1 , l + 1 p l , l + 1 - j ,   j=1,2,,l v l + 1 = v l 1 - p l + 1 , l + 1 1 + p l + 1 , l + 1 .  
If the condition pl,l1 occurs, say when l=l0, it indicates that the supplied autocorrelation coefficients do not form a positive definite sequence (see Hannan (1960)), and the recursion is not continued. The autoregressive parameters are overwritten at each recursive step, so that upon completion the only available values are pLj, for j=1,2,,L, or pl0-1,j if the recursion has been prematurely halted.

References

Box G E P and Jenkins G M (1976) Time Series Analysis: Forecasting and Control (Revised Edition) Holden–Day
Durbin J (1960) The fitting of time series models Rev. Inst. Internat. Stat. 28 233
Hannan E J (1960) Time Series Analysis Methuen

Parameters

Compulsory Input Parameters

1:     rnk – double array
The autocorrelation coefficient relating to lag k, for k=1,2,,K.
2:     nl int64int32nag_int scalar
L, the number of partial autocorrelation coefficients required.
Constraint: 0<nlnk.

Optional Input Parameters

1:     nk int64int32nag_int scalar
Default: the dimension of the array r.
K, the number of lags. The lags range from 1 to K and do not include zero.
Constraint: nk>0.

Output Parameters

1:     pnl – double array
pl contains the partial autocorrelation coefficient at lag l, pl,l, for l=1,2,,nvl.
2:     vnl – double array
vl contains the predictor error variance ratio vl, for l=1,2,,nvl.
3:     arnl – double array
The autoregressive parameters of maximum order, i.e., pLj if ifail=0, or pl0-1,j if ifail=3, for j=1,2,,nvl.
4:     nvl int64int32nag_int scalar
The number of valid values in each of p, v and ar. Thus in the case of premature termination at iteration l0 (see Description), nvl is returned as l0-1.
5:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and 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,nk0,
ornl0,
ornk<nl.
   ifail=2
On entry, the autocorrelation coefficient of lag 1 has an absolute value greater than or equal to 1.0; no recursions could be performed.
W  ifail=3
Recursion has been prematurely terminated; the supplied autocorrelation coefficients do not form a positive definite sequence (see Description). Argument nvl returns the number of valid values computed.
   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

The time taken by nag_tsa_uni_autocorr_part (g13ac) is proportional to nvl 2.

Example

This example uses an input series of 10 sample autocorrelation coefficients derived from the original series of sunspot numbers generated by the nag_tsa_uni_autocorr (g13ab) example program. The results show five values of each of the three output arrays: partial autocorrelation coefficients, predictor error variance ratios and autoregressive parameters. All of these were valid.
function g13ac_example


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

% coefficients for all 49 lags
r = [ 0.8004    0.4355    0.0328   -0.2835   -0.4505 ...
     -0.4242   -0.2419    0.0550    0.3783    0.5857 ...
      0.6123    0.4389    0.1538   -0.1626   -0.3828 ...
     -0.4637   -0.4133   -0.2630   -0.0711    0.1217 ...
      0.2547    0.2681    0.1211   -0.0683   -0.2248 ...
     -0.3187   -0.3365   -0.2748   -0.1696   -0.0500 ...
      0.0605    0.1131    0.1132    0.0604   -0.0171 ...
     -0.0909   -0.1269   -0.1345   -0.1056   -0.0581 ...
     -0.0119    0.0272    0.0496    0.0592    0.0167 ...
     -0.0138   -0.0328   -0.0383   -0.0287];

nl = int64(5);

% Calculate partial ACF
[p, v, ar, nvl, ifail] = g13ac( ...
                                r, nl, 'nk', int64(10));

% Display results
fprintf('Lag  Partial    Predictor error  Autoregressive\n');
fprintf('     autocorrn  variance ratio   parameter\n\n');
ivar = double([1:nvl])';
fprintf('%2d%9.3f%16.3f%14.3f\n',[ivar p v ar]');

% For plotting use all posible lags
nl = int64(numel(r));
[p, v, ar, nvl, ifail] = g13ac( ...
                                r, nl);

fig1 = figure;
refline = 1.96/sqrt(50);
hold on
h = bar(p,0.1);
h.FaceColor = [1 0 0];
h.EdgeColor = [1 0 0];
h.ShowBaseLine = 'off';
plot([0 50],[refline refline],'green');
plot([0 50],[-refline -refline],'green');
axis([0 50 -0.6 1]);
ax = gca;
ax.YTick = [-0.6:0.2:1];
ax.XTick = [0:10:50];
xlabel('Lag');
ylabel('PACF');
title('Partial autocorrelation coefficients');
hold off

g13ac example results

Lag  Partial    Predictor error  Autoregressive
     autocorrn  variance ratio   parameter

 1    0.800           0.359         1.108
 2   -0.571           0.242        -0.290
 3   -0.239           0.228        -0.193
 4   -0.049           0.228        -0.014
 5   -0.032           0.228        -0.032
g13ac_fig1.png
This plot shows the partial autocorrelations for all possible lag values. Reference lines are given at ±z0.975/n.

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