nag_tsa_multi_cross_corr (g13dmc) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG C Library Manual
NAG Library Function Document
nag_tsa_multi_cross_corr (g13dmc)
+
−
Contents
1
Purpose
2
Specification
3
Description
4
References
5
Arguments
6
Error Indicators and Warnings
7
Accuracy
8
Further Comments
+
−
9
Example
9.1
Program Text
9.2
Program Data
9.3
Program Results
1 Purpose
nag_tsa_multi_cross_corr (g13dmc) calculates the sample cross-correlation (or cross-covariance) matrices of a multivariate time series.
2 Specification
#include <nag.h>
#include <nagg13.h>
void
nag_tsa_multi_cross_corr (Nag_CovOrCorr
matrix
, Integer
k
, Integer
n
, Integer
m
, const double
w
[], double
wmean
[], double
r0
[], double
r
[], NagError *
fail
)
3 Description
Let
W
t
=
w
1
t
,
w
2
t
,
…
,
w
k
t
T
, for
t
=
1
,
2
,
…
,
n
, denote
n
observations of a vector of
k
time series. The sample cross-covariance matrix at lag
l
is defined to be the
k
by
k
matrix
C
^
l
, whose (
i
,
j
)th element is given by
C
^
i
j
l
=
1
n
∑
t
=
l
+
1
n
w
i
t
-
l
-
w
-
i
w
j
t
-
w
-
j
,
l
=
0
,
1
,
2
,
…
,
m
,
i
=
1
,
2
,
…
,
k
and
j
=
1
,
2
,
…
,
k
,
where
w
-
i
and
w
-
j
denote the sample means for the
i
th and
j
th series respectively. The sample cross-correlation matrix at lag
l
is defined to be the
k
by
k
matrix
R
^
l
, whose
i
,
j
th element is given by
R
^
i
j
l
=
C
^
i
j
l
C
^
i
i
0
C
^
j
j
0
,
l
=
0
,
1
,
2
,
…
,
m
,
i
=
1
,
2
,
…
,
k
and
j
=
1
,
2
,
…
,
k
.
The number of lags,
m
, is usually taken to be at most
n
/
4
.
If
W
t
follows a vector moving average model of order
q
, then it can be shown that the theoretical cross-correlation matrices
R
l
are zero beyond lag
q
. In order to help spot a possible cut-off point, the elements of
R
^
l
are usually compared to their approximate standard error of 1/
n
. For further details see, for example,
Wei (1990)
.
The function uses a single pass through the data to compute the means and the cross-covariance matrix at lag zero. The cross-covariance matrices at further lags are then computed on a second pass through the data.
4 References
Wei W W S (1990)
Time Series Analysis: Univariate and Multivariate Methods
Addison–Wesley
West D H D (1979) Updating mean and variance estimates: An improved method
Comm. ACM
22
532–555
5 Arguments
1:
matrix
–
Nag_CovOrCorr
Input
On entry
: indicates whether the cross-covariance or cross-correlation matrices are to be computed.
matrix
=
Nag_AutoCov
The cross-covariance matrices are computed.
matrix
=
Nag_AutoCorr
The cross-correlation matrices are computed.
Constraint
:
matrix
=
Nag_AutoCov
or
Nag_AutoCorr
.
2:
k
–
Integer
Input
On entry
:
k
, the dimension of the multivariate time series.
Constraint
:
k
≥
1
.
3:
n
–
Integer
Input
On entry
:
n
, the number of observations in the series.
Constraint
:
n
≥
2
.
4:
m
–
Integer
Input
On entry
:
m
, the number of cross-correlation (or cross-covariance) matrices to be computed. If in doubt set
m
=
10
. However it should be noted that
m
is usually taken to be at most
n
/
4
.
Constraint
:
1
≤
m
<
n
.
5:
w
[
k
×
n
]
–
const double
Input
On entry
:
w
[
t
-
1
k
+
i
-
1
]
must contain the value for series
i
at time
t
, for
i
=
1
,
2
,
…
,
k
and
t
=
1
,
2
,
…
,
n
.
6:
wmean
[
k
]
–
double
Output
On exit
: the means,
w
-
i
, for
i
=
1
,
2
,
…
,
k
.
7:
r0
[
k
×
k
]
–
double
Output
On exit
: if
matrix
=
Nag_AutoCov
,
r0
[
j
-
1
k
+
i
-
1
]
contains the
i
,
j
th element of the sample cross-covariance matrix.
If
matrix
=
Nag_AutoCorr
,
r0
[
j
-
1
k
+
i
-
1
]
,
i
≠
j
contains the
i
,
j
th element of the sample cross-correlation matrix and
r0
[
i
-
1
k
+
i
-
1
]
contains the standard deviation of the
i
th series.
8:
r
[
k
×
k
×
m
]
–
double
Output
On exit
: if
matrix
=
Nag_AutoCov
,
r
[
l
-
1
k
2
+
j
-
1
k
+
i
-
1
]
contains the
i
,
j
th element of the sample cross-covariance matrix at lag
l
.
If
matrix
=
Nag_AutoCorr
, then it contains the
i
,
j
th element of the sample cross-correlation matrix lag
l
, for
l
=
1
,
2
,
…
,
m
,
i
=
1
,
2
,
…
,
k
and
j
=
1
,
2
,
…
,
k
.
9:
fail
–
NagError *
Input/Output
The NAG error argument (see
Section 3.6
in the Essential Introduction).
6 Error Indicators and Warnings
NE_BAD_PARAM
On entry, argument
value
had an illegal value.
NE_INT
On entry,
k
=
value
.
Constraint:
k
≥
1
.
On entry,
n
=
value
.
Constraint:
n
≥
2
.
NE_INT_2
On entry,
m
=
value
and
n
=
value
.
Constraint:
m
≥
1
and
m
<
n
.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG
for assistance.
NE_ZERO_VARIANCE
On entry, at least one of the series is such that all its elements are practically identical giving zero (or near zero) variance.
7 Accuracy
For a discussion of the accuracy of the one-pass algorithm used to compute the sample cross-covariances at lag zero see
West (1979)
. For the other lags a two-pass algorithm is used to compute the cross-covariances; the accuracy of this algorithm is also discussed in
West (1979)
. The accuracy of the cross-correlations will depend on the accuracy of the computed cross-covariances.
8 Further Comments
The time taken is roughly proportional to
m
n
k
2
.
9 Example
This program computes the sample cross-correlation matrices of two time series of length
48
, up to lag
10
. It also prints the cross-correlation matrices together with plots of symbols indicating which elements of the correlation matrices are significant. Three * represent significance at the
0.5
% level, two * represent significance at the 1% level and a single * represents significance at the 5% level. The * are plotted above or below the line depending on whether the elements are significant in the positive or negative direction.
9.1 Program Text
Program Text (g13dmce.c)
9.2 Program Data
Program Data (g13dmce.d)
9.3 Program Results
Program Results (g13dmce.r)
nag_tsa_multi_cross_corr (g13dmc) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG C Library Manual
© The Numerical Algorithms Group Ltd, Oxford, UK. 2012