yasa.SWResults.get_coincidence_matrix#
- SWResults.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 slow-waves 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 slow-waves 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 slow-waves 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() # Coincidence 3
>>> (x * y).sum() / (x.sum() * y.sum()) # Scaled coincidence 0.12