Note

Click here to download the full example code

# Comparing PLI, wPLI, and dPLI#

This example demonstrates the different connectivity information captured by the phase lag index (PLI) 1, weighted phase lag index (wPLI) 2, and directed phase lag index (dPLI) 3 on simulated data.

```
# Authors: Kenji Marshall <kenji.marshall99@gmail.com>
# Charlotte Maschke <charlotte.maschke@mail.mcgill.ca>
# Stefanie Blain-Moraes <stefanie.blain-moraes@mcgill.ca>
#
# License: BSD (3-clause)
import mne
import numpy as np
import matplotlib.pyplot as plt
from mne_connectivity import spectral_connectivity_epochs
from mne.datasets import sample
```

## Background#

The formulae for PLI, wPLI, and dPLI are given below. In these equations, \(X_{ij}\) is the cross-spectral density (CSD) between two signals \(i, j\). Importantly, the imaginary component of the CSD is maximal when the signals have a phase difference given by \(k\pi+\frac{\pi}{2}\), and is \(0\) when the phase difference is given by \(k\pi\) (where \(k \in \mathbb{Z}\)). This property provides protection against recognizing volume conduction effects as connectivity, and is the backbone for these methods 2. In the equations below, \(\mathcal{I}\) refers to the imaginary component, \(\mathcal{H}\) refers to the Heaviside step function, and \(sgn\) refers to the sign function.

\(PLI = |E[sgn(\mathcal{I}(X_{ij}))]|\) 1

\(wPLI = \frac{|E[\mathcal{I}(X_{ij})]|}{E[|\mathcal{I}(X_{ij})|]}\) 2

\(dPLI = E[\mathcal{H}(\mathcal{I}(X_{ij}))]\) 3

All three of these metrics are bounded in the range \([0, 1]\).

For PLI, \(0\) means that signal \(i\) leads and lags signal \(j\) equally often, while a value greater than \(0\) means that there is an imbalance in the likelihood for signal \(i\) to be leading or lagging. A value of \(1\) means that signal \(i\) only leads or only lags signal \(j\).

For wPLI, \(0\) means that the total weight (not the quantity) of all leading relationships equals the total weight of lagging relationships, while a value greater than \(0\) means that there is an imbalance between these weights. A value of \(1\), just as in PLI, means that signal \(i\) only leads or only lags signal \(j\).

With dPLI, we gain the ability to distinguish whether signal \(i\) is leading or lagging signal \(j\), complementing the information provided by PLI or wPLI. A value of \(0.5\) means that signal \(i\) leads and lags signal \(j\) equally often. A value in the range \((0.5, 1.0]\) means that signal \(i\) leads signal \(j\) more often than it lags, with a value of \(1\) meaning that signal \(i\) always leads signal \(j\). A value in the range \([0.0, 0.5)\) means that signal \(i\) lags signal \(j\) more often than it leads, with a value of \(0\) meaning that signal \(i\) always lags signal \(j\). The PLI can actually be extracted from the dPLI by the relationship \(PLI = 2|dPLI - 0.5|\), but this relationship is not invertible (dPLI can not be estimated from the PLI).

Overall, these different approaches are closely related but have subtle differences, as will be demonstrated throughout the rest of this example.

## Capturing Leading/Lagging Phase Relationships with dPLI#

The main advantage of dPLI is that it’s *directed*, meaning it can
differentiate between phase relationships which are leading or lagging.
To illustrate this, we generate sinusoids with Gaussian noise. In particular,
we generate signals with phase differences of
\([-\pi, -\frac{\pi}{2}, 0, \frac{\pi}{2}, \pi]\) relative to a reference
signal. A negative difference means that the reference signal is lagging the
other signal.

```
fs = 250 # sampling rate (Hz)
n_e = 300 # number of epochs
T = 10 # length of epochs (s)
f = 10 # frequency of sinusoids (Hz)
t = np.arange(0, T, 1 / fs)
A = 1 # noise amplitude
sigma = 0.5 # Gaussian noise variance
data = []
phase_differences = [0, -np.pi, -np.pi / 2, 0, np.pi / 2, np.pi]
for ps in zip(phase_differences):
sig = []
for _ in range(n_e):
sig.append(np.sin(2 * np.pi * f * t - ps) +
A * np.random.normal(0, sigma, size=t.shape))
data.append(sig)
data = np.swapaxes(np.array(data), 0, 1) # make epochs the first dimension
```

A snippet of this simulated data is shown below. The blue signal is the reference signal.

```
fig, ax = plt.subplots(1, 2, figsize=(12, 5), sharey=True)
ax[0].plot(t[:fs], data[0, 0, :fs], label="Reference")
ax[0].plot(t[:fs], data[0, 2, :fs])
ax[0].set_title(r"Phase Lagging ($-\pi/2$ Phase Difference)")
ax[0].set_xlabel("Time (s)")
ax[0].set_ylabel("Signal")
ax[0].legend()
ax[1].plot(t[:fs], data[0, 0, :fs], label="Reference")
ax[1].plot(t[:fs], data[0, 4, :fs])
ax[1].set_title(r"Phase Leading ($\pi/2$ Phase Difference)")
ax[1].set_xlabel("Time (s)")
plt.show()
```

We will now compute PLI, wPLI, and dPLI for each phase relationship.

Out:

```
Connectivity computation...
computing connectivity for 5 connections
using t=0.000s..9.996s for estimation (2500 points)
frequencies: 9.0Hz..11.0Hz (21 points)
connectivity scores will be averaged for each band
Using multitaper spectrum estimation with 7 DPSS windows
the following metrics will be computed: PLI
computing connectivity for epoch 1
computing connectivity for epoch 2
computing connectivity for epoch 3
computing connectivity for epoch 4
computing connectivity for epoch 5
computing connectivity for epoch 6
computing connectivity for epoch 7
computing connectivity for epoch 8
computing connectivity for epoch 9
computing connectivity for epoch 10
computing connectivity for epoch 11
computing connectivity for epoch 12
computing connectivity for epoch 13
computing connectivity for epoch 14
computing connectivity for epoch 15
computing connectivity for epoch 16
computing connectivity for epoch 17
computing connectivity for epoch 18
computing connectivity for epoch 19
computing connectivity for epoch 20
computing connectivity for epoch 21
computing connectivity for epoch 22
computing connectivity for epoch 23
computing connectivity for epoch 24
computing connectivity for epoch 25
computing connectivity for epoch 26
computing connectivity for epoch 27
computing connectivity for epoch 28
computing connectivity for epoch 29
computing connectivity for epoch 30
computing connectivity for epoch 31
computing connectivity for epoch 32
computing connectivity for epoch 33
computing connectivity for epoch 34
computing connectivity for epoch 35
computing connectivity for epoch 36
computing connectivity for epoch 37
computing connectivity for epoch 38
computing connectivity for epoch 39
computing connectivity for epoch 40
computing connectivity for epoch 41
computing connectivity for epoch 42
computing connectivity for epoch 43
computing connectivity for epoch 44
computing connectivity for epoch 45
computing connectivity for epoch 46
computing connectivity for epoch 47
computing connectivity for epoch 48
computing connectivity for epoch 49
computing connectivity for epoch 50
computing connectivity for epoch 51
computing connectivity for epoch 52
computing connectivity for epoch 53
computing connectivity for epoch 54
computing connectivity for epoch 55
computing connectivity for epoch 56
computing connectivity for epoch 57
computing connectivity for epoch 58
computing connectivity for epoch 59
computing connectivity for epoch 60
computing connectivity for epoch 61
computing connectivity for epoch 62
computing connectivity for epoch 63
computing connectivity for epoch 64
computing connectivity for epoch 65
computing connectivity for epoch 66
computing connectivity for epoch 67
computing connectivity for epoch 68
computing connectivity for epoch 69
computing connectivity for epoch 70
computing connectivity for epoch 71
computing connectivity for epoch 72
computing connectivity for epoch 73
computing connectivity for epoch 74
computing connectivity for epoch 75
computing connectivity for epoch 76
computing connectivity for epoch 77
computing connectivity for epoch 78
computing connectivity for epoch 79
computing connectivity for epoch 80
computing connectivity for epoch 81
computing connectivity for epoch 82
computing connectivity for epoch 83
computing connectivity for epoch 84
computing connectivity for epoch 85
computing connectivity for epoch 86
computing connectivity for epoch 87
computing connectivity for epoch 88
computing connectivity for epoch 89
computing connectivity for epoch 90
computing connectivity for epoch 91
computing connectivity for epoch 92
computing connectivity for epoch 93
computing connectivity for epoch 94
computing connectivity for epoch 95
computing connectivity for epoch 96
computing connectivity for epoch 97
computing connectivity for epoch 98
computing connectivity for epoch 99
computing connectivity for epoch 100
computing connectivity for epoch 101
computing connectivity for epoch 102
computing connectivity for epoch 103
computing connectivity for epoch 104
computing connectivity for epoch 105
computing connectivity for epoch 106
computing connectivity for epoch 107
computing connectivity for epoch 108
computing connectivity for epoch 109
computing connectivity for epoch 110
computing connectivity for epoch 111
computing connectivity for epoch 112
computing connectivity for epoch 113
computing connectivity for epoch 114
computing connectivity for epoch 115
computing connectivity for epoch 116
computing connectivity for epoch 117
computing connectivity for epoch 118
computing connectivity for epoch 119
computing connectivity for epoch 120
computing connectivity for epoch 121
computing connectivity for epoch 122
computing connectivity for epoch 123
computing connectivity for epoch 124
computing connectivity for epoch 125
computing connectivity for epoch 126
computing connectivity for epoch 127
computing connectivity for epoch 128
computing connectivity for epoch 129
computing connectivity for epoch 130
computing connectivity for epoch 131
computing connectivity for epoch 132
computing connectivity for epoch 133
computing connectivity for epoch 134
computing connectivity for epoch 135
computing connectivity for epoch 136
computing connectivity for epoch 137
computing connectivity for epoch 138
computing connectivity for epoch 139
computing connectivity for epoch 140
computing connectivity for epoch 141
computing connectivity for epoch 142
computing connectivity for epoch 143
computing connectivity for epoch 144
computing connectivity for epoch 145
computing connectivity for epoch 146
computing connectivity for epoch 147
computing connectivity for epoch 148
computing connectivity for epoch 149
computing connectivity for epoch 150
computing connectivity for epoch 151
computing connectivity for epoch 152
computing connectivity for epoch 153
computing connectivity for epoch 154
computing connectivity for epoch 155
computing connectivity for epoch 156
computing connectivity for epoch 157
computing connectivity for epoch 158
computing connectivity for epoch 159
computing connectivity for epoch 160
computing connectivity for epoch 161
computing connectivity for epoch 162
computing connectivity for epoch 163
computing connectivity for epoch 164
computing connectivity for epoch 165
computing connectivity for epoch 166
computing connectivity for epoch 167
computing connectivity for epoch 168
computing connectivity for epoch 169
computing connectivity for epoch 170
computing connectivity for epoch 171
computing connectivity for epoch 172
computing connectivity for epoch 173
computing connectivity for epoch 174
computing connectivity for epoch 175
computing connectivity for epoch 176
computing connectivity for epoch 177
computing connectivity for epoch 178
computing connectivity for epoch 179
computing connectivity for epoch 180
computing connectivity for epoch 181
computing connectivity for epoch 182
computing connectivity for epoch 183
computing connectivity for epoch 184
computing connectivity for epoch 185
computing connectivity for epoch 186
computing connectivity for epoch 187
computing connectivity for epoch 188
computing connectivity for epoch 189
computing connectivity for epoch 190
computing connectivity for epoch 191
computing connectivity for epoch 192
computing connectivity for epoch 193
computing connectivity for epoch 194
computing connectivity for epoch 195
computing connectivity for epoch 196
computing connectivity for epoch 197
computing connectivity for epoch 198
computing connectivity for epoch 199
computing connectivity for epoch 200
computing connectivity for epoch 201
computing connectivity for epoch 202
computing connectivity for epoch 203
computing connectivity for epoch 204
computing connectivity for epoch 205
computing connectivity for epoch 206
computing connectivity for epoch 207
computing connectivity for epoch 208
computing connectivity for epoch 209
computing connectivity for epoch 210
computing connectivity for epoch 211
computing connectivity for epoch 212
computing connectivity for epoch 213
computing connectivity for epoch 214
computing connectivity for epoch 215
computing connectivity for epoch 216
computing connectivity for epoch 217
computing connectivity for epoch 218
computing connectivity for epoch 219
computing connectivity for epoch 220
computing connectivity for epoch 221
computing connectivity for epoch 222
computing connectivity for epoch 223
computing connectivity for epoch 224
computing connectivity for epoch 225
computing connectivity for epoch 226
computing connectivity for epoch 227
computing connectivity for epoch 228
computing connectivity for epoch 229
computing connectivity for epoch 230
computing connectivity for epoch 231
computing connectivity for epoch 232
computing connectivity for epoch 233
computing connectivity for epoch 234
computing connectivity for epoch 235
computing connectivity for epoch 236
computing connectivity for epoch 237
computing connectivity for epoch 238
computing connectivity for epoch 239
computing connectivity for epoch 240
computing connectivity for epoch 241
computing connectivity for epoch 242
computing connectivity for epoch 243
computing connectivity for epoch 244
computing connectivity for epoch 245
computing connectivity for epoch 246
computing connectivity for epoch 247
computing connectivity for epoch 248
computing connectivity for epoch 249
computing connectivity for epoch 250
computing connectivity for epoch 251
computing connectivity for epoch 252
computing connectivity for epoch 253
computing connectivity for epoch 254
computing connectivity for epoch 255
computing connectivity for epoch 256
computing connectivity for epoch 257
computing connectivity for epoch 258
computing connectivity for epoch 259
computing connectivity for epoch 260
computing connectivity for epoch 261
computing connectivity for epoch 262
computing connectivity for epoch 263
computing connectivity for epoch 264
computing connectivity for epoch 265
computing connectivity for epoch 266
computing connectivity for epoch 267
computing connectivity for epoch 268
computing connectivity for epoch 269
computing connectivity for epoch 270
computing connectivity for epoch 271
computing connectivity for epoch 272
computing connectivity for epoch 273
computing connectivity for epoch 274
computing connectivity for epoch 275
computing connectivity for epoch 276
computing connectivity for epoch 277
computing connectivity for epoch 278
computing connectivity for epoch 279
computing connectivity for epoch 280
computing connectivity for epoch 281
computing connectivity for epoch 282
computing connectivity for epoch 283
computing connectivity for epoch 284
computing connectivity for epoch 285
computing connectivity for epoch 286
computing connectivity for epoch 287
computing connectivity for epoch 288
computing connectivity for epoch 289
computing connectivity for epoch 290
computing connectivity for epoch 291
computing connectivity for epoch 292
computing connectivity for epoch 293
computing connectivity for epoch 294
computing connectivity for epoch 295
computing connectivity for epoch 296
computing connectivity for epoch 297
computing connectivity for epoch 298
computing connectivity for epoch 299
computing connectivity for epoch 300
[Connectivity computation done]
Connectivity computation...
computing connectivity for 5 connections
using t=0.000s..9.996s for estimation (2500 points)
frequencies: 9.0Hz..11.0Hz (21 points)
connectivity scores will be averaged for each band
Using multitaper spectrum estimation with 7 DPSS windows
the following metrics will be computed: WPLI
computing connectivity for epoch 1
computing connectivity for epoch 2
computing connectivity for epoch 3
computing connectivity for epoch 4
computing connectivity for epoch 5
computing connectivity for epoch 6
computing connectivity for epoch 7
computing connectivity for epoch 8
computing connectivity for epoch 9
computing connectivity for epoch 10
computing connectivity for epoch 11
computing connectivity for epoch 12
computing connectivity for epoch 13
computing connectivity for epoch 14
computing connectivity for epoch 15
computing connectivity for epoch 16
computing connectivity for epoch 17
computing connectivity for epoch 18
computing connectivity for epoch 19
computing connectivity for epoch 20
computing connectivity for epoch 21
computing connectivity for epoch 22
computing connectivity for epoch 23
computing connectivity for epoch 24
computing connectivity for epoch 25
computing connectivity for epoch 26
computing connectivity for epoch 27
computing connectivity for epoch 28
computing connectivity for epoch 29
computing connectivity for epoch 30
computing connectivity for epoch 31
computing connectivity for epoch 32
computing connectivity for epoch 33
computing connectivity for epoch 34
computing connectivity for epoch 35
computing connectivity for epoch 36
computing connectivity for epoch 37
computing connectivity for epoch 38
computing connectivity for epoch 39
computing connectivity for epoch 40
computing connectivity for epoch 41
computing connectivity for epoch 42
computing connectivity for epoch 43
computing connectivity for epoch 44
computing connectivity for epoch 45
computing connectivity for epoch 46
computing connectivity for epoch 47
computing connectivity for epoch 48
computing connectivity for epoch 49
computing connectivity for epoch 50
computing connectivity for epoch 51
computing connectivity for epoch 52
computing connectivity for epoch 53
computing connectivity for epoch 54
computing connectivity for epoch 55
computing connectivity for epoch 56
computing connectivity for epoch 57
computing connectivity for epoch 58
computing connectivity for epoch 59
computing connectivity for epoch 60
computing connectivity for epoch 61
computing connectivity for epoch 62
computing connectivity for epoch 63
computing connectivity for epoch 64
computing connectivity for epoch 65
computing connectivity for epoch 66
computing connectivity for epoch 67
computing connectivity for epoch 68
computing connectivity for epoch 69
computing connectivity for epoch 70
computing connectivity for epoch 71
computing connectivity for epoch 72
computing connectivity for epoch 73
computing connectivity for epoch 74
computing connectivity for epoch 75
computing connectivity for epoch 76
computing connectivity for epoch 77
computing connectivity for epoch 78
computing connectivity for epoch 79
computing connectivity for epoch 80
computing connectivity for epoch 81
computing connectivity for epoch 82
computing connectivity for epoch 83
computing connectivity for epoch 84
computing connectivity for epoch 85
computing connectivity for epoch 86
computing connectivity for epoch 87
computing connectivity for epoch 88
computing connectivity for epoch 89
computing connectivity for epoch 90
computing connectivity for epoch 91
computing connectivity for epoch 92
computing connectivity for epoch 93
computing connectivity for epoch 94
computing connectivity for epoch 95
computing connectivity for epoch 96
computing connectivity for epoch 97
computing connectivity for epoch 98
computing connectivity for epoch 99
computing connectivity for epoch 100
computing connectivity for epoch 101
computing connectivity for epoch 102
computing connectivity for epoch 103
computing connectivity for epoch 104
computing connectivity for epoch 105
computing connectivity for epoch 106
computing connectivity for epoch 107
computing connectivity for epoch 108
computing connectivity for epoch 109
computing connectivity for epoch 110
computing connectivity for epoch 111
computing connectivity for epoch 112
computing connectivity for epoch 113
computing connectivity for epoch 114
computing connectivity for epoch 115
computing connectivity for epoch 116
computing connectivity for epoch 117
computing connectivity for epoch 118
computing connectivity for epoch 119
computing connectivity for epoch 120
computing connectivity for epoch 121
computing connectivity for epoch 122
computing connectivity for epoch 123
computing connectivity for epoch 124
computing connectivity for epoch 125
computing connectivity for epoch 126
computing connectivity for epoch 127
computing connectivity for epoch 128
computing connectivity for epoch 129
computing connectivity for epoch 130
computing connectivity for epoch 131
computing connectivity for epoch 132
computing connectivity for epoch 133
computing connectivity for epoch 134
computing connectivity for epoch 135
computing connectivity for epoch 136
computing connectivity for epoch 137
computing connectivity for epoch 138
computing connectivity for epoch 139
computing connectivity for epoch 140
computing connectivity for epoch 141
computing connectivity for epoch 142
computing connectivity for epoch 143
computing connectivity for epoch 144
computing connectivity for epoch 145
computing connectivity for epoch 146
computing connectivity for epoch 147
computing connectivity for epoch 148
computing connectivity for epoch 149
computing connectivity for epoch 150
computing connectivity for epoch 151
computing connectivity for epoch 152
computing connectivity for epoch 153
computing connectivity for epoch 154
computing connectivity for epoch 155
computing connectivity for epoch 156
computing connectivity for epoch 157
computing connectivity for epoch 158
computing connectivity for epoch 159
computing connectivity for epoch 160
computing connectivity for epoch 161
computing connectivity for epoch 162
computing connectivity for epoch 163
computing connectivity for epoch 164
computing connectivity for epoch 165
computing connectivity for epoch 166
computing connectivity for epoch 167
computing connectivity for epoch 168
computing connectivity for epoch 169
computing connectivity for epoch 170
computing connectivity for epoch 171
computing connectivity for epoch 172
computing connectivity for epoch 173
computing connectivity for epoch 174
computing connectivity for epoch 175
computing connectivity for epoch 176
computing connectivity for epoch 177
computing connectivity for epoch 178
computing connectivity for epoch 179
computing connectivity for epoch 180
computing connectivity for epoch 181
computing connectivity for epoch 182
computing connectivity for epoch 183
computing connectivity for epoch 184
computing connectivity for epoch 185
computing connectivity for epoch 186
computing connectivity for epoch 187
computing connectivity for epoch 188
computing connectivity for epoch 189
computing connectivity for epoch 190
computing connectivity for epoch 191
computing connectivity for epoch 192
computing connectivity for epoch 193
computing connectivity for epoch 194
computing connectivity for epoch 195
computing connectivity for epoch 196
computing connectivity for epoch 197
computing connectivity for epoch 198
computing connectivity for epoch 199
computing connectivity for epoch 200
computing connectivity for epoch 201
computing connectivity for epoch 202
computing connectivity for epoch 203
computing connectivity for epoch 204
computing connectivity for epoch 205
computing connectivity for epoch 206
computing connectivity for epoch 207
computing connectivity for epoch 208
computing connectivity for epoch 209
computing connectivity for epoch 210
computing connectivity for epoch 211
computing connectivity for epoch 212
computing connectivity for epoch 213
computing connectivity for epoch 214
computing connectivity for epoch 215
computing connectivity for epoch 216
computing connectivity for epoch 217
computing connectivity for epoch 218
computing connectivity for epoch 219
computing connectivity for epoch 220
computing connectivity for epoch 221
computing connectivity for epoch 222
computing connectivity for epoch 223
computing connectivity for epoch 224
computing connectivity for epoch 225
computing connectivity for epoch 226
computing connectivity for epoch 227
computing connectivity for epoch 228
computing connectivity for epoch 229
computing connectivity for epoch 230
computing connectivity for epoch 231
computing connectivity for epoch 232
computing connectivity for epoch 233
computing connectivity for epoch 234
computing connectivity for epoch 235
computing connectivity for epoch 236
computing connectivity for epoch 237
computing connectivity for epoch 238
computing connectivity for epoch 239
computing connectivity for epoch 240
computing connectivity for epoch 241
computing connectivity for epoch 242
computing connectivity for epoch 243
computing connectivity for epoch 244
computing connectivity for epoch 245
computing connectivity for epoch 246
computing connectivity for epoch 247
computing connectivity for epoch 248
computing connectivity for epoch 249
computing connectivity for epoch 250
computing connectivity for epoch 251
computing connectivity for epoch 252
computing connectivity for epoch 253
computing connectivity for epoch 254
computing connectivity for epoch 255
computing connectivity for epoch 256
computing connectivity for epoch 257
computing connectivity for epoch 258
computing connectivity for epoch 259
computing connectivity for epoch 260
computing connectivity for epoch 261
computing connectivity for epoch 262
computing connectivity for epoch 263
computing connectivity for epoch 264
computing connectivity for epoch 265
computing connectivity for epoch 266
computing connectivity for epoch 267
computing connectivity for epoch 268
computing connectivity for epoch 269
computing connectivity for epoch 270
computing connectivity for epoch 271
computing connectivity for epoch 272
computing connectivity for epoch 273
computing connectivity for epoch 274
computing connectivity for epoch 275
computing connectivity for epoch 276
computing connectivity for epoch 277
computing connectivity for epoch 278
computing connectivity for epoch 279
computing connectivity for epoch 280
computing connectivity for epoch 281
computing connectivity for epoch 282
computing connectivity for epoch 283
computing connectivity for epoch 284
computing connectivity for epoch 285
computing connectivity for epoch 286
computing connectivity for epoch 287
computing connectivity for epoch 288
computing connectivity for epoch 289
computing connectivity for epoch 290
computing connectivity for epoch 291
computing connectivity for epoch 292
computing connectivity for epoch 293
computing connectivity for epoch 294
computing connectivity for epoch 295
computing connectivity for epoch 296
computing connectivity for epoch 297
computing connectivity for epoch 298
computing connectivity for epoch 299
computing connectivity for epoch 300
[Connectivity computation done]
Connectivity computation...
computing connectivity for 5 connections
using t=0.000s..9.996s for estimation (2500 points)
frequencies: 9.0Hz..11.0Hz (21 points)
connectivity scores will be averaged for each band
Using multitaper spectrum estimation with 7 DPSS windows
the following metrics will be computed: DPLI
computing connectivity for epoch 1
computing connectivity for epoch 2
computing connectivity for epoch 3
computing connectivity for epoch 4
computing connectivity for epoch 5
computing connectivity for epoch 6
computing connectivity for epoch 7
computing connectivity for epoch 8
computing connectivity for epoch 9
computing connectivity for epoch 10
computing connectivity for epoch 11
computing connectivity for epoch 12
computing connectivity for epoch 13
computing connectivity for epoch 14
computing connectivity for epoch 15
computing connectivity for epoch 16
computing connectivity for epoch 17
computing connectivity for epoch 18
computing connectivity for epoch 19
computing connectivity for epoch 20
computing connectivity for epoch 21
computing connectivity for epoch 22
computing connectivity for epoch 23
computing connectivity for epoch 24
computing connectivity for epoch 25
computing connectivity for epoch 26
computing connectivity for epoch 27
computing connectivity for epoch 28
computing connectivity for epoch 29
computing connectivity for epoch 30
computing connectivity for epoch 31
computing connectivity for epoch 32
computing connectivity for epoch 33
computing connectivity for epoch 34
computing connectivity for epoch 35
computing connectivity for epoch 36
computing connectivity for epoch 37
computing connectivity for epoch 38
computing connectivity for epoch 39
computing connectivity for epoch 40
computing connectivity for epoch 41
computing connectivity for epoch 42
computing connectivity for epoch 43
computing connectivity for epoch 44
computing connectivity for epoch 45
computing connectivity for epoch 46
computing connectivity for epoch 47
computing connectivity for epoch 48
computing connectivity for epoch 49
computing connectivity for epoch 50
computing connectivity for epoch 51
computing connectivity for epoch 52
computing connectivity for epoch 53
computing connectivity for epoch 54
computing connectivity for epoch 55
computing connectivity for epoch 56
computing connectivity for epoch 57
computing connectivity for epoch 58
computing connectivity for epoch 59
computing connectivity for epoch 60
computing connectivity for epoch 61
computing connectivity for epoch 62
computing connectivity for epoch 63
computing connectivity for epoch 64
computing connectivity for epoch 65
computing connectivity for epoch 66
computing connectivity for epoch 67
computing connectivity for epoch 68
computing connectivity for epoch 69
computing connectivity for epoch 70
computing connectivity for epoch 71
computing connectivity for epoch 72
computing connectivity for epoch 73
computing connectivity for epoch 74
computing connectivity for epoch 75
computing connectivity for epoch 76
computing connectivity for epoch 77
computing connectivity for epoch 78
computing connectivity for epoch 79
computing connectivity for epoch 80
computing connectivity for epoch 81
computing connectivity for epoch 82
computing connectivity for epoch 83
computing connectivity for epoch 84
computing connectivity for epoch 85
computing connectivity for epoch 86
computing connectivity for epoch 87
computing connectivity for epoch 88
computing connectivity for epoch 89
computing connectivity for epoch 90
computing connectivity for epoch 91
computing connectivity for epoch 92
computing connectivity for epoch 93
computing connectivity for epoch 94
computing connectivity for epoch 95
computing connectivity for epoch 96
computing connectivity for epoch 97
computing connectivity for epoch 98
computing connectivity for epoch 99
computing connectivity for epoch 100
computing connectivity for epoch 101
computing connectivity for epoch 102
computing connectivity for epoch 103
computing connectivity for epoch 104
computing connectivity for epoch 105
computing connectivity for epoch 106
computing connectivity for epoch 107
computing connectivity for epoch 108
computing connectivity for epoch 109
computing connectivity for epoch 110
computing connectivity for epoch 111
computing connectivity for epoch 112
computing connectivity for epoch 113
computing connectivity for epoch 114
computing connectivity for epoch 115
computing connectivity for epoch 116
computing connectivity for epoch 117
computing connectivity for epoch 118
computing connectivity for epoch 119
computing connectivity for epoch 120
computing connectivity for epoch 121
computing connectivity for epoch 122
computing connectivity for epoch 123
computing connectivity for epoch 124
computing connectivity for epoch 125
computing connectivity for epoch 126
computing connectivity for epoch 127
computing connectivity for epoch 128
computing connectivity for epoch 129
computing connectivity for epoch 130
computing connectivity for epoch 131
computing connectivity for epoch 132
computing connectivity for epoch 133
computing connectivity for epoch 134
computing connectivity for epoch 135
computing connectivity for epoch 136
computing connectivity for epoch 137
computing connectivity for epoch 138
computing connectivity for epoch 139
computing connectivity for epoch 140
computing connectivity for epoch 141
computing connectivity for epoch 142
computing connectivity for epoch 143
computing connectivity for epoch 144
computing connectivity for epoch 145
computing connectivity for epoch 146
computing connectivity for epoch 147
computing connectivity for epoch 148
computing connectivity for epoch 149
computing connectivity for epoch 150
computing connectivity for epoch 151
computing connectivity for epoch 152
computing connectivity for epoch 153
computing connectivity for epoch 154
computing connectivity for epoch 155
computing connectivity for epoch 156
computing connectivity for epoch 157
computing connectivity for epoch 158
computing connectivity for epoch 159
computing connectivity for epoch 160
computing connectivity for epoch 161
computing connectivity for epoch 162
computing connectivity for epoch 163
computing connectivity for epoch 164
computing connectivity for epoch 165
computing connectivity for epoch 166
computing connectivity for epoch 167
computing connectivity for epoch 168
computing connectivity for epoch 169
computing connectivity for epoch 170
computing connectivity for epoch 171
computing connectivity for epoch 172
computing connectivity for epoch 173
computing connectivity for epoch 174
computing connectivity for epoch 175
computing connectivity for epoch 176
computing connectivity for epoch 177
computing connectivity for epoch 178
computing connectivity for epoch 179
computing connectivity for epoch 180
computing connectivity for epoch 181
computing connectivity for epoch 182
computing connectivity for epoch 183
computing connectivity for epoch 184
computing connectivity for epoch 185
computing connectivity for epoch 186
computing connectivity for epoch 187
computing connectivity for epoch 188
computing connectivity for epoch 189
computing connectivity for epoch 190
computing connectivity for epoch 191
computing connectivity for epoch 192
computing connectivity for epoch 193
computing connectivity for epoch 194
computing connectivity for epoch 195
computing connectivity for epoch 196
computing connectivity for epoch 197
computing connectivity for epoch 198
computing connectivity for epoch 199
computing connectivity for epoch 200
computing connectivity for epoch 201
computing connectivity for epoch 202
computing connectivity for epoch 203
computing connectivity for epoch 204
computing connectivity for epoch 205
computing connectivity for epoch 206
computing connectivity for epoch 207
computing connectivity for epoch 208
computing connectivity for epoch 209
computing connectivity for epoch 210
computing connectivity for epoch 211
computing connectivity for epoch 212
computing connectivity for epoch 213
computing connectivity for epoch 214
computing connectivity for epoch 215
computing connectivity for epoch 216
computing connectivity for epoch 217
computing connectivity for epoch 218
computing connectivity for epoch 219
computing connectivity for epoch 220
computing connectivity for epoch 221
computing connectivity for epoch 222
computing connectivity for epoch 223
computing connectivity for epoch 224
computing connectivity for epoch 225
computing connectivity for epoch 226
computing connectivity for epoch 227
computing connectivity for epoch 228
computing connectivity for epoch 229
computing connectivity for epoch 230
computing connectivity for epoch 231
computing connectivity for epoch 232
computing connectivity for epoch 233
computing connectivity for epoch 234
computing connectivity for epoch 235
computing connectivity for epoch 236
computing connectivity for epoch 237
computing connectivity for epoch 238
computing connectivity for epoch 239
computing connectivity for epoch 240
computing connectivity for epoch 241
computing connectivity for epoch 242
computing connectivity for epoch 243
computing connectivity for epoch 244
computing connectivity for epoch 245
computing connectivity for epoch 246
computing connectivity for epoch 247
computing connectivity for epoch 248
computing connectivity for epoch 249
computing connectivity for epoch 250
computing connectivity for epoch 251
computing connectivity for epoch 252
computing connectivity for epoch 253
computing connectivity for epoch 254
computing connectivity for epoch 255
computing connectivity for epoch 256
computing connectivity for epoch 257
computing connectivity for epoch 258
computing connectivity for epoch 259
computing connectivity for epoch 260
computing connectivity for epoch 261
computing connectivity for epoch 262
computing connectivity for epoch 263
computing connectivity for epoch 264
computing connectivity for epoch 265
computing connectivity for epoch 266
computing connectivity for epoch 267
computing connectivity for epoch 268
computing connectivity for epoch 269
computing connectivity for epoch 270
computing connectivity for epoch 271
computing connectivity for epoch 272
computing connectivity for epoch 273
computing connectivity for epoch 274
computing connectivity for epoch 275
computing connectivity for epoch 276
computing connectivity for epoch 277
computing connectivity for epoch 278
computing connectivity for epoch 279
computing connectivity for epoch 280
computing connectivity for epoch 281
computing connectivity for epoch 282
computing connectivity for epoch 283
computing connectivity for epoch 284
computing connectivity for epoch 285
computing connectivity for epoch 286
computing connectivity for epoch 287
computing connectivity for epoch 288
computing connectivity for epoch 289
computing connectivity for epoch 290
computing connectivity for epoch 291
computing connectivity for epoch 292
computing connectivity for epoch 293
computing connectivity for epoch 294
computing connectivity for epoch 295
computing connectivity for epoch 296
computing connectivity for epoch 297
computing connectivity for epoch 298
computing connectivity for epoch 299
computing connectivity for epoch 300
[Connectivity computation done]
```

The estimated connectivites are shown in the figure below, which provides insight into the differences between PLI/wPLI, and dPLI.

**Similarities Of All Measures**

Capture presence of connectivity in same situations (phase difference of \(\pm\frac{\pi}{2}\))

Do not predict connectivity when phase difference is a multiple of \(\pi\)

Bounded between \(0\) and \(1\)

**How dPLI is Different Than PLI/wPLI**

Null connectivity is \(0\) for PLI and wPLI, but \(0.5\) for dPLI

dPLI differentiates whether the reference signal is leading or lagging the other signal (lagging if \(0 <= dPlI < 0.5\), leading if \(0.5 < dPLI <= 1.0\))

```
x = np.arange(5)
plt.figure()
plt.bar(x - 0.2, conn[0], 0.2, align='center', label="PLI")
plt.bar(x, conn[1], 0.2, align='center', label="wPLI")
plt.bar(x + 0.2, conn[2], 0.2, align='center', label="dPLI")
plt.title("Connectivity Estimation Comparison")
plt.xticks(x, (r"$-\pi$", r"$-\pi/2$", r"$0$", r"$\pi/2$", r"$\pi$"))
plt.legend()
plt.xlabel("Phase Difference")
plt.ylabel("Estimated Connectivity")
plt.show()
```

## Robustness to Outliers and Noise with wPLI#

The previous experiment illustrated the advantages conferred by dPLI when differentiating leading and lagging phase relationships. This experiment will now focus on understanding the advantages of wPLI, and explore how it extends upon PLI.

The main difference between PLI and wPLI is in how different phase
relationships are *weighted*. In PLI, phase differences are weighted as
\(-1\) or \(1\) according to their sign. In wPLI, phase differences
are weighted based on their value, meaning that phase differences closer to
\(\pm\frac{\pi}{2}\) are weighted more heavily than those close to
\(0\) or any other multiple of \(\pi\).

This avoids a discontinuity at the transition between positive and negative phase, treating all phase differences near this transition in a similar way. This provides some robustness against outliers and noise when estimating connectivity. For instance, volume conduction can distort EEG/MEG recordings, wherein signals emanating from the same neural source will be picked up by multiple sensors on the scalp. This can effect connectivity estimations, bringing the relative phase differences between two signals close to \(0\). wPLI minimizes the contribution of phase relationships that are small but non-zero (and may thus be attributed to volume conduciton), while PLI weighs these in the same way as phase relationships of \(\pm\frac{\pi}{2}\).

To demonstrate this, we recreate a result from (Vinck et al, 2011) 2. Two sinusoids are simulated, where the phase difference for half of the epochs is \(\frac{\pi}{2}\), and is \(-\frac{\pi}{100}\) for the others. We also explore the effect of applying uniform noise to this phase difference.

```
n_noise = 41 # amount of noise amplitude samples in [0, 4]
data = [[]]
# Generate reference
for _ in range(n_e):
data[0].append(np.sin(2 * np.pi * f * t))
A_list = np.linspace(0, 4, n_noise)
for A in A_list:
sig = []
# Generate other signal
for _ in range(int(n_e / 2)): # phase difference -pi/100
sig.append(np.sin(2 * np.pi * f * t + np.pi /
100 + A * np.random.uniform(-1, 1)))
for _ in range(int(n_e / 2), n_e): # phase difference pi/2
sig.append(np.sin(2 * np.pi * f * t - np.pi /
2 + A * np.random.uniform(-1, 1)))
data.append(sig)
data = np.swapaxes(np.array(data), 0, 1)
# Visualize the data
fig, ax = plt.subplots(1, 2, figsize=(12, 5), sharey=True)
ax[0].plot(t[:10], data[0, 0, :10], label="Reference")
ax[0].plot(t[:10], data[1, 1, :10])
ax[0].set_title(r"Phase Lagging ($-\pi/100$ Phase Difference)")
ax[0].set_xlabel("Time (s)")
ax[0].set_ylabel("Signal")
ax[0].legend()
ax[1].plot(t[:fs], data[0, 0, :fs], label="Reference")
ax[1].plot(t[:fs], data[-1, 1, :fs])
ax[1].set_title(r"Phase Leading ($\pi/2$ Phase Difference)")
ax[1].set_xlabel("Time (s)")
plt.show()
```

We can now compute PLI and wPLI

Out:

```
Connectivity computation...
computing connectivity for 41 connections
using t=0.000s..9.996s for estimation (2500 points)
frequencies: 9.0Hz..11.0Hz (21 points)
connectivity scores will be averaged for each band
Using multitaper spectrum estimation with 7 DPSS windows
the following metrics will be computed: PLI
computing connectivity for epoch 1
computing connectivity for epoch 2
computing connectivity for epoch 3
computing connectivity for epoch 4
computing connectivity for epoch 5
computing connectivity for epoch 6
computing connectivity for epoch 7
computing connectivity for epoch 8
computing connectivity for epoch 9
computing connectivity for epoch 10
computing connectivity for epoch 11
computing connectivity for epoch 12
computing connectivity for epoch 13
computing connectivity for epoch 14
computing connectivity for epoch 15
computing connectivity for epoch 16
computing connectivity for epoch 17
computing connectivity for epoch 18
computing connectivity for epoch 19
computing connectivity for epoch 20
computing connectivity for epoch 21
computing connectivity for epoch 22
computing connectivity for epoch 23
computing connectivity for epoch 24
computing connectivity for epoch 25
computing connectivity for epoch 26
computing connectivity for epoch 27
computing connectivity for epoch 28
computing connectivity for epoch 29
computing connectivity for epoch 30
computing connectivity for epoch 31
computing connectivity for epoch 32
computing connectivity for epoch 33
computing connectivity for epoch 34
computing connectivity for epoch 35
computing connectivity for epoch 36
computing connectivity for epoch 37
computing connectivity for epoch 38
computing connectivity for epoch 39
computing connectivity for epoch 40
computing connectivity for epoch 41
computing connectivity for epoch 42
computing connectivity for epoch 43
computing connectivity for epoch 44
computing connectivity for epoch 45
computing connectivity for epoch 46
computing connectivity for epoch 47
computing connectivity for epoch 48
computing connectivity for epoch 49
computing connectivity for epoch 50
computing connectivity for epoch 51
computing connectivity for epoch 52
computing connectivity for epoch 53
computing connectivity for epoch 54
computing connectivity for epoch 55
computing connectivity for epoch 56
computing connectivity for epoch 57
computing connectivity for epoch 58
computing connectivity for epoch 59
computing connectivity for epoch 60
computing connectivity for epoch 61
computing connectivity for epoch 62
computing connectivity for epoch 63
computing connectivity for epoch 64
computing connectivity for epoch 65
computing connectivity for epoch 66
computing connectivity for epoch 67
computing connectivity for epoch 68
computing connectivity for epoch 69
computing connectivity for epoch 70
computing connectivity for epoch 71
computing connectivity for epoch 72
computing connectivity for epoch 73
computing connectivity for epoch 74
computing connectivity for epoch 75
computing connectivity for epoch 76
computing connectivity for epoch 77
computing connectivity for epoch 78
computing connectivity for epoch 79
computing connectivity for epoch 80
computing connectivity for epoch 81
computing connectivity for epoch 82
computing connectivity for epoch 83
computing connectivity for epoch 84
computing connectivity for epoch 85
computing connectivity for epoch 86
computing connectivity for epoch 87
computing connectivity for epoch 88
computing connectivity for epoch 89
computing connectivity for epoch 90
computing connectivity for epoch 91
computing connectivity for epoch 92
computing connectivity for epoch 93
computing connectivity for epoch 94
computing connectivity for epoch 95
computing connectivity for epoch 96
computing connectivity for epoch 97
computing connectivity for epoch 98
computing connectivity for epoch 99
computing connectivity for epoch 100
computing connectivity for epoch 101
computing connectivity for epoch 102
computing connectivity for epoch 103
computing connectivity for epoch 104
computing connectivity for epoch 105
computing connectivity for epoch 106
computing connectivity for epoch 107
computing connectivity for epoch 108
computing connectivity for epoch 109
computing connectivity for epoch 110
computing connectivity for epoch 111
computing connectivity for epoch 112
computing connectivity for epoch 113
computing connectivity for epoch 114
computing connectivity for epoch 115
computing connectivity for epoch 116
computing connectivity for epoch 117
computing connectivity for epoch 118
computing connectivity for epoch 119
computing connectivity for epoch 120
computing connectivity for epoch 121
computing connectivity for epoch 122
computing connectivity for epoch 123
computing connectivity for epoch 124
computing connectivity for epoch 125
computing connectivity for epoch 126
computing connectivity for epoch 127
computing connectivity for epoch 128
computing connectivity for epoch 129
computing connectivity for epoch 130
computing connectivity for epoch 131
computing connectivity for epoch 132
computing connectivity for epoch 133
computing connectivity for epoch 134
computing connectivity for epoch 135
computing connectivity for epoch 136
computing connectivity for epoch 137
computing connectivity for epoch 138
computing connectivity for epoch 139
computing connectivity for epoch 140
computing connectivity for epoch 141
computing connectivity for epoch 142
computing connectivity for epoch 143
computing connectivity for epoch 144
computing connectivity for epoch 145
computing connectivity for epoch 146
computing connectivity for epoch 147
computing connectivity for epoch 148
computing connectivity for epoch 149
computing connectivity for epoch 150
computing connectivity for epoch 151
computing connectivity for epoch 152
computing connectivity for epoch 153
computing connectivity for epoch 154
computing connectivity for epoch 155
computing connectivity for epoch 156
computing connectivity for epoch 157
computing connectivity for epoch 158
computing connectivity for epoch 159
computing connectivity for epoch 160
computing connectivity for epoch 161
computing connectivity for epoch 162
computing connectivity for epoch 163
computing connectivity for epoch 164
computing connectivity for epoch 165
computing connectivity for epoch 166
computing connectivity for epoch 167
computing connectivity for epoch 168
computing connectivity for epoch 169
computing connectivity for epoch 170
computing connectivity for epoch 171
computing connectivity for epoch 172
computing connectivity for epoch 173
computing connectivity for epoch 174
computing connectivity for epoch 175
computing connectivity for epoch 176
computing connectivity for epoch 177
computing connectivity for epoch 178
computing connectivity for epoch 179
computing connectivity for epoch 180
computing connectivity for epoch 181
computing connectivity for epoch 182
computing connectivity for epoch 183
computing connectivity for epoch 184
computing connectivity for epoch 185
computing connectivity for epoch 186
computing connectivity for epoch 187
computing connectivity for epoch 188
computing connectivity for epoch 189
computing connectivity for epoch 190
computing connectivity for epoch 191
computing connectivity for epoch 192
computing connectivity for epoch 193
computing connectivity for epoch 194
computing connectivity for epoch 195
computing connectivity for epoch 196
computing connectivity for epoch 197
computing connectivity for epoch 198
computing connectivity for epoch 199
computing connectivity for epoch 200
computing connectivity for epoch 201
computing connectivity for epoch 202
computing connectivity for epoch 203
computing connectivity for epoch 204
computing connectivity for epoch 205
computing connectivity for epoch 206
computing connectivity for epoch 207
computing connectivity for epoch 208
computing connectivity for epoch 209
computing connectivity for epoch 210
computing connectivity for epoch 211
computing connectivity for epoch 212
computing connectivity for epoch 213
computing connectivity for epoch 214
computing connectivity for epoch 215
computing connectivity for epoch 216
computing connectivity for epoch 217
computing connectivity for epoch 218
computing connectivity for epoch 219
computing connectivity for epoch 220
computing connectivity for epoch 221
computing connectivity for epoch 222
computing connectivity for epoch 223
computing connectivity for epoch 224
computing connectivity for epoch 225
computing connectivity for epoch 226
computing connectivity for epoch 227
computing connectivity for epoch 228
computing connectivity for epoch 229
computing connectivity for epoch 230
computing connectivity for epoch 231
computing connectivity for epoch 232
computing connectivity for epoch 233
computing connectivity for epoch 234
computing connectivity for epoch 235
computing connectivity for epoch 236
computing connectivity for epoch 237
computing connectivity for epoch 238
computing connectivity for epoch 239
computing connectivity for epoch 240
computing connectivity for epoch 241
computing connectivity for epoch 242
computing connectivity for epoch 243
computing connectivity for epoch 244
computing connectivity for epoch 245
computing connectivity for epoch 246
computing connectivity for epoch 247
computing connectivity for epoch 248
computing connectivity for epoch 249
computing connectivity for epoch 250
computing connectivity for epoch 251
computing connectivity for epoch 252
computing connectivity for epoch 253
computing connectivity for epoch 254
computing connectivity for epoch 255
computing connectivity for epoch 256
computing connectivity for epoch 257
computing connectivity for epoch 258
computing connectivity for epoch 259
computing connectivity for epoch 260
computing connectivity for epoch 261
computing connectivity for epoch 262
computing connectivity for epoch 263
computing connectivity for epoch 264
computing connectivity for epoch 265
computing connectivity for epoch 266
computing connectivity for epoch 267
computing connectivity for epoch 268
computing connectivity for epoch 269
computing connectivity for epoch 270
computing connectivity for epoch 271
computing connectivity for epoch 272
computing connectivity for epoch 273
computing connectivity for epoch 274
computing connectivity for epoch 275
computing connectivity for epoch 276
computing connectivity for epoch 277
computing connectivity for epoch 278
computing connectivity for epoch 279
computing connectivity for epoch 280
computing connectivity for epoch 281
computing connectivity for epoch 282
computing connectivity for epoch 283
computing connectivity for epoch 284
computing connectivity for epoch 285
computing connectivity for epoch 286
computing connectivity for epoch 287
computing connectivity for epoch 288
computing connectivity for epoch 289
computing connectivity for epoch 290
computing connectivity for epoch 291
computing connectivity for epoch 292
computing connectivity for epoch 293
computing connectivity for epoch 294
computing connectivity for epoch 295
computing connectivity for epoch 296
computing connectivity for epoch 297
computing connectivity for epoch 298
computing connectivity for epoch 299
computing connectivity for epoch 300
[Connectivity computation done]
Connectivity computation...
computing connectivity for 41 connections
using t=0.000s..9.996s for estimation (2500 points)
frequencies: 9.0Hz..11.0Hz (21 points)
connectivity scores will be averaged for each band
Using multitaper spectrum estimation with 7 DPSS windows
the following metrics will be computed: WPLI
computing connectivity for epoch 1
computing connectivity for epoch 2
computing connectivity for epoch 3
computing connectivity for epoch 4
computing connectivity for epoch 5
computing connectivity for epoch 6
computing connectivity for epoch 7
computing connectivity for epoch 8
computing connectivity for epoch 9
computing connectivity for epoch 10
computing connectivity for epoch 11
computing connectivity for epoch 12
computing connectivity for epoch 13
computing connectivity for epoch 14
computing connectivity for epoch 15
computing connectivity for epoch 16
computing connectivity for epoch 17
computing connectivity for epoch 18
computing connectivity for epoch 19
computing connectivity for epoch 20
computing connectivity for epoch 21
computing connectivity for epoch 22
computing connectivity for epoch 23
computing connectivity for epoch 24
computing connectivity for epoch 25
computing connectivity for epoch 26
computing connectivity for epoch 27
computing connectivity for epoch 28
computing connectivity for epoch 29
computing connectivity for epoch 30
computing connectivity for epoch 31
computing connectivity for epoch 32
computing connectivity for epoch 33
computing connectivity for epoch 34
computing connectivity for epoch 35
computing connectivity for epoch 36
computing connectivity for epoch 37
computing connectivity for epoch 38
computing connectivity for epoch 39
computing connectivity for epoch 40
computing connectivity for epoch 41
computing connectivity for epoch 42
computing connectivity for epoch 43
computing connectivity for epoch 44
computing connectivity for epoch 45
computing connectivity for epoch 46
computing connectivity for epoch 47
computing connectivity for epoch 48
computing connectivity for epoch 49
computing connectivity for epoch 50
computing connectivity for epoch 51
computing connectivity for epoch 52
computing connectivity for epoch 53
computing connectivity for epoch 54
computing connectivity for epoch 55
computing connectivity for epoch 56
computing connectivity for epoch 57
computing connectivity for epoch 58
computing connectivity for epoch 59
computing connectivity for epoch 60
computing connectivity for epoch 61
computing connectivity for epoch 62
computing connectivity for epoch 63
computing connectivity for epoch 64
computing connectivity for epoch 65
computing connectivity for epoch 66
computing connectivity for epoch 67
computing connectivity for epoch 68
computing connectivity for epoch 69
computing connectivity for epoch 70
computing connectivity for epoch 71
computing connectivity for epoch 72
computing connectivity for epoch 73
computing connectivity for epoch 74
computing connectivity for epoch 75
computing connectivity for epoch 76
computing connectivity for epoch 77
computing connectivity for epoch 78
computing connectivity for epoch 79
computing connectivity for epoch 80
computing connectivity for epoch 81
computing connectivity for epoch 82
computing connectivity for epoch 83
computing connectivity for epoch 84
computing connectivity for epoch 85
computing connectivity for epoch 86
computing connectivity for epoch 87
computing connectivity for epoch 88
computing connectivity for epoch 89
computing connectivity for epoch 90
computing connectivity for epoch 91
computing connectivity for epoch 92
computing connectivity for epoch 93
computing connectivity for epoch 94
computing connectivity for epoch 95
computing connectivity for epoch 96
computing connectivity for epoch 97
computing connectivity for epoch 98
computing connectivity for epoch 99
computing connectivity for epoch 100
computing connectivity for epoch 101
computing connectivity for epoch 102
computing connectivity for epoch 103
computing connectivity for epoch 104
computing connectivity for epoch 105
computing connectivity for epoch 106
computing connectivity for epoch 107
computing connectivity for epoch 108
computing connectivity for epoch 109
computing connectivity for epoch 110
computing connectivity for epoch 111
computing connectivity for epoch 112
computing connectivity for epoch 113
computing connectivity for epoch 114
computing connectivity for epoch 115
computing connectivity for epoch 116
computing connectivity for epoch 117
computing connectivity for epoch 118
computing connectivity for epoch 119
computing connectivity for epoch 120
computing connectivity for epoch 121
computing connectivity for epoch 122
computing connectivity for epoch 123
computing connectivity for epoch 124
computing connectivity for epoch 125
computing connectivity for epoch 126
computing connectivity for epoch 127
computing connectivity for epoch 128
computing connectivity for epoch 129
computing connectivity for epoch 130
computing connectivity for epoch 131
computing connectivity for epoch 132
computing connectivity for epoch 133
computing connectivity for epoch 134
computing connectivity for epoch 135
computing connectivity for epoch 136
computing connectivity for epoch 137
computing connectivity for epoch 138
computing connectivity for epoch 139
computing connectivity for epoch 140
computing connectivity for epoch 141
computing connectivity for epoch 142
computing connectivity for epoch 143
computing connectivity for epoch 144
computing connectivity for epoch 145
computing connectivity for epoch 146
computing connectivity for epoch 147
computing connectivity for epoch 148
computing connectivity for epoch 149
computing connectivity for epoch 150
computing connectivity for epoch 151
computing connectivity for epoch 152
computing connectivity for epoch 153
computing connectivity for epoch 154
computing connectivity for epoch 155
computing connectivity for epoch 156
computing connectivity for epoch 157
computing connectivity for epoch 158
computing connectivity for epoch 159
computing connectivity for epoch 160
computing connectivity for epoch 161
computing connectivity for epoch 162
computing connectivity for epoch 163
computing connectivity for epoch 164
computing connectivity for epoch 165
computing connectivity for epoch 166
computing connectivity for epoch 167
computing connectivity for epoch 168
computing connectivity for epoch 169
computing connectivity for epoch 170
computing connectivity for epoch 171
computing connectivity for epoch 172
computing connectivity for epoch 173
computing connectivity for epoch 174
computing connectivity for epoch 175
computing connectivity for epoch 176
computing connectivity for epoch 177
computing connectivity for epoch 178
computing connectivity for epoch 179
computing connectivity for epoch 180
computing connectivity for epoch 181
computing connectivity for epoch 182
computing connectivity for epoch 183
computing connectivity for epoch 184
computing connectivity for epoch 185
computing connectivity for epoch 186
computing connectivity for epoch 187
computing connectivity for epoch 188
computing connectivity for epoch 189
computing connectivity for epoch 190
computing connectivity for epoch 191
computing connectivity for epoch 192
computing connectivity for epoch 193
computing connectivity for epoch 194
computing connectivity for epoch 195
computing connectivity for epoch 196
computing connectivity for epoch 197
computing connectivity for epoch 198
computing connectivity for epoch 199
computing connectivity for epoch 200
computing connectivity for epoch 201
computing connectivity for epoch 202
computing connectivity for epoch 203
computing connectivity for epoch 204
computing connectivity for epoch 205
computing connectivity for epoch 206
computing connectivity for epoch 207
computing connectivity for epoch 208
computing connectivity for epoch 209
computing connectivity for epoch 210
computing connectivity for epoch 211
computing connectivity for epoch 212
computing connectivity for epoch 213
computing connectivity for epoch 214
computing connectivity for epoch 215
computing connectivity for epoch 216
computing connectivity for epoch 217
computing connectivity for epoch 218
computing connectivity for epoch 219
computing connectivity for epoch 220
computing connectivity for epoch 221
computing connectivity for epoch 222
computing connectivity for epoch 223
computing connectivity for epoch 224
computing connectivity for epoch 225
computing connectivity for epoch 226
computing connectivity for epoch 227
computing connectivity for epoch 228
computing connectivity for epoch 229
computing connectivity for epoch 230
computing connectivity for epoch 231
computing connectivity for epoch 232
computing connectivity for epoch 233
computing connectivity for epoch 234
computing connectivity for epoch 235
computing connectivity for epoch 236
computing connectivity for epoch 237
computing connectivity for epoch 238
computing connectivity for epoch 239
computing connectivity for epoch 240
computing connectivity for epoch 241
computing connectivity for epoch 242
computing connectivity for epoch 243
computing connectivity for epoch 244
computing connectivity for epoch 245
computing connectivity for epoch 246
computing connectivity for epoch 247
computing connectivity for epoch 248
computing connectivity for epoch 249
computing connectivity for epoch 250
computing connectivity for epoch 251
computing connectivity for epoch 252
computing connectivity for epoch 253
computing connectivity for epoch 254
computing connectivity for epoch 255
computing connectivity for epoch 256
computing connectivity for epoch 257
computing connectivity for epoch 258
computing connectivity for epoch 259
computing connectivity for epoch 260
computing connectivity for epoch 261
computing connectivity for epoch 262
computing connectivity for epoch 263
computing connectivity for epoch 264
computing connectivity for epoch 265
computing connectivity for epoch 266
computing connectivity for epoch 267
computing connectivity for epoch 268
computing connectivity for epoch 269
computing connectivity for epoch 270
computing connectivity for epoch 271
computing connectivity for epoch 272
computing connectivity for epoch 273
computing connectivity for epoch 274
computing connectivity for epoch 275
computing connectivity for epoch 276
computing connectivity for epoch 277
computing connectivity for epoch 278
computing connectivity for epoch 279
computing connectivity for epoch 280
computing connectivity for epoch 281
computing connectivity for epoch 282
computing connectivity for epoch 283
computing connectivity for epoch 284
computing connectivity for epoch 285
computing connectivity for epoch 286
computing connectivity for epoch 287
computing connectivity for epoch 288
computing connectivity for epoch 289
computing connectivity for epoch 290
computing connectivity for epoch 291
computing connectivity for epoch 292
computing connectivity for epoch 293
computing connectivity for epoch 294
computing connectivity for epoch 295
computing connectivity for epoch 296
computing connectivity for epoch 297
computing connectivity for epoch 298
computing connectivity for epoch 299
computing connectivity for epoch 300
[Connectivity computation done]
```

The results from the simulation are shown in the figure below. In the case without noise, the difference between wPLI and PLI is made obvious. In PLI, no connectivity is detected, as the \(-\frac{\pi}{100}\) phase differences are weighted in the exact same way as the \(\frac{\pi}{2}\) relationships. wPLI is able to avoid the cancellation of the \(\frac{\pi}{2}\) relationships.

As noise gets added, PLI increases since the \(-\frac{\pi}{100}\) relationships are made positive more often than the \(\frac{\pi}{2}\) relationships are made negative. However, wPLI maintains an advantage in its ability to distinguish the underlying structure. Beyond a certain point, the noise dominates any pre-defined structure, and both methods behave similarly, tending toward \(0\). For a more detailed analysis of this result and the properties of wPLI, please refer to (Vinck et al, 2011) 2.

```
plt.figure()
plt.plot(A_list, conn[0], "o-", label="PLI")
plt.plot(A_list, conn[1], "o-", label="wPLI")
plt.legend()
plt.xlabel("Noise Amplitude")
plt.ylabel("Connectivity Measure")
plt.title("wPLI and PLI Under Increasing Noise")
plt.show()
```

## Demo On MEG Data#

To finish this example, we also quickly demonstrate these methods on some sample MEG data recorded during visual stimulation.

```
data_path = sample.data_path()
raw_fname = data_path / 'MEG/sample/sample_audvis_filt-0-40_raw.fif'
event_fname = data_path / 'MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
raw = mne.io.read_raw_fif(raw_fname)
events = mne.read_events(event_fname)
# Select gradiometers
picks = mne.pick_types(raw.info, meg='grad', eeg=False, stim=False, eog=True,
exclude='bads')
# Create epochs
event_id, tmin, tmax = 3, -0.2, 1.5 # need a long enough epoch for 5 cycles
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), reject=dict(grad=4000e-13, eog=150e-6))
epochs.load_data().pick_types(meg='grad') # just keep MEG and no EOG now
fmin, fmax = 4., 9. # compute connectivity within 4-9 Hz
sfreq = raw.info['sfreq'] # the sampling frequency
tmin = 0.0 # exclude the baseline period
# Compute PLI, wPLI, and dPLI
con_pli = spectral_connectivity_epochs(
epochs, method='pli', mode='multitaper', sfreq=sfreq, fmin=fmin,
fmax=fmax, faverage=True, tmin=tmin, mt_adaptive=False, n_jobs=1)
con_wpli = spectral_connectivity_epochs(
epochs, method='wpli', mode='multitaper', sfreq=sfreq, fmin=fmin,
fmax=fmax, faverage=True, tmin=tmin, mt_adaptive=False, n_jobs=1)
con_dpli = spectral_connectivity_epochs(
epochs, method='dpli', mode='multitaper', sfreq=sfreq, fmin=fmin,
fmax=fmax, faverage=True, tmin=tmin, mt_adaptive=False, n_jobs=1)
```

Out:

```
Opening raw data file /Users/adam2392/mne_data/MNE-sample-data/MEG/sample/sample_audvis_filt-0-40_raw.fif...
Read a total of 4 projection items:
PCA-v1 (1 x 102) idle
PCA-v2 (1 x 102) idle
PCA-v3 (1 x 102) idle
Average EEG reference (1 x 60) idle
Range : 6450 ... 48149 = 42.956 ... 320.665 secs
Ready.
Not setting metadata
73 matching events found
Setting baseline interval to [-0.19979521315838786, 0.0] sec
Applying baseline correction (mode: mean)
4 projection items activated
Loading data for 73 events and 256 original time points ...
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
Rejecting epoch based on EOG : ['EOG 061']
24 bad epochs dropped
Removing projector <Projection | PCA-v1, active : True, n_channels : 102>
Removing projector <Projection | PCA-v2, active : True, n_channels : 102>
Removing projector <Projection | PCA-v3, active : True, n_channels : 102>
Removing projector <Projection | Average EEG reference, active : True, n_channels : 60>
Adding metadata with 3 columns
Connectivity computation...
only using indices for lower-triangular matrix
computing connectivity for 20503 connections
using t=0.000s..1.498s for estimation (226 points)
frequencies: 4.7Hz..8.6Hz (7 points)
connectivity scores will be averaged for each band
Using multitaper spectrum estimation with 7 DPSS windows
the following metrics will be computed: PLI
computing connectivity for epoch 1
computing connectivity for epoch 2
computing connectivity for epoch 3
computing connectivity for epoch 4
computing connectivity for epoch 5
computing connectivity for epoch 6
computing connectivity for epoch 7
computing connectivity for epoch 8
computing connectivity for epoch 9
computing connectivity for epoch 10
computing connectivity for epoch 11
computing connectivity for epoch 12
computing connectivity for epoch 13
computing connectivity for epoch 14
computing connectivity for epoch 15
computing connectivity for epoch 16
computing connectivity for epoch 17
computing connectivity for epoch 18
computing connectivity for epoch 19
computing connectivity for epoch 20
computing connectivity for epoch 21
computing connectivity for epoch 22
computing connectivity for epoch 23
computing connectivity for epoch 24
computing connectivity for epoch 25
computing connectivity for epoch 26
computing connectivity for epoch 27
computing connectivity for epoch 28
computing connectivity for epoch 29
computing connectivity for epoch 30
computing connectivity for epoch 31
computing connectivity for epoch 32
computing connectivity for epoch 33
computing connectivity for epoch 34
computing connectivity for epoch 35
computing connectivity for epoch 36
computing connectivity for epoch 37
computing connectivity for epoch 38
computing connectivity for epoch 39
computing connectivity for epoch 40
computing connectivity for epoch 41
computing connectivity for epoch 42
computing connectivity for epoch 43
computing connectivity for epoch 44
computing connectivity for epoch 45
computing connectivity for epoch 46
computing connectivity for epoch 47
computing connectivity for epoch 48
computing connectivity for epoch 49
assembling connectivity matrix
[Connectivity computation done]
Replacing existing metadata with 3 columns
Connectivity computation...
only using indices for lower-triangular matrix
computing connectivity for 20503 connections
using t=0.000s..1.498s for estimation (226 points)
frequencies: 4.7Hz..8.6Hz (7 points)
connectivity scores will be averaged for each band
Using multitaper spectrum estimation with 7 DPSS windows
the following metrics will be computed: WPLI
computing connectivity for epoch 1
computing connectivity for epoch 2
computing connectivity for epoch 3
computing connectivity for epoch 4
computing connectivity for epoch 5
computing connectivity for epoch 6
computing connectivity for epoch 7
computing connectivity for epoch 8
computing connectivity for epoch 9
computing connectivity for epoch 10
computing connectivity for epoch 11
computing connectivity for epoch 12
computing connectivity for epoch 13
computing connectivity for epoch 14
computing connectivity for epoch 15
computing connectivity for epoch 16
computing connectivity for epoch 17
computing connectivity for epoch 18
computing connectivity for epoch 19
computing connectivity for epoch 20
computing connectivity for epoch 21
computing connectivity for epoch 22
computing connectivity for epoch 23
computing connectivity for epoch 24
computing connectivity for epoch 25
computing connectivity for epoch 26
computing connectivity for epoch 27
computing connectivity for epoch 28
computing connectivity for epoch 29
computing connectivity for epoch 30
computing connectivity for epoch 31
computing connectivity for epoch 32
computing connectivity for epoch 33
computing connectivity for epoch 34
computing connectivity for epoch 35
computing connectivity for epoch 36
computing connectivity for epoch 37
computing connectivity for epoch 38
computing connectivity for epoch 39
computing connectivity for epoch 40
computing connectivity for epoch 41
computing connectivity for epoch 42
computing connectivity for epoch 43
computing connectivity for epoch 44
computing connectivity for epoch 45
computing connectivity for epoch 46
computing connectivity for epoch 47
computing connectivity for epoch 48
computing connectivity for epoch 49
assembling connectivity matrix
[Connectivity computation done]
Replacing existing metadata with 3 columns
Connectivity computation...
only using indices for lower-triangular matrix
computing connectivity for 20503 connections
using t=0.000s..1.498s for estimation (226 points)
frequencies: 4.7Hz..8.6Hz (7 points)
connectivity scores will be averaged for each band
Using multitaper spectrum estimation with 7 DPSS windows
the following metrics will be computed: DPLI
computing connectivity for epoch 1
computing connectivity for epoch 2
computing connectivity for epoch 3
computing connectivity for epoch 4
computing connectivity for epoch 5
computing connectivity for epoch 6
computing connectivity for epoch 7
computing connectivity for epoch 8
computing connectivity for epoch 9
computing connectivity for epoch 10
computing connectivity for epoch 11
computing connectivity for epoch 12
computing connectivity for epoch 13
computing connectivity for epoch 14
computing connectivity for epoch 15
computing connectivity for epoch 16
computing connectivity for epoch 17
computing connectivity for epoch 18
computing connectivity for epoch 19
computing connectivity for epoch 20
computing connectivity for epoch 21
computing connectivity for epoch 22
computing connectivity for epoch 23
computing connectivity for epoch 24
computing connectivity for epoch 25
computing connectivity for epoch 26
computing connectivity for epoch 27
computing connectivity for epoch 28
computing connectivity for epoch 29
computing connectivity for epoch 30
computing connectivity for epoch 31
computing connectivity for epoch 32
computing connectivity for epoch 33
computing connectivity for epoch 34
computing connectivity for epoch 35
computing connectivity for epoch 36
computing connectivity for epoch 37
computing connectivity for epoch 38
computing connectivity for epoch 39
computing connectivity for epoch 40
computing connectivity for epoch 41
computing connectivity for epoch 42
computing connectivity for epoch 43
computing connectivity for epoch 44
computing connectivity for epoch 45
computing connectivity for epoch 46
computing connectivity for epoch 47
computing connectivity for epoch 48
computing connectivity for epoch 49
assembling connectivity matrix
[Connectivity computation done]
```

In this example, there is strong connectivity between sensors 190-200 and sensors 110-160.

Moreover, after observing the presence of connectivity, dPLI can be used to ascertain the direction of the phase relationship. Here, it appears that the dPLI connectivity in this area is less than \(0.5\), and thus sensors 190-200 are lagging sensors 110-160.

In keeping with the previous simulation, we can see that wPLI identifies stronger connectivity relationships than PLI. This is due to its robustness against volume conduction effects decreasing the detected connectivity strength, as was mentioned earlier.

```
fig, axs = plt.subplots(1, 3, figsize=(14, 5), sharey=True)
axs[0].imshow(con_pli.get_data('dense'), vmin=0, vmax=1)
axs[0].set_title("PLI")
axs[0].set_ylabel("Sensor 1")
axs[0].set_xlabel("Sensor 2")
axs[1].imshow(con_wpli.get_data('dense'), vmin=0, vmax=1)
axs[1].set_title("wPLI")
axs[1].set_xlabel("Sensor 2")
im = axs[2].imshow(con_dpli.get_data('dense'), vmin=0, vmax=1)
axs[2].set_title("dPLI")
axs[2].set_xlabel("Sensor 2")
fig.colorbar(im, ax=axs.ravel())
plt.show()
```

## Conclusions#

Both wPLI and dPLI are extensions upon the original PLI method, and provide complementary information about underlying connectivity.

To identify the presence of an underlying phase relationship, wPLI is the method of choice for most researchers as it provides an improvement in robustness over the original PLI method

To know the directionality of the connectivity identified by wPLI, dPLI should be used

Ultimately, these methods work great together, providing a comprehensive estimate of phase-based connectivity.

## References#

- 1(1,2)
Cornelis J. Stam, Guido Nolte, and Andreas Daffertshofer. Phase lag index: assessment of functional connectivity from multi channel EEG and MEG with diminished bias from common sources.

*Human Brain Mapping*, 28(11):1178–1193, 2007. doi:10.1002/hbm.20346.- 2(1,2,3,4,5)
Martin Vinck, Robert Oostenveld, Marijn van Wingerden, Franscesco Battaglia, and Cyriel M.A. Pennartz. An improved index of phase-synchronization for electrophysiological data in the presence of volume-conduction, noise and sample-size bias.

*NeuroImage*, 55(4):1548–1565, 2011. doi:10.1016/j.neuroimage.2011.01.055.- 3(1,2)
C. J. Stam and E. C. W. van Straaten. Go with the flow: use of a directed phase lag index (dpli) to characterize patterns of phase relations in a large-scale model of brain dynamics.

*NeuroImage*, 62(3):1415–1428, Sep 2012. doi:10.1016/j.neuroimage.2012.05.050.

**Total running time of the script:** ( 0 minutes 10.495 seconds)