spectral_connectivity.statistics.coherence_rate_adjustment#

coherence_rate_adjustment(firing_rate_condition1: float, firing_rate_condition2: float, spike_power_spectrum: NDArray[floating], homogeneous_poisson_noise: float = 0, dt: float = 1, *, is_one_sided: bool | None = None) → NDArray[floating][source]#

Return the factor by which a firing-rate change alone alters spike-field coherence.

Spike-field coherence depends on the firing rate even when the coupling between spikes and field does not change. This function gives the factor by which the coherence falls when a fraction of a spike train’s spikes is removed at random (thinning), optionally with independent Poisson spikes added [1]. Multiply the first condition’s coherence by it to get the coherence expected at the second condition’s rate under unchanged coupling, and compare the second condition’s coherence with that.

Parameters:
  • firing_rate_condition1 (float) – Average firing rate in the first condition (spikes/sec).

  • firing_rate_condition2 (float) – Average firing rate in the second condition (spikes/sec), including any spikes counted in homogeneous_poisson_noise.

  • spike_power_spectrum (NDArray[floating], shape (n_frequencies,)) – Power spectral density of the first condition’s spike train, where the train was given as spike counts per time bin (0 or 1 for small bins), not as a rate. Say with is_one_sided whether it is the one-sided density, as Connectivity.power returns it, or a two-sided one.

  • homogeneous_poisson_noise (float, default=0) –

    Rate (spikes/sec) of spikes added in the second condition at a constant rate, independently of the field (beta in [1]). The second condition is then the first with a fraction alpha of its spikes kept, plus these, so alpha is (firing_rate_condition2 - homogeneous_poisson_noise) / firing_rate_condition1. This rate is not estimated here: give it only if the experiment tells you what it is, and leave 0 when spikes are only removed. Must be at least 0 and below firing_rate_condition2.

    Changed in version 3.0: firing_rate_condition2 includes these spikes. 2.x took it as the rate of the kept spikes alone, against its documentation, so a call with a non-zero rate here warns about the change (until 4.0).

  • dt (float, default=1) – Width of the time bins the spikes are counted in, in seconds: for a spectrum from this package, 1 / sampling_frequency of the spike train. The default of 1 suits only a spectrum computed with a sampling frequency of 1.

  • is_one_sided (bool, optional) –

    Whether spike_power_spectrum is a one-sided density, in which each frequency bin includes the power of its mirror negative frequency, as Connectivity.power() returns it (True), or a two-sided one, such as Connectivity.power(one_sided=False) (False). The adjustment is defined for the two-sided density, which is half of the one-sided one at frequencies other than 0 Hz and Nyquist. If omitted, the spectrum is taken as one-sided and a warning says so, because the two cannot be told apart from their values.

    Added in version 3.0: In 2.x the spectrum was read as two-sided, which is what power() returned then.

Returns:

rate_adjustment_factor – Factor that multiplies the magnitude of the first condition’s coherence (not its square); at most 1 when the rate does not rise. NaN where it is undefined. Leave out the value at 0 Hz, and with the default mean removal (detrend_type="constant") the values within a taper’s bandwidth of it: the removal of each window’s mean distorts the estimated spike spectrum there. Without mean removal the mean’s power dominates 0 Hz, and with added Poisson spikes the distortion reaches further. The value at the Nyquist frequency is valid only with a two-sided spectrum, because a one-sided density is not doubled there.

Return type:

NDArray[floating], shape (n_frequencies,)

Examples

>>> import numpy as np
>>> rate1, rate2 = 15.0, 10.0  # firing rate decreases in condition 2
>>> dt = 0.002  # spikes counted in 2 ms bins (sampling frequency 500 Hz)
>>> freqs = np.linspace(1, 100, 50)
>>> # A one-sided spike spectrum: the level of a Poisson train of that rate,
>>> # 2 * rate * dt**2, with a peak at 40 Hz.
>>> power_spec = 2 * rate1 * dt**2 * (1 + 3 * np.exp(-(((freqs - 40) / 5) ** 2)))
>>> adjustment = coherence_rate_adjustment(
...     rate1, rate2, power_spec, dt=dt, is_one_sided=True
... )
>>> print(f"Adjustment range: {adjustment.min():.3f} to {adjustment.max():.3f}")
Adjustment range: 0.816 to 0.942

Notes

The spectrum a spike train of rate mu would have without any structure is mu * dt**2 as a two-sided density and twice that as a one-sided one. The adjustment depends on the given spectrum relative to that level, which is why the kind of density matters.

For spike-spike coherence comparisons, apply this adjustment twice, once for each spike train.

References

[1] (1,2)

Aoi, M.C., Lepage, K.Q., Kramer, M.A., and Eden, U.T. (2015). Rate-adjusted spike-LFP coherence comparisons from spike-train statistics. Journal of Neuroscience Methods 240, 141-153.