8.4.1. Group analysis of resting-state fMRI with ICA: CanICA

An example applying CanICA to resting-state data. This example applies it to 30 subjects of the ADHD200 datasets. Then it plots a map with all the components together and an axial cut for each of the components separately.

CanICA is an ICA method for group-level analysis of fMRI data. Compared to other strategies, it brings a well-controlled group model, as well as a thresholding algorithm controlling for specificity and sensitivity with an explicit model of the signal. The reference papers are:

  • G. Varoquaux et al. “A group model for stable multi-subject ICA on fMRI datasets”, NeuroImage Vol 51 (2010), p. 288-299
  • G. Varoquaux et al. “ICA-based sparse features recovery from fMRI datasets”, IEEE ISBI 2010, p. 1177

Pre-prints for both papers are available on hal (http://hal.archives-ouvertes.fr)

Note

The use of the attribute components_img_ from decomposition estimators is implemented from version 0.4.1. For older versions, unmask the deprecated attribute components_ to get the components image using attribute masker_ embedded in estimator. See the section Inverse transform: unmasking data.

8.4.1.1. First we load the ADHD200 data

from nilearn import datasets

adhd_dataset = datasets.fetch_adhd(n_subjects=30)
func_filenames = adhd_dataset.func  # list of 4D nifti files for each subject

# print basic information on the dataset
print('First functional nifti image (4D) is at: %s' %
      func_filenames[0])  # 4D data

Out:

Downloading data from https://www.nitrc.org/frs/download.php/7786/adhd40_0023008.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7787/adhd40_0023012.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7788/adhd40_0027011.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7789/adhd40_0027018.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7790/adhd40_0027034.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7791/adhd40_0027037.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7794/adhd40_1418396.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7795/adhd40_1517058.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7796/adhd40_1552181.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7797/adhd40_1562298.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7798/adhd40_1679142.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7799/adhd40_2014113.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7800/adhd40_2497695.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7801/adhd40_2950754.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7802/adhd40_3007585.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7803/adhd40_3154996.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7804/adhd40_3205761.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7805/adhd40_3520880.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7806/adhd40_3624598.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7807/adhd40_3699991.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7808/adhd40_3884955.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7809/adhd40_3902469.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7810/adhd40_3994098.tgz ...
Downloading data from https://www.nitrc.org/frs/download.php/7811/adhd40_4016887.tgz ...
First functional nifti image (4D) is at: /home/kamalakar/nilearn_data/adhd/data/0010042/0010042_rest_tshift_RPI_voreg_mni.nii.gz

8.4.1.2. Here we apply CanICA on the data

from nilearn.decomposition import CanICA

canica = CanICA(n_components=20, smoothing_fwhm=6.,
                memory="nilearn_cache", memory_level=2,
                threshold=3., verbose=10, random_state=0)
canica.fit(func_filenames)

# Retrieve the independent components in brain space. Directly
# accesible through attribute `components_img_`. Note that this
# attribute is implemented from version 0.4.1. For older versions,
# see note section above for details.
components_img = canica.components_img_
# components_img is a Nifti Image object, and can be saved to a file with
# the following line:
components_img.to_filename('canica_resting_state.nii.gz')

Out:

[MultiNiftiMasker.fit] Loading data from [/home/kamalakar/nilearn_data/adhd/data/0010042/0010042_rest_tshift_RPI_voreg_mni.nii.gz, /home/kamalakar/nilearn_data/adhd/data/0010064/0010064_rest_tshift_RPI_voreg_mni.nii.gz, /home/kamalakar/nilea
[MultiNiftiMasker.fit] Computing mask
[MultiNiftiMasker.transform] Resampling mask
[CanICA] Loading data
[Memory]    0.3s, 0.0min: Loading randomized_svd from nilearn_cache/joblib/sklearn/utils/extmath/randomized_svd/75022f35e0f2a3800612612a084f45ce
______________________________________randomized_svd cache loaded - 0.0s, 0.0min
________________________________________________________________________________
[Memory] Calling sklearn.decomposition.fastica_.fastica...
fastica(array([[ 0.002964, ...,  0.004765],
       ...,
       [ 0.003539, ..., -0.004918]]), fun='cube', random_state=209652396, whiten=True)
__________________________________________________________fastica - 2.7s, 0.0min
________________________________________________________________________________
[Memory] Calling sklearn.decomposition.fastica_.fastica...
fastica(array([[ 0.002964, ...,  0.004765],
       ...,
       [ 0.003539, ..., -0.004918]]), fun='cube', random_state=398764591, whiten=True)
__________________________________________________________fastica - 2.2s, 0.0min
________________________________________________________________________________
[Memory] Calling sklearn.decomposition.fastica_.fastica...
fastica(array([[ 0.002964, ...,  0.004765],
       ...,
       [ 0.003539, ..., -0.004918]]), fun='cube', random_state=924231285, whiten=True)
__________________________________________________________fastica - 1.9s, 0.0min
________________________________________________________________________________
[Memory] Calling sklearn.decomposition.fastica_.fastica...
fastica(array([[ 0.002964, ...,  0.004765],
       ...,
       [ 0.003539, ..., -0.004918]]), fun='cube', random_state=1478610112, whiten=True)
__________________________________________________________fastica - 2.6s, 0.0min
________________________________________________________________________________
[Memory] Calling sklearn.decomposition.fastica_.fastica...
fastica(array([[ 0.002964, ...,  0.004765],
       ...,
       [ 0.003539, ..., -0.004918]]), fun='cube', random_state=441365315, whiten=True)
__________________________________________________________fastica - 2.4s, 0.0min
________________________________________________________________________________
[Memory] Calling sklearn.decomposition.fastica_.fastica...
fastica(array([[ 0.002964, ...,  0.004765],
       ...,
       [ 0.003539, ..., -0.004918]]), fun='cube', random_state=1537364731, whiten=True)
__________________________________________________________fastica - 2.7s, 0.0min
________________________________________________________________________________
[Memory] Calling sklearn.decomposition.fastica_.fastica...
fastica(array([[ 0.002964, ...,  0.004765],
       ...,
       [ 0.003539, ..., -0.004918]]), fun='cube', random_state=192771779, whiten=True)
__________________________________________________________fastica - 2.2s, 0.0min
________________________________________________________________________________
[Memory] Calling sklearn.decomposition.fastica_.fastica...
fastica(array([[ 0.002964, ...,  0.004765],
       ...,
       [ 0.003539, ..., -0.004918]]), fun='cube', random_state=1491434855, whiten=True)
__________________________________________________________fastica - 4.6s, 0.1min
________________________________________________________________________________
[Memory] Calling sklearn.decomposition.fastica_.fastica...
fastica(array([[ 0.002964, ...,  0.004765],
       ...,
       [ 0.003539, ..., -0.004918]]), fun='cube', random_state=1819583497, whiten=True)
__________________________________________________________fastica - 5.2s, 0.1min
________________________________________________________________________________
[Memory] Calling sklearn.decomposition.fastica_.fastica...
fastica(array([[ 0.002964, ...,  0.004765],
       ...,
       [ 0.003539, ..., -0.004918]]), fun='cube', random_state=530702035, whiten=True)
__________________________________________________________fastica - 2.5s, 0.0min

8.4.1.3. To visualize we plot the outline of all components on one figure

from nilearn.plotting import plot_prob_atlas

# Plot all ICA components together
plot_prob_atlas(components_img, title='All ICA components')
../../_images/sphx_glr_plot_canica_resting_state_001.png

8.4.1.4. Finally, we plot the map for each ICA component separately

from nilearn.image import iter_img
from nilearn.plotting import plot_stat_map, show

for i, cur_img in enumerate(iter_img(components_img)):
    plot_stat_map(cur_img, display_mode="z", title="IC %d" % i,
                  cut_coords=1, colorbar=False)

show()
  • ../../_images/sphx_glr_plot_canica_resting_state_002.png
  • ../../_images/sphx_glr_plot_canica_resting_state_003.png
  • ../../_images/sphx_glr_plot_canica_resting_state_004.png
  • ../../_images/sphx_glr_plot_canica_resting_state_005.png
  • ../../_images/sphx_glr_plot_canica_resting_state_006.png
  • ../../_images/sphx_glr_plot_canica_resting_state_007.png
  • ../../_images/sphx_glr_plot_canica_resting_state_008.png
  • ../../_images/sphx_glr_plot_canica_resting_state_009.png
  • ../../_images/sphx_glr_plot_canica_resting_state_010.png
  • ../../_images/sphx_glr_plot_canica_resting_state_011.png
  • ../../_images/sphx_glr_plot_canica_resting_state_012.png
  • ../../_images/sphx_glr_plot_canica_resting_state_013.png
  • ../../_images/sphx_glr_plot_canica_resting_state_014.png
  • ../../_images/sphx_glr_plot_canica_resting_state_015.png
  • ../../_images/sphx_glr_plot_canica_resting_state_016.png
  • ../../_images/sphx_glr_plot_canica_resting_state_017.png
  • ../../_images/sphx_glr_plot_canica_resting_state_018.png
  • ../../_images/sphx_glr_plot_canica_resting_state_019.png
  • ../../_images/sphx_glr_plot_canica_resting_state_020.png
  • ../../_images/sphx_glr_plot_canica_resting_state_021.png

Total running time of the script: ( 57 minutes 49.217 seconds)

Generated by Sphinx-Gallery