yasa.SpindlesResults.get_coincidence_matrix#

SpindlesResults.get_coincidence_matrix(scaled=True)[source]#

Return the (scaled) coincidence matrix.

Parameters:
scaledbool

If True (default), the coincidence matrix is scaled (see Notes).

Returns:
coincidencepd.DataFrame

A symmetric matrix with the (scaled) coincidence values.

Notes

Do spindles occur at the same time? One way to measure this is to calculate the coincidence matrix, which gives, for each pair of channel, the number of samples that were marked as a spindle in both channels. The output is a symmetric matrix, in which the diagonal is simply the number of data points that were marked as a spindle in the channel.

The coincidence matrix can be scaled (default) by dividing the output by the product of the sum of each individual binary mask, as shown in the example below. It can then be used to define functional networks or quickly find outlier channels.

References

Examples

Calculate the coincidence of two binary mask:

>>> import numpy as np
>>> x = np.array([0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1])
>>> y = np.array([0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1])
>>> x * y
array([0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1])
>>> (x * y).sum()  # Unscaled coincidence
3
>>> (x * y).sum() / (x.sum() * y.sum())  # Scaled coincidence
0.12