nag_tsa_cross_spectrum_bivar (g13cec) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_tsa_cross_spectrum_bivar (g13cec)

## 1  Purpose

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

## 2  Specification

 #include #include
 void nag_tsa_cross_spectrum_bivar (const double xg[], const double yg[], const Complex xyg[], Integer ng, const double stats[], double ca[], double calw[], double caup[], double *t, double sc[], double sclw[], double scup[], NagError *fail)

## 3  Description

Estimates of the cross amplitude spectrum $A\left(\omega \right)$ and squared coherency $W\left(\omega \right)$ are calculated for each frequency $\omega$ as
 $A ω = f xy ω = cf ω 2 + qf ω 2 ​ and ​ W ω = f xy ω 2 f xx ω f yy ω$
where:
$cf\left(\omega \right)$ and $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 ${f}_{xy}\left(\omega \right)$ as obtained using nag_tsa_spectrum_bivar_cov (g13ccc) or nag_tsa_spectrum_bivar (g13cdc). ${f}_{xx}\left(\omega \right)$ and ${f}_{yy}\left(\omega \right)$ are the univariate spectrum estimates for the two series as obtained using nag_tsa_spectrum_univar_cov (g13cac) or nag_tsa_spectrum_univar (g13cbc). 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_spectrum_univar_cov (g13cac) or nag_tsa_spectrum_univar (g13cbc).
Upper and lower 95% confidence limits for the cross amplitude are given approximately by
 $A ω 1 ± 1.96 / d W ω -1 + 1 ,$
except that a negative lower limit is reset to 0.0, in which case the approximation is rather poor. You are therefore particularly recommended to compare the coherency estimate $W\left(\omega \right)$ with the critical value $T$ derived from the upper 5% point of the $F$-distribution on $\left(2,d-2\right)$ degrees of freedom:
 $T = 2F d - 2 + 2 F$
where $d$ is the degrees of freedom associated with the univariate spectrum estimates. The value of $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% level if $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\left(\omega \right)$ are strictly appropriate only at frequencies for which the coherency is significant. The same applies to the confidence limits on $W\left(\omega \right)$ which are however calculated at all frequencies using the approximation that $\mathrm{arctanh}\left(\sqrt{W\left(l\right)}\right)$ is Normal with variance $1/d$.

## 4  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

## 5  Arguments

1:     xg[ng]const doubleInput
On entry: the ng univariate spectral estimates, ${f}_{xx}\left(\omega \right)$, for the $x$ series.
2:     yg[ng]const doubleInput
On entry: the ng univariate spectral estimates, ${f}_{yy}\left(\omega \right)$, for the $y$ series.
3:     xyg[ng]const ComplexInput
On entry: ${f}_{xy}\left(\omega \right)$, the ng bivariate spectral estimates for the $x$ and $y$ series. The $x$ series leads the $y$ series.
Note: the two univariate and the bivariate spectra must each have been calculated using the same amount of smoothing. 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.
4:     ngIntegerInput
On entry: the number of spectral estimates in each of the arrays xg, yg and xyg. It is also the number of cross amplitude spectral and squared coherency estimates.
Constraint: ${\mathbf{ng}}\ge 1$.
5:     stats[$4$]const doubleInput
On entry: the 4 associated statistics for the univariate spectral estimates for the $x$ and $y$ series. ${\mathbf{stats}}\left[0\right]$ contains the degrees of freedom, ${\mathbf{stats}}\left[1\right]$ and ${\mathbf{stats}}\left[2\right]$ contain the lower and upper bound multiplying factors respectively and ${\mathbf{stats}}\left[3\right]$ contains the bandwidth.
Constraints:
• ${\mathbf{stats}}\left[0\right]\ge 3.0$;
• $0.0<{\mathbf{stats}}\left[1\right]\le 1.0$;
• ${\mathbf{stats}}\left[2\right]\ge 1.0$.
6:     ca[ng]doubleOutput
On exit: the ng cross amplitude spectral estimates $\stackrel{^}{A}\left(\omega \right)$ at each frequency of $\omega$.
7:     calw[ng]doubleOutput
On exit: the ng lower bounds for the ng cross amplitude spectral estimates.
8:     caup[ng]doubleOutput
On exit: the ng upper bounds for the ng cross amplitude spectral estimates.
9:     tdouble *Output
On exit: the critical value for the significance of the squared coherency, $T$.
10:   sc[ng]doubleOutput
On exit: the ng squared coherency estimates, $\stackrel{^}{W}\left(\omega \right)$ at each frequency $\omega$.
11:   sclw[ng]doubleOutput
On exit: the ng lower bounds for the ng squared coherency estimates.
12:   scup[ng]doubleOutput
On exit: the ng upper bounds for the ng squared coherency estimates.
13:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BIVAR_SPECTRAL_ESTIM_ZERO
A bivariate spectral estimate is zero.
For this frequency the cross amplitude spectrum is set to zero, and the contributions to the impulse response function and its standard error are set to zero.
NE_INT_ARG_LT
On entry, ${\mathbf{ng}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ng}}\ge 1$.
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_REAL_ARG_GT
On entry, ${\mathbf{stats}}\left[1\right]$ must not be greater than 1.0: ${\mathbf{stats}}\left[1\right]=〈\mathit{\text{value}}〉$.
NE_REAL_ARG_LE
On entry, ${\mathbf{stats}}\left[1\right]$ must not be less than or equal to 0.0: ${\mathbf{stats}}\left[1\right]=〈\mathit{\text{value}}〉$.
NE_REAL_ARG_LT
On entry, ${\mathbf{stats}}\left[0\right]$ must not be less than 3.0: ${\mathbf{stats}}\left[0\right]=〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{stats}}\left[2\right]$ must not be less than 1.0: ${\mathbf{stats}}\left[2\right]=〈\mathit{\text{value}}〉$.
NE_SQUARED_FREQ_GT_ONE
A calculated value of the squared coherency exceeds one.
For this frequency the squared coherency is reset to one with the result that the cross amplitude spectrum is zero and the contribution to the impulse response function at this frequency is zero.
NE_UNIVAR_SPECTRAL_ESTIM_NEG
A bivariate spectral estimate is negative.
For this frequency the cross amplitude spectrum is set to zero, and the contributions to the impulse response function and its standard error are set to zero.
NE_UNIVAR_SPECTRAL_ESTIM_ZERO
A bivariate spectral estimate is zero.
For this frequency the cross amplitude spectrum is set to zero, and the contributions to the impulse response function and its standard error are set to zero.

## 7  Accuracy

All computations are very stable and yield good accuracy.

## 8  Further Comments

The time taken by nag_tsa_cross_spectrum_bivar (g13cec) is approximately proportional to ng.

## 9  Example

The example program reads the set of univariate spectrum statistics, the 2 univariate spectra and the cross spectrum at a frequency division of $\frac{2\pi }{20}$ for a pair of time series. It calls nag_tsa_cross_spectrum_bivar (g13cec) to calculate the cross amplitude spectrum and squared coherency and their bounds and prints the results.

### 9.1  Program Text

Program Text (g13cece.c)

### 9.2  Program Data

Program Data (g13cece.d)

### 9.3  Program Results

Program Results (g13cece.r)

nag_tsa_cross_spectrum_bivar (g13cec) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG C Library Manual