Run an image-based meta-analysis (IBMA) workflow

NiMARE provides a plethora of tools for performing meta-analyses on neuroimaging data. Sometimes it’s difficult to know where to start, especially if you’re new to meta-analysis. This tutorial will walk you through using a IBMA workflow function which puts together the fundamental steps of a IBMA meta-analysis.

import os
from pathlib import Path

import matplotlib.pyplot as plt
from nilearn.plotting import plot_stat_map

from nimare.extract import download_nidm_pain

Download data

Load Dataset

from nimare.dataset import Dataset
from nimare.utils import get_resource_path

dset_file = os.path.join(get_resource_path(), "nidm_pain_dset.json")
dset = Dataset(dset_file)
dset.update_path(dset_dir)

Run IBMA Workflow

The fit method of a IBMA workflow class runs the following steps:

  1. Runs a meta-analysis using the specified method (default: Stouffers)

  2. Applies a corrector to the meta-analysis results (default: FDRCorrector, indep)

  3. Generates cluster tables and runs diagnostics on the corrected results (default: Jackknife)

All in one call!

from nimare.workflows.ibma import IBMAWorkflow

workflow = IBMAWorkflow()
result = workflow.fit(dset)
/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/maskers/nifti_masker.py:108: UserWarning:

imgs are being resampled to the mask_img resolution. This process is memory intensive. You might want to provide a target_affine that is equal to the affine of the imgs or resample the mask beforehand to save memory and computation time.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/maskers/nifti_masker.py:108: UserWarning:

imgs are being resampled to the mask_img resolution. This process is memory intensive. You might want to provide a target_affine that is equal to the affine of the imgs or resample the mask beforehand to save memory and computation time.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/maskers/nifti_masker.py:108: UserWarning:

imgs are being resampled to the mask_img resolution. This process is memory intensive. You might want to provide a target_affine that is equal to the affine of the imgs or resample the mask beforehand to save memory and computation time.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/maskers/nifti_masker.py:108: UserWarning:

imgs are being resampled to the mask_img resolution. This process is memory intensive. You might want to provide a target_affine that is equal to the affine of the imgs or resample the mask beforehand to save memory and computation time.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/maskers/nifti_masker.py:108: UserWarning:

imgs are being resampled to the mask_img resolution. This process is memory intensive. You might want to provide a target_affine that is equal to the affine of the imgs or resample the mask beforehand to save memory and computation time.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/maskers/nifti_masker.py:108: UserWarning:

imgs are being resampled to the mask_img resolution. This process is memory intensive. You might want to provide a target_affine that is equal to the affine of the imgs or resample the mask beforehand to save memory and computation time.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/maskers/nifti_masker.py:108: UserWarning:

imgs are being resampled to the mask_img resolution. This process is memory intensive. You might want to provide a target_affine that is equal to the affine of the imgs or resample the mask beforehand to save memory and computation time.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/maskers/nifti_masker.py:108: UserWarning:

imgs are being resampled to the mask_img resolution. This process is memory intensive. You might want to provide a target_affine that is equal to the affine of the imgs or resample the mask beforehand to save memory and computation time.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/maskers/nifti_masker.py:108: UserWarning:

imgs are being resampled to the mask_img resolution. This process is memory intensive. You might want to provide a target_affine that is equal to the affine of the imgs or resample the mask beforehand to save memory and computation time.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/maskers/nifti_masker.py:108: UserWarning:

imgs are being resampled to the mask_img resolution. This process is memory intensive. You might want to provide a target_affine that is equal to the affine of the imgs or resample the mask beforehand to save memory and computation time.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/_utils/niimg.py:61: UserWarning:

Non-finite values detected. These values will be replaced with zeros.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/reporting/_get_clusters_table.py:339: UserWarning:

Attention: No clusters with stat lower than -1.65


  0%|          | 0/21 [00:00<?, ?it/s]
  5%|▍         | 1/21 [00:04<01:37,  4.86s/it]
 10%|▉         | 2/21 [00:09<01:32,  4.89s/it]
 14%|█▍        | 3/21 [00:14<01:27,  4.86s/it]
 19%|█▉        | 4/21 [00:19<01:22,  4.85s/it]
 24%|██▍       | 5/21 [00:24<01:17,  4.83s/it]
 29%|██▊       | 6/21 [00:28<01:12,  4.81s/it]
 33%|███▎      | 7/21 [00:33<01:07,  4.80s/it]
 38%|███▊      | 8/21 [00:38<01:02,  4.81s/it]
 43%|████▎     | 9/21 [00:43<00:57,  4.82s/it]
 48%|████▊     | 10/21 [00:48<00:53,  4.83s/it]
 52%|█████▏    | 11/21 [00:53<00:47,  4.80s/it]
 57%|█████▋    | 12/21 [00:57<00:43,  4.79s/it]
 62%|██████▏   | 13/21 [01:02<00:38,  4.80s/it]
 67%|██████▋   | 14/21 [01:07<00:33,  4.77s/it]
 71%|███████▏  | 15/21 [01:12<00:28,  4.76s/it]
 76%|███████▌  | 16/21 [01:17<00:24,  4.81s/it]
 81%|████████  | 17/21 [01:21<00:19,  4.82s/it]
 86%|████████▌ | 18/21 [01:26<00:14,  4.81s/it]
 90%|█████████ | 19/21 [01:31<00:09,  4.80s/it]
 95%|█████████▌| 20/21 [01:36<00:04,  4.79s/it]
100%|██████████| 21/21 [01:40<00:00,  4.78s/it]
100%|██████████| 21/21 [01:40<00:00,  4.81s/it]

Plot Results

The fit method of the IBMA workflow class returns a MetaResult object, where you can access the corrected results of the meta-analysis and diagnostics tables.

Corrected map:

img = result.get_map("z_corr-FDR_method-indep")
plot_stat_map(
    img,
    cut_coords=4,
    display_mode="z",
    threshold=1.65,  # voxel_thresh p < .05, one-tailed
    cmap="RdBu_r",
    vmax=4,
)
plt.show()
12 plot ibma workflow
/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/_utils/niimg.py:61: UserWarning:

Non-finite values detected. These values will be replaced with zeros.

Clusters table

result.tables["z_corr-FDR_method-indep_tab-clust"]
Cluster ID X Y Z Peak Stat Cluster Size (mm3)
0 PositiveTail 1 36.0 2.0 6.0 16.769136 939424
1 PositiveTail 1a 54.0 -30.0 20.0 16.268434
2 PositiveTail 1b 54.0 2.0 2.0 16.145081
3 PositiveTail 1c 42.0 12.0 -6.0 15.977971
4 PositiveTail 2 20.0 -4.0 -44.0 2.762857 216
5 PositiveTail 3 40.0 -22.0 -34.0 2.732670 192
6 PositiveTail 4 -48.0 -30.0 -4.0 2.003478 88


Contribution table

result.tables["z_corr-FDR_method-indep_diag-Jackknife_tab-counts_tail-positive"]
id PositiveTail 1 PositiveTail 2 PositiveTail 3 PositiveTail 4
0 pain_01.nidm-1 0.044394 0.01868 0.074477 -0.026824
1 pain_02.nidm-1 0.043526 0.167249 0.052227 -0.040677
2 pain_03.nidm-1 0.032433 0.025998 -0.061257 0.081187
3 pain_04.nidm-1 -0.028653 0.02323 0.112011 -0.065503
4 pain_05.nidm-1 0.025724 0.025139 -0.043088 0.144395
5 pain_06.nidm-1 0.055553 -0.000242 -0.052256 0.387372
6 pain_07.nidm-1 0.04053 -0.18095 0.027047 0.21813
7 pain_08.nidm-1 -0.002606 -0.095769 -0.071068 0.056958
8 pain_09.nidm-1 -0.002566 0.084539 0.033037 -0.13354
9 pain_10.nidm-1 -0.010243 -0.012623 -0.054661 -0.314747
10 pain_11.nidm-1 0.046483 -0.096602 0.020545 0.082071
11 pain_12.nidm-1 0.041606 0.227346 0.124347 0.085361
12 pain_13.nidm-1 0.007327 -0.065216 -0.108369 -0.306596
13 pain_14.nidm-1 0.092277 0.041139 -0.115225 0.182585
14 pain_15.nidm-1 0.021191 0.103468 0.152658 0.11612
15 pain_16.nidm-1 0.013284 0.026708 0.148158 -0.013997
16 pain_17.nidm-1 0.050429 0.015772 -0.01307 0.187865
17 pain_18.nidm-1 -0.02677 0.06133 0.04667 -0.077445
18 pain_19.nidm-1 0.006546 0.07387 0.075034 -0.133254
19 pain_20.nidm-1 0.051845 0.079528 0.140477 0.212827
20 pain_21.nidm-1 0.003787 -0.016495 0.018407 -0.13619


Report

Finally, a NiMARE report is generated from the MetaResult.

from nimare.reports.base import run_reports

# root_dir = Path(os.getcwd()).parents[1] / "docs" / "_build"
# Use the previous root to run the documentation locally.
root_dir = Path(os.getcwd()).parents[1] / "_readthedocs"
html_dir = root_dir / "html" / "auto_examples" / "02_meta-analyses" / "12_plot_ibma_workflow"
html_dir.mkdir(parents=True, exist_ok=True)

run_reports(result, html_dir)
/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/_utils/niimg.py:61: UserWarning:

Non-finite values detected. These values will be replaced with zeros.

/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/_utils/niimg.py:61: UserWarning:

Non-finite values detected. These values will be replaced with zeros.

Total running time of the script: (2 minutes 58.126 seconds)

Gallery generated by Sphinx-Gallery