netneurotools.stats.network_pearsonr

netneurotools.stats.network_pearsonr(annot1, annot2, weight)[source]

Calculate pearson correlation between two annotation vectors.

Warning

Test before use.

Parameters:
  • annot1 ((N,) array_like) – First annotation vector, demean will be applied.

  • annot2 ((N,) array_like) – Second annotation vector, demean will be applied.

  • weight ((N, N) array_like) – Weight matrix. Diagonal elements should be 1.

Returns:

corr – Network correlation between annot1 and annot2

Return type:

float

Notes

If Pearson correlation is represented as

\[\rho_{x,y} = \dfrac{ \mathrm{sum}(I \times (\hat{x} \otimes \hat{y})) }{ \sigma_x \sigma_y }\]

The network correlation is defined analogously as

\[\rho_{x,y,G} = \dfrac{ \mathrm{sum}(W \times (\hat{x} \otimes \hat{y})) }{ \sigma_{x,W} \sigma_{y,W} }\]

where \(\hat{x}\) and \(\hat{y}\) are the demeaned annotation vectors,

The weight matrix \(W\) is used to represent the network structure. It is usually in the form of \(W = \\exp(-kL)\) where \(L\) is the length matrix and \(k\) is a decay parameter.

Example using shortest path length as weight

spl, _ = distance_wei_floyd(D) # input should be distance matrix
spl_wei = 1 / np.exp(spl)
netcorr = network_pearsonr(annot1, annot2, spl_wei)

Example using (inverse) effective resistance as weight

R_eff = effective_resistance(W)
R_eff_norm = R_eff / np.max(R_eff)
W = 1 / R_eff_norm
W = W / np.max(W)
np.fill_diagonal(W, 1.0)
netcorr = network_pearsonr(annot1, annot2, W)

References