8.4.9. Functional connectivity measures for group analysis of connectomesΒΆ

This example compares different measures of functional connectivity between regions of interest : correlation, partial correlation, as well as a measure called tangent. The resulting connectivity coefficients are used to classify ADHD vs control subjects and the tangent measure outperforms the standard measures.

# Fetch dataset
from nilearn import datasets
atlas = datasets.fetch_atlas_msdl()
dataset = datasets.fetch_adhd(n_subjects=20)

Extract regions time series signals

from nilearn import input_data
masker = input_data.NiftiMapsMasker(
    atlas.maps, resampling_target="maps", detrend=True,
    low_pass=.1, high_pass=.01, t_r=2.5, standardize=False,
    memory='nilearn_cache', memory_level=1)
subjects = []
sites = []
adhds = []
for func_file, confound_file, phenotypic in zip(
        dataset.func, dataset.confounds, dataset.phenotypic):
    time_series = masker.fit_transform(func_file, confounds=confound_file)
    adhds.append(phenotypic['adhd'])  # ADHD/control label

Estimate connectivity

from nilearn import connectome
kinds = ['tangent', 'partial correlation', 'correlation']
individual_connectivity_matrices = {}
mean_connectivity_matrix = {}
for kind in kinds:
    conn_measure = connectome.ConnectivityMeasure(kind=kind)
    individual_connectivity_matrices[kind] = conn_measure.fit_transform(
    # Compute the mean connectivity
    if kind == 'tangent':
        mean_connectivity_matrix[kind] = conn_measure.mean_
        mean_connectivity_matrix[kind] = \

Plot the mean connectome with hemispheric saggital cuts

import numpy as np
from nilearn import plotting
labels = atlas.labels
region_coords = atlas.region_coords
for kind in kinds:
                             region_coords, edge_threshold='98%',
                             title=kind, display_mode='lzry')
  • ../../_images/sphx_glr_plot_connectivity_measures_001.png
  • ../../_images/sphx_glr_plot_connectivity_measures_002.png
  • ../../_images/sphx_glr_plot_connectivity_measures_003.png

Use the connectivity coefficients to classify ADHD vs controls

from sklearn.svm import LinearSVC
from sklearn.cross_validation import StratifiedKFold, cross_val_score
classes = ['{0}{1}'.format(site, adhd) for site, adhd in zip(sites, adhds)]
print('Classification accuracy:')
mean_scores = []
cv = StratifiedKFold(classes, n_folds=3)
for kind in kinds:
    svc = LinearSVC()
    # Transform the connectivity matrices to 1D arrays
    coonectivity_coefs = connectome.sym_to_vec(
    cv_scores = cross_val_score(svc, coonectivity_coefs,
                                adhds, cv=cv, scoring='accuracy')
    print('%20s score: %1.2f +- %1.2f' % (kind, cv_scores.mean(),


Classification accuracy:
             tangent score: 0.74 +- 0.05
 partial correlation score: 0.67 +- 0.06
         correlation score: 0.56 +- 0.08

Display the classification scores

import matplotlib.pyplot as plt
plt.figure(figsize=(6, 4))
positions = np.arange(len(kinds)) * .1 + .1
plt.barh(positions, mean_scores, align='center', height=.05)
yticks = [kind.replace(' ', '\n') for kind in kinds]
plt.yticks(positions, yticks)
plt.xlabel('Classification accuracy')

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

Generated by Sphinx-Gallery