For a bivariate time series, g13cg 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.

# Syntax

C#
public static void g13cg(
double[] xg,
double[] yg,
double[] xyrg,
double[] xyig,
int ng,
double[] stats,
int l,
int n,
double[] er,
out double erlw,
out double erup,
double[] rf,
out double rfse,
out int ifail
)
Visual Basic
Public Shared Sub g13cg ( _
xg As Double(), _
yg As Double(), _
xyrg As Double(), _
xyig As Double(), _
ng As Integer, _
stats As Double(), _
l As Integer, _
n As Integer, _
er As Double(), _
<OutAttribute> ByRef erlw As Double, _
<OutAttribute> ByRef erup As Double, _
rf As Double(), _
<OutAttribute> ByRef rfse As Double, _
<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g13cg(
array<double>^ xg,
array<double>^ yg,
array<double>^ xyrg,
array<double>^ xyig,
int ng,
array<double>^ stats,
int l,
int n,
array<double>^ er,
[OutAttribute] double% erlw,
[OutAttribute] double% erup,
array<double>^ rf,
[OutAttribute] double% rfse,
[OutAttribute] int% ifail
)
F#
static member g13cg :
xg : float[] *
yg : float[] *
xyrg : float[] *
xyig : float[] *
ng : int *
stats : float[] *
l : int *
n : int *
er : float[] *
erlw : float byref *
erup : float byref *
rf : float[] *
rfse : float byref *
ifail : int byref -> unit

#### Parameters

xg
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On entry: the ng univariate spectral estimates, ${f}_{xx}\left(\omega \right)$, for the $x$ series.
yg
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On entry: the ng univariate spectral estimates, ${f}_{yy}\left(\omega \right)$, for the $y$ series.
xyrg
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On entry: the real parts, $cf\left(\omega \right)$, of the ng bivariate spectral estimates for the $x$ and $y$ series. The $x$ series leads the $y$ series.
xyig
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On entry: the imaginary parts, $qf\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 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.
ng
Type: System..::..Int32
On entry: the number of spectral estimates in each of the arrays xg, yg, xyrg, xyig. It is also the number of noise spectral estimates.
Constraint: ${\mathbf{ng}}\ge 1$.
stats
Type: array<System..::..Double>[]()[][]
An array of size [$4$]
On entry: the four 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$.
l
Type: System..::..Int32
On entry: $L$, the frequency division of the spectral estimates as $\frac{2\pi }{L}$. It is also the order of the FFT used to calculate the impulse response function. l must relate to the parameter ng by the relationship.
Constraints:
• ${\mathbf{ng}}=\left[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.
n
Type: System..::..Int32
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 g13cc or g13cd which calculated the smoothed sample cross spectrum. n is used in calculating the impulse response function standard error (rfse).
Constraint: ${\mathbf{n}}\ge 1$.
er
Type: array<System..::..Double>[]()[][]
An array of size [ng]
On exit: the ng estimates of the noise spectrum, ${\stackrel{^}{f}}_{y\mid x}\left(\omega \right)$ at each frequency.
erlw
Type: System..::..Double%
On exit: the noise spectrum lower limit multiplying factor.
erup
Type: System..::..Double%
On exit: the noise spectrum upper limit multiplying factor.
rf
Type: array<System..::..Double>[]()[][]
An array of size [l]
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}}-1\right]$.
rfse
Type: System..::..Double%
On exit: the impulse response function standard error.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

An estimate of the noise spectrum in the dependence of series $y$ on series $x$ at frequency $\omega$ is given by
 $fy∣xω=fyyω1-Wω,$
where $W\left(\omega \right)$ is the squared coherency described in g13ce 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 g13ca, 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
 $yt=v0xt+v1xt-1+⋯+nt,$
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 \text{}$ may also be obtained as
 $vk=1π∫0πReexpikωfxyωfxxω,$
where $\mathrm{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 method for a frequency range
 $ωl=2πlL, 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 parameter 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 \text{}$.

# 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

# Error Indicators and Warnings

Note: g13cg may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{ng}}<1$, or ${\mathbf{stats}}\left[0\right]<3.0$, or ${\mathbf{stats}}\left[1\right]\le 0.0$, or ${\mathbf{stats}}\left[1\right]>1.0$, or ${\mathbf{stats}}\left[2\right]<1.0$, or ${\mathbf{n}}<1$.
${\mathbf{ifail}}=2$
A bivariate spectral estimate is zero. For this frequency the noise spectrum is set to zero, and the contribution to the impulse response function and its standard error is set to zero.
${\mathbf{ifail}}=3$
A univariate 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.
${\mathbf{ifail}}=4$
A univariate 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.
${\mathbf{ifail}}=5$
A calculated value of the squared coherency exceeds $1.0$. For this frequency the squared coherency is reset to $1.0$ with the consequence that the noise spectrum is zero and the contribution to the impulse response function at this frequency is zero.
${\mathbf{ifail}}=6$
 On entry, $\left[{\mathbf{l}}/2\right]+1\ne {\mathbf{ng}}$, or l has a prime factor exceeding $19$, or l has more than $20$ prime factors, counting repetitions.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
If more than one failure of types $2$, $3$, $4$ and $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

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.

# Parallelism and Performance

None.

The time taken by g13cg is approximately proportional to ng.

# Example

This example reads the set of univariate spectrum statistics, the two univariate spectra and the cross spectrum at a frequency division of $\frac{2\pi }{20}$ for a pair of time series. It calls g13cg to calculate the noise spectrum and its confidence limits multiplying factors, the impulse response function and its standard error. It then prints the results.

Example program (C#): g13cge.cs

Example program data: g13cge.d

Example program results: g13cge.r