[ENH]: In-built support for spearman correlation for FunctionalConnectivity markers #335
3 changed files with 25 additions and 15 deletions
1
docs/changes/newsfragments/335.enh
Normal file
1
docs/changes/newsfragments/335.enh
Normal file
|
|
@ -0,0 +1 @@
|
|||
Add support for Spearman's correlation in :class:`.JuniferConnectivityMeasure` by `Leonard Sasse`_
|
||||
|
|
@ -13,7 +13,7 @@ from nilearn.connectome import (
|
|||
prec_to_partial,
|
||||
sym_matrix_to_vec,
|
||||
)
|
||||
from scipy import linalg
|
||||
from scipy import linalg, stats
|
||||
from sklearn.base import clone
|
||||
from sklearn.covariance import EmpiricalCovariance
|
||||
|
||||
|
|
@ -314,15 +314,18 @@ class JuniferConnectivityMeasure(ConnectivityMeasure):
|
|||
* default ``cov_estimator`` is
|
||||
:class:`sklearn.covariance.EmpiricalCovariance`
|
||||
* default ``kind`` is ``"correlation"``
|
||||
* supports Spearman's correlation via ``kind="spearman correlation"``
|
||||
|
||||
Parameters
|
||||
----------
|
||||
cov_estimator : estimator object, optional
|
||||
The covariance estimator
|
||||
(default ``EmpiricalCovariance(store_precision=False)``).
|
||||
kind : {"covariance", "correlation", "partial correlation", \
|
||||
"tangent", "precision"}, optional
|
||||
The matrix kind. For the use of ``"tangent"`` see [1]_
|
||||
kind : {"covariance", "correlation", "spearman correlation", \
|
||||
"partial correlation", "tangent", "precision"}, optional
|
||||
The matrix kind. The default value uses Pearson's correlation.
|
||||
If ``"spearman correlation"`` is used, the data will be ranked before
|
||||
estimating the covariance. For the use of ``"tangent"`` see [1]_
|
||||
(default "correlation").
|
||||
vectorize : bool, optional
|
||||
If True, connectivity matrices are reshaped into 1D arrays and only
|
||||
|
|
@ -400,17 +403,22 @@ class JuniferConnectivityMeasure(ConnectivityMeasure):
|
|||
self.cov_estimator_ = clone(self.cov_estimator)
|
||||
|
||||
# Compute all the matrices, stored in "connectivities"
|
||||
if self.kind == "correlation":
|
||||
covariances_std = [
|
||||
self.cov_estimator_.fit(
|
||||
signal.standardize_signal(
|
||||
x,
|
||||
detrend=False,
|
||||
standardize=self.standardize,
|
||||
)
|
||||
).covariance_
|
||||
for x in X
|
||||
]
|
||||
if self.kind in ["correlation", "spearman correlation"]:
|
||||
covariances_std = []
|
||||
for x in X:
|
||||
x = signal.standardize_signal(
|
||||
x,
|
||||
detrend=False,
|
||||
standardize=self.standardize,
|
||||
)
|
||||
|
||||
# rank data if spearman correlation
|
||||
# before calculating covariance
|
||||
if self.kind == "spearman correlation":
|
||||
x = stats.rankdata(x, axis=0)
|
||||
|
||||
covariances_std.append(self.cov_estimator_.fit(x).covariance_)
|
||||
|
||||
connectivities = [cov_to_corr(cov) for cov in covariances_std]
|
||||
else:
|
||||
covariances = [self.cov_estimator_.fit(x).covariance_ for x in X]
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ CONNECTIVITY_KINDS = (
|
|||
"tangent",
|
||||
"precision",
|
||||
"partial correlation",
|
||||
"spearman correlation",
|
||||
)
|
||||
|
||||
N_FEATURES = 49
|
||||
|
|
|
|||
Loading…
Reference in a new issue