[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,
|
prec_to_partial,
|
||||||
sym_matrix_to_vec,
|
sym_matrix_to_vec,
|
||||||
)
|
)
|
||||||
from scipy import linalg
|
from scipy import linalg, stats
|
||||||
from sklearn.base import clone
|
from sklearn.base import clone
|
||||||
from sklearn.covariance import EmpiricalCovariance
|
from sklearn.covariance import EmpiricalCovariance
|
||||||
|
|
||||||
|
|
@ -314,15 +314,18 @@ class JuniferConnectivityMeasure(ConnectivityMeasure):
|
||||||
* default ``cov_estimator`` is
|
* default ``cov_estimator`` is
|
||||||
:class:`sklearn.covariance.EmpiricalCovariance`
|
:class:`sklearn.covariance.EmpiricalCovariance`
|
||||||
* default ``kind`` is ``"correlation"``
|
* default ``kind`` is ``"correlation"``
|
||||||
|
* supports Spearman's correlation via ``kind="spearman correlation"``
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
cov_estimator : estimator object, optional
|
cov_estimator : estimator object, optional
|
||||||
The covariance estimator
|
The covariance estimator
|
||||||
(default ``EmpiricalCovariance(store_precision=False)``).
|
(default ``EmpiricalCovariance(store_precision=False)``).
|
||||||
kind : {"covariance", "correlation", "partial correlation", \
|
kind : {"covariance", "correlation", "spearman correlation", \
|
||||||
"tangent", "precision"}, optional
|
"partial correlation", "tangent", "precision"}, optional
|
||||||
The matrix kind. For the use of ``"tangent"`` see [1]_
|
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").
|
(default "correlation").
|
||||||
vectorize : bool, optional
|
vectorize : bool, optional
|
||||||
If True, connectivity matrices are reshaped into 1D arrays and only
|
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)
|
self.cov_estimator_ = clone(self.cov_estimator)
|
||||||
|
|
||||||
# Compute all the matrices, stored in "connectivities"
|
# Compute all the matrices, stored in "connectivities"
|
||||||
if self.kind == "correlation":
|
if self.kind in ["correlation", "spearman correlation"]:
|
||||||
covariances_std = [
|
covariances_std = []
|
||||||
self.cov_estimator_.fit(
|
for x in X:
|
||||||
signal.standardize_signal(
|
x = signal.standardize_signal(
|
||||||
x,
|
x,
|
||||||
detrend=False,
|
detrend=False,
|
||||||
standardize=self.standardize,
|
standardize=self.standardize,
|
||||||
)
|
)
|
||||||
).covariance_
|
|
||||||
for x in X
|
# 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]
|
connectivities = [cov_to_corr(cov) for cov in covariances_std]
|
||||||
else:
|
else:
|
||||||
covariances = [self.cov_estimator_.fit(x).covariance_ for x in X]
|
covariances = [self.cov_estimator_.fit(x).covariance_ for x in X]
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ CONNECTIVITY_KINDS = (
|
||||||
"tangent",
|
"tangent",
|
||||||
"precision",
|
"precision",
|
||||||
"partial correlation",
|
"partial correlation",
|
||||||
|
"spearman correlation",
|
||||||
)
|
)
|
||||||
|
|
||||||
N_FEATURES = 49
|
N_FEATURES = 49
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue