Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_tsa_multi_spectrum_bivar (g13ce)

## Purpose

For a bivariate time series, nag_tsa_multi_spectrum_bivar (g13ce) calculates the cross amplitude spectrum and squared coherency, together with lower and upper bounds from the univariate and bivariate (cross) spectra.

## Syntax

[ca, calw, caup, t, sc, sclw, scup, ifail] = g13ce(xg, yg, xyrg, xyig, stats, 'ng', ng)
[ca, calw, caup, t, sc, sclw, scup, ifail] = nag_tsa_multi_spectrum_bivar(xg, yg, xyrg, xyig, stats, 'ng', ng)

## Description

Estimates of the cross amplitude spectrum A(ω)$A\left(\omega \right)$ and squared coherency W(ω)$W\left(\omega \right)$ are calculated for each frequency ω$\omega$ as
 A(ω) = |fxy(ω)| = sqrt(cf(ω)2 + qf(ω)2)  and W(ω) = (|fxy(ω)|2)/(fxx(ω)fyy(ω)),
$A(ω)=|fxy(ω)|=cf (ω) 2+qf (ω) 2 and W(ω)= |fxy(ω)|2fxx(ω)fyy(ω) ,$
where
• cf(ω)$cf\left(\omega \right)$ and qf(ω)$qf\left(\omega \right)$ are the co-spectrum and quadrature spectrum estimates between the series, i.e., the real and imaginary parts of the cross spectrum fxy(ω)${f}_{xy}\left(\omega \right)$ as obtained using nag_tsa_multi_spectrum_lag (g13cc) or nag_tsa_multi_spectrum_daniell (g13cd);
• fxx(ω)${f}_{xx}\left(\omega \right)$ and fyy(ω)${f}_{yy}\left(\omega \right)$ are the univariate spectrum estimates for the two series as obtained using nag_tsa_uni_spectrum_lag (g13ca) or nag_tsa_uni_spectrum_daniell (g13cb).
The same type and amount of smoothing should be used for these estimates, and this is specified by the degrees of freedom and bandwidth values which are passed from the calls of nag_tsa_uni_spectrum_lag (g13ca) or nag_tsa_uni_spectrum_daniell (g13cb).
Upper and lower 95%$95%$ confidence limits for the cross amplitude are given approximately by
 A(ω) [1 ± (1.96 / sqrt(d))sqrt(W(ω) − 1 + 1)] , $A(ω) [1±(1.96/d)W(ω)-1+1] ,$
except that a negative lower limit is reset to 0.0$0.0$, in which case the approximation is rather poor. You are therefore particularly recommended to compare the coherency estimate W(ω)$W\left(\omega \right)$ with the critical value T$T$ derived from the upper 5%$5%$ point of the F$F$-distribution on (2,d2)$\left(2,d-2\right)$ degrees of freedom:
 T = (2F)/(d − 2 + 2F), $T=2F d-2+2F ,$
where d$d$ is the degrees of freedom associated with the univariate spectrum estimates. The value of T$T$ is returned by the function.
The hypothesis that the series are unrelated at frequency ω$\omega$, i.e., that both the true cross amplitude and coherency are zero, may be rejected at the 5%$5%$ level if W(ω) > T$W\left(\omega \right)>T$. Tests at two frequencies separated by more than the bandwidth may be taken to be independent.
The confidence limits on A(ω)$A\left(\omega \right)$ are strictly appropriate only at frequencies for which the coherency is significant. The same applies to the confidence limits on W(ω)$W\left(\omega \right)$ which are however calculated at all frequencies using the approximation that arctanh(sqrt(W(l)))$\mathrm{arctanh}\left(\sqrt{W\left(l\right)}\right)$ is Normal with variance 1 / d$1/d$.

## References

Bloomfield P (1976) Fourier Analysis of Time Series: An Introduction Wiley
Jenkins G M and Watts D G (1968) Spectral Analysis and its Applications Holden–Day

## Parameters

### Compulsory Input Parameters

1:     xg(ng) – double array
ng, the dimension of the array, must satisfy the constraint ng1${\mathbf{ng}}\ge 1$.
The ng univariate spectral estimates, fxx(ω)${f}_{xx}\left(\omega \right)$, for the x$x$ series.
2:     yg(ng) – double array
ng, the dimension of the array, must satisfy the constraint ng1${\mathbf{ng}}\ge 1$.
The ng univariate spectral estimates, fyy(ω)${f}_{yy}\left(\omega \right)$, for the y$y$ series.
3:     xyrg(ng) – double array
ng, the dimension of the array, must satisfy the constraint ng1${\mathbf{ng}}\ge 1$.
The real parts, cf(ω)$cf\left(\omega \right)$, of the ng bivariate spectral estimates for the x$x$ and y$y$ series. The x$x$ series leads the y$y$ series.
4:     xyig(ng) – double array
ng, the dimension of the array, must satisfy the constraint ng1${\mathbf{ng}}\ge 1$.
The imaginary parts, qf(ω)$qf\left(\omega \right)$, of the ng bivariate spectral estimates for the x$x$ and y$y$ series. The x$x$ series leads the y$y$ series.
Note:  the two univariate and the bivariate spectra must each have been calculated using the same method of smoothing. For rectangular, Bartlett, Tukey or Parzen smoothing windows, the same cut-off point of lag window and the same frequency division of the spectral estimates must be used. For the trapezium frequency smoothing window, the frequency width and the shape of the window and the frequency division of the spectral estimates must be the same. The spectral estimates and statistics must also be unlogged.
5:     stats(4$4$) – double array
The four associated statistics for the univariate spectral estimates for the x$x$ and y$y$ series. stats(1)${\mathbf{stats}}\left(1\right)$ contains the degrees of freedom, stats(2)${\mathbf{stats}}\left(2\right)$ and stats(3)${\mathbf{stats}}\left(3\right)$ contain the lower and upper bound multiplying factors respectively and stats(4)${\mathbf{stats}}\left(4\right)$ contains the bandwidth.
Constraints:
• stats(1)3.0${\mathbf{stats}}\left(1\right)\ge 3.0$;
• 0.0 < stats(2)1.0$0.0<{\mathbf{stats}}\left(2\right)\le 1.0$;
• stats(3)1.0${\mathbf{stats}}\left(3\right)\ge 1.0$.

### Optional Input Parameters

1:     ng – int64int32nag_int scalar
Default: The dimension of the arrays xg, yg, xyrg, xyig. (An error is raised if these dimensions are not equal.)
The number of spectral estimates in each of the arrays xg, yg, xyrg and xyig. It is also the number of cross amplitude spectral and squared coherency estimates.
Constraint: ng1${\mathbf{ng}}\ge 1$.

None.

### Output Parameters

1:     ca(ng) – double array
The ng cross amplitude spectral estimates (ω)$\stackrel{^}{A}\left(\omega \right)$ at each frequency of ω$\omega$.
2:     calw(ng) – double array
The ng lower bounds for the ng cross amplitude spectral estimates.
3:     caup(ng) – double array
The ng upper bounds for the ng cross amplitude spectral estimates.
4:     t – double scalar
The critical value for the significance of the squared coherency, T$T$.
5:     sc(ng) – double array
The ng squared coherency estimates, (ω)$\stackrel{^}{W}\left(\omega \right)$ at each frequency ω$\omega$.
6:     sclw(ng) – double array
The ng lower bounds for the ng squared coherency estimates.
7:     scup(ng) – double array
The ng upper bounds for the ng squared coherency estimates.
8:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{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${\mathbf{ifail}}=1$
 On entry, ng < 1${\mathbf{ng}}<1$, or stats(1) < 3.0${\mathbf{stats}}\left(1\right)<3.0$, or stats(2) ≤ 0.0${\mathbf{stats}}\left(2\right)\le 0.0$, or stats(2) > 1.0${\mathbf{stats}}\left(2\right)>1.0$, or stats(3) < 1.0${\mathbf{stats}}\left(3\right)<1.0$.
W ifail = 2${\mathbf{ifail}}=2$
A bivariate spectral estimate is zero. For this frequency the cross amplitude spectrum and squared coherency and their bounds are set to zero.
W ifail = 3${\mathbf{ifail}}=3$
A univariate spectral estimate is negative. For this frequency the cross amplitude spectrum and squared coherency and their bounds are set to zero.
W ifail = 4${\mathbf{ifail}}=4$
A univariate spectral estimate is zero. For this frequency the cross amplitude spectrum and squared coherency and their bounds are set to zero.
W ifail = 5${\mathbf{ifail}}=5$
A calculated value of the squared coherency exceeds 1.0$1.0$. For this frequency the squared coherency is reset to 1.0$1.0$ and this value for the squared coherency is used in the formulae for the calculation of bounds for both the cross amplitude spectrum and squared coherency. This has the consequence that both squared coherency bounds are 1.0$1.0$.
If more than one failure of the types 2$2$, 3$3$, 4$4$ and 5$5$ occurs then the failure type which occurred at lowest frequency is returned in ifail. However the actions indicated above are also carried out for failures at higher frequencies.

## Accuracy

All computations are very stable and yield good accuracy.

The time taken by nag_tsa_multi_spectrum_bivar (g13ce) is approximately proportional to ng.

## Example

```function nag_tsa_multi_spectrum_bivar_example
xg = [2.0349;
0.51554;
0.0764;
0.01068;
0.00093;
0.001;
0.00076;
0.00037;
0.00021];
yg = [21.97712;
3.29761;
0.28782;
0.0248;
0.00285;
0.00203;
0.00125;
0.00107;
0.00191];
xyrg = [-6.54995;
0.34107;
0.12335;
-0.00514;
-0.00033;
-0.00039;
-0.00026;
0.00011;
7e-05];
xyig = [0;
-1.1903;
0.04087;
0.00842;
0.00032;
-1e-05;
0.00018;
-0.00016;
0];
stats = [30;
0.63858;
1.7867;
0.33288];
[ca, calw, caup, t, sc, sclw, scup, ifail] = ...
nag_tsa_multi_spectrum_bivar(xg, yg, xyrg, xyig, stats)
```
```

ca =

6.5499
1.2382
0.1299
0.0099
0.0005
0.0004
0.0003
0.0002
0.0001

calw =

3.9277
0.7364
0.0755
0.0049
0.0001
0.0001
0.0001
0.0001
0.0000

caup =

10.9228
2.0820
0.2236
0.0197
0.0017
0.0015
0.0010
0.0007
0.0018

t =

0.1926

sc =

0.9593
0.9018
0.7679
0.3674
0.0797
0.0750
0.1053
0.0952
0.0122

sclw =

0.9185
0.8093
0.5811
0.1102
0
0
0
0
0

scup =

0.9799
0.9507
0.8790
0.6177
0.3253
0.3182
0.3610
0.3475
0.1912

ifail =

0

```
```function g13ce_example
xg = [2.0349;
0.51554;
0.0764;
0.01068;
0.00093;
0.001;
0.00076;
0.00037;
0.00021];
yg = [21.97712;
3.29761;
0.28782;
0.0248;
0.00285;
0.00203;
0.00125;
0.00107;
0.00191];
xyrg = [-6.54995;
0.34107;
0.12335;
-0.00514;
-0.00033;
-0.00039;
-0.00026;
0.00011;
7e-05];
xyig = [0;
-1.1903;
0.04087;
0.00842;
0.00032;
-1e-05;
0.00018;
-0.00016;
0];
stats = [30;
0.63858;
1.7867;
0.33288];
[ca, calw, caup, t, sc, sclw, scup, ifail] = g13ce(xg, yg, xyrg, xyig, stats)
```
```

ca =

6.5499
1.2382
0.1299
0.0099
0.0005
0.0004
0.0003
0.0002
0.0001

calw =

3.9277
0.7364
0.0755
0.0049
0.0001
0.0001
0.0001
0.0001
0.0000

caup =

10.9228
2.0820
0.2236
0.0197
0.0017
0.0015
0.0010
0.0007
0.0018

t =

0.1926

sc =

0.9593
0.9018
0.7679
0.3674
0.0797
0.0750
0.1053
0.0952
0.0122

sclw =

0.9185
0.8093
0.5811
0.1102
0
0
0
0
0

scup =

0.9799
0.9507
0.8790
0.6177
0.3253
0.3182
0.3610
0.3475
0.1912

ifail =

0

```