Giving credit

Previous topic

8.3.14. Reconstruction of visual stimuli from Miyawaki et al. 2008

Next topic

8.4.2. Extracting signals of a probabilistic atlas of rest functional regions

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)

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:

First functional nifti image (4D) is at: /home/parietal/gvaroqua/nilearn_data/adhd/data/0010042/0010042_rest_tshift_RPI_voreg_mni.nii.gz

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
components_img = canica.masker_.inverse_transform(canica.components_)
# 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/parietal/gvaroqua/nilearn_data/adhd/data/0010042/0010042_rest_tshift_RPI_voreg_mni.nii.gz, /home/parietal/gvaroqua/nilearn_data/adhd/data/0010064/0010064_rest_tshift_RPI_voreg_mni.nii.gz, /home
[MultiNiftiMasker.fit] Computing mask
[Memory]    0.0s, 0.0min: Loading compute_multi_epi_mask from nilearn_cache/joblib/nilearn/masking/compute_multi_epi_mask/5fbfad7b671960d38182e55a4cd9deaa
______________________________compute_multi_epi_mask cache loaded - 0.0s, 0.0min
[MultiNiftiMasker.transform] Resampling mask
[Memory]    0.1s, 0.0min: Loading resample_img from nilearn_cache/joblib/nilearn/image/resampling/resample_img/c36e2d55dadf84ca1f60c059653f9e08
________________________________________resample_img cache loaded - 0.1s, 0.0min
[Memory]    0.1s, 0.0min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/481c37a25838ece5d21141ab25c4318e
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]    2.3s, 0.0min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/7f177895a5d384dfba8b06038f738e39
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]    4.4s, 0.1min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/153fdfed3a941efa48c1ac91b26e1baa
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]    6.5s, 0.1min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/240581108de696edca7cfc244dacfdf4
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]    8.7s, 0.1min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/32d2f0e674eb070888e1cab3ce95d63f
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]    9.6s, 0.2min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/4fde6dfd02f343b2881b56a1fecb3076
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   10.5s, 0.2min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/519b7f0d182705a6875b4eb7ca3d7f0b
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   13.1s, 0.2min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/7af8193a5e91e4d6cb66d3ff96d374c2
_____________________________________filter_and_mask cache loaded - 0.2s, 0.0min
[Memory]   15.8s, 0.3min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/7590c0c32b1bd71ec3f543cfaa0e33d0
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   18.5s, 0.3min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/dfc1fd52866c998b0a828d1b995f2ba1
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   21.1s, 0.4min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/ccda84cb4b527e737a513ee45a7aa7d8
_____________________________________filter_and_mask cache loaded - 0.2s, 0.0min
[Memory]   23.2s, 0.4min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/a8e8b6933b8c81dfc9fc8cbf8a40f279
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   24.1s, 0.4min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/e42abb7e7374a2379d09904c5d7f6e6d
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   25.0s, 0.4min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/194c5246d55856f0befec943d771d1b3
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   27.4s, 0.5min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/6422b07dab2475febd1635d131f2946f
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   28.3s, 0.5min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/06ae8df115f07c88d84a12eae82b1837
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   30.6s, 0.5min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/495b111d20cda58953b88560ee8e55c2
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   31.5s, 0.5min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/d0b6b91febbec9672c37abab87ea28ea
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   33.2s, 0.6min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/7925dce1242f4f07bb9c65517b7405c0
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   35.2s, 0.6min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/6aa127a02a2c14168634f7b2eee4ef42
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   37.6s, 0.6min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/93ca911c912a5fe6be180e94b954479e
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   40.3s, 0.7min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/ab5c7bfc904101ccaacdf7d01026c46a
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   42.0s, 0.7min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/668dd25f72665d70979d660e5375289d
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   44.3s, 0.7min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/c0f8236b96afa346d8627b34284bc6c3
_____________________________________filter_and_mask cache loaded - 0.2s, 0.0min
[Memory]   46.8s, 0.8min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/43c2b5bb09852484dbb610b09f1768ef
_____________________________________filter_and_mask cache loaded - 0.3s, 0.0min
[Memory]   49.4s, 0.8min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/6776a811239bd1421c4805b18b184bdc
_____________________________________filter_and_mask cache loaded - 0.2s, 0.0min
[Memory]   51.5s, 0.9min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/98c46c404b652c01da148aee7fd35b7f
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]   53.3s, 0.9min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/3de7178604b4f0db99cccabd2cb58a82
_____________________________________filter_and_mask cache loaded - 0.2s, 0.0min
[Memory]   55.4s, 0.9min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/2eb602b05af3dd51b4b706aecbf1dd8b
_____________________________________filter_and_mask cache loaded - 0.2s, 0.0min
[Memory]   57.9s, 1.0min: Loading filter_and_mask from nilearn_cache/joblib/nilearn/input_data/nifti_masker/filter_and_mask/1445f34e598b07b3e8c94e553df979ee
_____________________________________filter_and_mask cache loaded - 0.1s, 0.0min
[Memory]    0.6s, 0.0min: Loading randomized_svd from nilearn_cache/joblib/sklearn/utils/extmath/randomized_svd/75349ef741325d4ea250323005a6cab5
______________________________________randomized_svd cache loaded - 0.1s, 0.0min
[Memory]    0.8s, 0.0min: Loading fastica from nilearn_cache/joblib/sklearn/decomposition/fastica_/fastica/a06a6c378526481ae9f72457f7b53c11
_____________________________________________fastica cache loaded - 0.1s, 0.0min
[Memory]    0.9s, 0.0min: Loading fastica from nilearn_cache/joblib/sklearn/decomposition/fastica_/fastica/3d1d169acf69014cb83ec2b05c200196
_____________________________________________fastica cache loaded - 0.1s, 0.0min
[Memory]    1.0s, 0.0min: Loading fastica from nilearn_cache/joblib/sklearn/decomposition/fastica_/fastica/3b5faa485433b249d99ac81ee8a02429
_____________________________________________fastica cache loaded - 0.2s, 0.0min
[Memory]    1.3s, 0.0min: Loading fastica from nilearn_cache/joblib/sklearn/decomposition/fastica_/fastica/8c3f66e80eb64e6491e078a50d01fe6f
_____________________________________________fastica cache loaded - 0.2s, 0.0min
[Memory]    1.5s, 0.0min: Loading fastica from nilearn_cache/joblib/sklearn/decomposition/fastica_/fastica/e10febf53a6c3db185cf667551fa2a4c
_____________________________________________fastica cache loaded - 0.1s, 0.0min
[Memory]    1.5s, 0.0min: Loading fastica from nilearn_cache/joblib/sklearn/decomposition/fastica_/fastica/fa944b88f8dea5732a16dedd3865d941
_____________________________________________fastica cache loaded - 0.1s, 0.0min
[Memory]    1.7s, 0.0min: Loading fastica from nilearn_cache/joblib/sklearn/decomposition/fastica_/fastica/bb7b2fcafac7804b0871d82970371393
_____________________________________________fastica cache loaded - 0.1s, 0.0min
[Memory]    1.8s, 0.0min: Loading fastica from nilearn_cache/joblib/sklearn/decomposition/fastica_/fastica/d63b569b231134ddc1324ded97dd5fd2
_____________________________________________fastica cache loaded - 0.0s, 0.0min
[Memory]    1.8s, 0.0min: Loading fastica from nilearn_cache/joblib/sklearn/decomposition/fastica_/fastica/00480cb8ce29ee6d955740554a340cfd
_____________________________________________fastica cache loaded - 0.1s, 0.0min
[Memory]    1.9s, 0.0min: Loading fastica from nilearn_cache/joblib/sklearn/decomposition/fastica_/fastica/99d919e30989096dd6d68600a5fb4256
_____________________________________________fastica cache loaded - 0.1s, 0.0min
[Memory]   62.3s, 1.0min: Loading unmask from nilearn_cache/joblib/nilearn/masking/unmask/f0fcd7fe6835513d316513717068cb07
______________________________________________unmask cache loaded - 0.2s, 0.0min

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

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: ( 1 minutes 24.211 seconds)

Generated by Sphinx-Gallery