# NAG Library Function Document

## 1Purpose

For a bivariate time series, nag_tsa_noise_spectrum_bivar (g13cgc) calculates the noise spectrum together with multiplying factors for the bounds and the impulse response function and its standard error, from the univariate and bivariate spectra.

## 2Specification

 #include #include
 void nag_tsa_noise_spectrum_bivar (const double xg[], const double yg[], const Complex xyg[], Integer ng, const double stats[], Integer l, Integer n, double er[], double *erlw, double *erup, double rf[], double *rfse, NagError *fail)

## 3Description

An estimate of the noise spectrum in the dependence of series $y$ on series $x$ at frequency $\omega$ is given by
 $f y∣x ω = f yy ω 1 - W ω$
where $W\left(\omega \right)$ is the squared coherency described in G13GEF and ${f}_{yy}\left(\omega \right)$ is the univariate spectrum estimate for series $y$. Confidence limits on the true spectrum are obtained using multipliers as described for G13CAF, but based on $\left(d-2\right)$ degrees of freedom.
If the dependence of ${y}_{t}$ on ${x}_{t}$ can be assumed to be represented in the time domain by the one sided relationship
 $y t = v 0 x t + v 1 x t-1 + ⋯ + n t$
where the noise ${n}_{t}$ is independent of ${x}_{t}$, then it is the spectrum of this noise which is estimated by ${f}_{y\mid x}\left(\omega \right)$.
Estimates of the impulse response function ${v}_{0},{v}_{1},{v}_{2},\dots$ may also be obtained as
 $v k = 1 π ∫ 0 π Re exp ik ω f xy ω f xx ω$
where Re indicates the real part of the expression. For this purpose it is essential that the univariate spectrum for $x$, ${f}_{xx}\left(\omega \right)$,and the cross spectrum, ${f}_{xy}\left(\omega \right)$ be supplied to this function for a frequency range
 $ω l = 2πl L , 0 ≤ l ≤ L/2 ,$
where $\left[\right]$ denotes the integer part, the integral being approximated by a finite Fourier transform.
An approximate standard error is calculated for the estimates ${v}_{k}$. Significant values of ${v}_{k}$ in the locations described as anticipatory responses in the argument array rf, indicate that feedback exists from ${y}_{t}$ to ${x}_{t}$. This will bias the estimates of ${v}_{k}$ in any causal dependence of ${y}_{t}$ on ${x}_{t},{x}_{t-1},\dots$.

## 4References

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

## 5Arguments

1:    $\mathbf{xg}\left[{\mathbf{ng}}\right]$const doubleInput
On entry: the ng univariate spectral estimates, ${f}_{xx}\left(\omega \right)$, for the $x$ series.
2:    $\mathbf{yg}\left[{\mathbf{ng}}\right]$const doubleInput
On entry: the ng univariate spectral estimates, ${f}_{yy}\left(\omega \right)$, for the $y$ series.
3:    $\mathbf{xyg}\left[{\mathbf{ng}}\right]$const ComplexInput
On entry: ${f}_{xy}\left(\omega \right)$, of the ng bivariate spectral estimates for the $x$ and $y$ series. The $x$ series leads the $y$ series.
Note: the two univariate and 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:    $\mathbf{ng}$IntegerInput
On entry: the number of spectral estimates in each of the arrays xg, yg and xyg. It is also the number of noise spectral estimates.
Constraint: ${\mathbf{ng}}\ge 1$.
5:    $\mathbf{stats}\left[4\right]$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 degree 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:    $\mathbf{l}$IntegerInput
On entry: the frequency division, $L$, of the spectral estimates as $2\pi /L$, as input to nag_tsa_spectrum_univar (g13cbc) and nag_tsa_spectrum_bivar (g13cdc).
Constraints:
• ${\mathbf{ng}}=\left[{\mathbf{l}}/2\right]+1$;
• The largest prime factor of l must not exceed $19$, and the total number of prime factors of l, counting repetitions, must not exceed $20$. These two restrictions are imposed by the internal FFT algorithm used.
7:    $\mathbf{n}$IntegerInput
On entry: the number of points in each of the time series $x$ and $y$. n should have the same value as nxy in the call of nag_tsa_spectrum_bivar_cov (g13ccc) or nag_tsa_spectrum_bivar (g13cdc) which calculated the smoothed sample cross spectrum. n is used in calculating the impulse response function standard error (rfse).
Constraint: ${\mathbf{n}}\ge 1$.
8:    $\mathbf{er}\left[{\mathbf{ng}}\right]$doubleOutput
On exit: the ng estimates of the noise spectrum, ${\stackrel{^}{f}}_{y\mid x}\left(\omega \right)$ at each frequency.
9:    $\mathbf{erlw}$double *Output
On exit: the noise spectrum lower limit multiplying factor.
10:  $\mathbf{erup}$double *Output
On exit: the noise spectrum upper limit multiplying factor.
11:  $\mathbf{rf}\left[{\mathbf{l}}\right]$doubleOutput
On exit: the impulse response function. Causal responses are stored in ascending frequency in ${\mathbf{rf}}\left[0\right]$ to ${\mathbf{rf}}\left[{\mathbf{ng}}-1\right]$ and anticipatory responses are stored in descending frequency in ${\mathbf{rf}}\left[{\mathbf{ng}}\right]$ to ${\mathbf{rf}}\left[{\mathbf{l}}\right]$.
12:  $\mathbf{rfse}$double *Output
On exit: the impulse response function standard error.
13:  $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_2_INT_ARG_CONS
On entry, ${\mathbf{l}}=〈\mathit{\text{value}}〉$ while ${\mathbf{ng}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{ng}}=\left[{\mathbf{l}}/2\right]+1$ when ${\mathbf{ng}}>0$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BIVAR_SPECTRAL_ESTIM_ZERO
A bivariate spectral estimate is zero.
For this frequency the noise spectrum is set to zero, and the contributions to the impulse response function and its standard error are set to zero.
NE_FACTOR_GT
At least one of the prime factors of l is greater than 19.
NE_INT_ARG_LT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
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 noise spectrum is zero and the contribution to the impulse response function at this frequency is zero.
NE_TOO_MANY_FACTORS
l has more than 20 prime factors.
NE_UNIVAR_SPECTRAL_ESTIM_NEG
A bivariate spectral estimate is negative.
For this frequency the noise 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 noise spectrum is set to zero, and the contributions to the impulse response function and its standard error are set to zero.

## 7Accuracy

The computation of the noise is stable and yields good accuracy. The FFT is a numerically stable process, and any errors introduced during the computation will normally be insignificant compared with uncertainty in the data.

## 8Parallelism and Performance

nag_tsa_noise_spectrum_bivar (g13cgc) is not threaded in any implementation.

The time taken by nag_tsa_noise_spectrum_bivar (g13cgc) is approximately proportional to ng.

## 10Example

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_noise_spectrum_bivar (g13cgc) to calculate the noise spectrum and its confidence limits multiplying factors, the impulse response function and its standard error. It then prints the results.

### 10.1Program Text

Program Text (g13cgce.c)

### 10.2Program Data

Program Data (g13cgce.d)

### 10.3Program Results

Program Results (g13cgce.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017