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:110: 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:110: 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:110: 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:110: 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:110: 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:110: 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:110: 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:110: 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:110: 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:110: 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/image/image.py:939: UserWarning:

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


  0%|          | 0/21 [00:00<?, ?it/s]
  5%|▍         | 1/21 [00:05<01:40,  5.04s/it]
 10%|▉         | 2/21 [00:10<01:35,  5.03s/it]
 14%|█▍        | 3/21 [00:15<01:30,  5.03s/it]
 19%|█▉        | 4/21 [00:20<01:25,  5.03s/it]
 24%|██▍       | 5/21 [00:25<01:20,  5.04s/it]
 29%|██▊       | 6/21 [00:30<01:15,  5.03s/it]
 33%|███▎      | 7/21 [00:35<01:10,  5.03s/it]
 38%|███▊      | 8/21 [00:40<01:05,  5.03s/it]
 43%|████▎     | 9/21 [00:45<01:00,  5.03s/it]
 48%|████▊     | 10/21 [00:50<00:55,  5.02s/it]
 52%|█████▏    | 11/21 [00:55<00:49,  4.98s/it]
 57%|█████▋    | 12/21 [01:00<00:44,  4.94s/it]
 62%|██████▏   | 13/21 [01:04<00:39,  4.93s/it]
 67%|██████▋   | 14/21 [01:09<00:34,  4.92s/it]
 71%|███████▏  | 15/21 [01:14<00:29,  4.91s/it]
 76%|███████▌  | 16/21 [01:19<00:24,  4.90s/it]
 81%|████████  | 17/21 [01:24<00:19,  4.89s/it]
 86%|████████▌ | 18/21 [01:29<00:14,  4.89s/it]
 90%|█████████ | 19/21 [01:34<00:09,  4.88s/it]
 95%|█████████▌| 20/21 [01:39<00:04,  4.88s/it]
100%|██████████| 21/21 [01:43<00:00,  4.88s/it]
100%|██████████| 21/21 [01:43<00:00,  4.95s/it]

  0%|          | 0/21 [00:00<?, ?it/s]
  5%|▍         | 1/21 [00:05<01:40,  5.03s/it]
 10%|▉         | 2/21 [00:10<01:35,  5.04s/it]
 14%|█▍        | 3/21 [00:15<01:31,  5.07s/it]
 19%|█▉        | 4/21 [00:20<01:26,  5.07s/it]
 24%|██▍       | 5/21 [00:25<01:21,  5.08s/it]
 29%|██▊       | 6/21 [00:30<01:16,  5.08s/it]
 33%|███▎      | 7/21 [00:35<01:10,  5.06s/it]
 38%|███▊      | 8/21 [00:40<01:05,  5.05s/it]
 43%|████▎     | 9/21 [00:45<01:00,  5.05s/it]
 48%|████▊     | 10/21 [00:50<00:55,  5.05s/it]
 52%|█████▏    | 11/21 [00:55<00:50,  5.00s/it]
 57%|█████▋    | 12/21 [01:00<00:44,  4.96s/it]
 62%|██████▏   | 13/21 [01:05<00:39,  4.94s/it]
 67%|██████▋   | 14/21 [01:10<00:34,  4.93s/it]
 71%|███████▏  | 15/21 [01:15<00:29,  4.91s/it]
 76%|███████▌  | 16/21 [01:19<00:24,  4.90s/it]
 81%|████████  | 17/21 [01:24<00:19,  4.90s/it]
 86%|████████▌ | 18/21 [01:29<00:14,  4.90s/it]
 90%|█████████ | 19/21 [01:34<00:09,  4.90s/it]
 95%|█████████▌| 20/21 [01:39<00:04,  4.91s/it]
100%|██████████| 21/21 [01:44<00:00,  4.91s/it]
100%|██████████| 21/21 [01:44<00:00,  4.97s/it]
/home/docs/checkouts/readthedocs.org/user_builds/nimare/checkouts/stable/nimare/diagnostics.py:249: FutureWarning:

Downcasting object dtype arrays on .fillna, .ffill, .bfill is deprecated and will change in a future version. Call result.infer_objects(copy=False) instead. To opt-in to the future behavior, set `pd.set_option('future.no_silent_downcasting', True)`

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",
    symmetric_cbar=True,
    vmax=4,
)
plt.show()
12 plot ibma workflow
/home/docs/checkouts/readthedocs.org/user_builds/nimare/envs/stable/lib/python3.9/site-packages/nilearn/plotting/img_plotting.py:1317: 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.727896 904360
1 PositiveTail 1a 54.0 -30.0 20.0 16.225935
2 PositiveTail 1b 54.0 2.0 2.0 16.102255
3 PositiveTail 1c 42.0 12.0 -6.0 15.934701
4 PositiveTail 2 20.0 -4.0 -44.0 2.590588 168
5 PositiveTail 3 40.0 -22.0 -34.0 2.559119 128
6 NegativeTail 1 -4.0 36.0 -20.0 -9.575846 86424
7 NegativeTail 1a 2.0 30.0 -22.0 -9.067977
8 NegativeTail 1b -4.0 52.0 -14.0 -9.018521
9 NegativeTail 1c 2.0 50.0 -20.0 -8.987223
10 NegativeTail 2 -8.0 -56.0 8.0 -8.186770 23096
11 NegativeTail 2a 8.0 -54.0 8.0 -5.416190
12 NegativeTail 2b 22.0 -84.0 34.0 -4.269425
13 NegativeTail 2c 48.0 -66.0 22.0 -4.261751
14 NegativeTail 3 -24.0 -12.0 -28.0 -8.158261 11712
15 NegativeTail 3a -32.0 -36.0 -20.0 -7.760459
16 NegativeTail 4 20.0 -10.0 -28.0 -7.600538 13896
17 NegativeTail 4a 26.0 -42.0 -18.0 -6.367305
18 NegativeTail 4b 32.0 -46.0 -4.0 -4.253106
19 NegativeTail 4c 26.0 -40.0 6.0 -3.263061
20 NegativeTail 5 60.0 -4.0 22.0 -7.289905 15632
21 NegativeTail 5a 48.0 -24.0 52.0 -6.652910
22 NegativeTail 5b 52.0 -8.0 24.0 -6.155638
23 NegativeTail 5c 58.0 -10.0 34.0 -6.153455
24 NegativeTail 6 60.0 -6.0 -28.0 -7.025333 11504
25 NegativeTail 6a 58.0 -10.0 -12.0 -5.152494
26 NegativeTail 6b 66.0 -24.0 -2.0 -4.928535
27 NegativeTail 6c 56.0 2.0 -34.0 -4.724670
28 NegativeTail 7 -56.0 -14.0 -22.0 -6.962164 25576
29 NegativeTail 7a -52.0 12.0 -36.0 -6.561857
30 NegativeTail 7b -46.0 32.0 -18.0 -6.087229
31 NegativeTail 7c -54.0 -2.0 -30.0 -5.911299
32 NegativeTail 8 -50.0 -10.0 28.0 -6.674637 16112
33 NegativeTail 8a -44.0 -24.0 56.0 -5.776607
34 NegativeTail 8b -40.0 -22.0 64.0 -4.926554
35 NegativeTail 8c -36.0 -26.0 48.0 -4.258848
36 NegativeTail 9 -48.0 -66.0 26.0 -6.522043 8720
37 NegativeTail 9a -26.0 -80.0 38.0 -2.473196
38 NegativeTail 10 4.0 -28.0 60.0 -3.689675 1408
39 NegativeTail 10a -6.0 -26.0 58.0 -2.095735
40 NegativeTail 11 2.0 2.0 -14.0 -2.747405 232
41 NegativeTail 12 26.0 12.0 -34.0 -2.747010 184
42 NegativeTail 13 28.0 26.0 -24.0 -2.744970 296
43 NegativeTail 13a 34.0 32.0 -22.0 -2.692963
44 NegativeTail 14 -20.0 -84.0 24.0 -2.584229 352
45 NegativeTail 14a -12.0 -86.0 26.0 -1.992551
46 NegativeTail 15 26.0 -64.0 60.0 -2.574988 160


Contribution table

result.tables["z_corr-FDR_method-indep_diag-Jackknife_tab-counts"]
id PositiveTail 1 PositiveTail 2 PositiveTail 3 NegativeTail 1 NegativeTail 2 NegativeTail 3 NegativeTail 4 NegativeTail 5 NegativeTail 6 NegativeTail 7 NegativeTail 8 NegativeTail 9 NegativeTail 10 NegativeTail 11 NegativeTail 12 NegativeTail 13 NegativeTail 14 NegativeTail 15
0 pain_01.nidm-1 0.048408 0.020491 0.106404 -0.063035 0.030371 -0.023289 -0.004600 -0.108661 -0.054622 -0.067538 -0.074264 -0.019137 -0.165459 0.089236 0.136269 -0.193732 -0.260231 -0.158173
1 pain_02.nidm-1 0.046867 0.211019 0.072354 -0.084875 -0.100809 -0.088976 -0.074166 -0.142351 -0.128693 -0.073019 -0.166903 -0.050730 -0.230920 -0.095580 0.136257 -0.112527 -0.305218 -0.201329
2 pain_03.nidm-1 0.035032 0.007184 -0.053123 -0.085353 0.035409 0.004919 0.010427 0.044239 -0.071262 -0.097218 -0.091275 0.026263 0.008808 -0.182281 0.011699 -0.229043 0.122724 -0.205269
3 pain_04.nidm-1 -0.029973 0.059922 0.113370 -0.005871 0.118628 0.074437 0.071191 0.129127 0.018604 0.016468 0.037855 0.165820 0.104726 -0.015201 0.126604 -0.177685 0.290132 0.026571
4 pain_05.nidm-1 0.027823 0.006869 -0.043879 -0.008897 -0.042757 -0.041564 -0.029761 -0.095608 -0.012597 -0.017804 -0.039128 -0.097659 0.004344 0.102629 -0.097465 0.064178 0.054830 -0.082503
5 pain_06.nidm-1 0.059577 -0.034635 -0.082232 -0.055895 -0.143436 -0.059135 -0.044689 -0.130540 -0.040141 -0.102425 -0.100846 -0.191151 -0.216109 -0.103332 0.053000 -0.148706 -0.026357 -0.096896
6 pain_07.nidm-1 0.042981 -0.226729 0.079746 -0.044894 -0.201116 -0.097909 -0.117464 -0.089642 -0.030951 -0.055089 -0.105024 -0.132388 -0.251158 -0.161134 0.114070 0.056376 -0.392043 -0.123292
7 pain_08.nidm-1 -0.001439 -0.141758 -0.058071 0.118060 0.178546 0.091701 0.087691 0.163324 0.095751 0.112429 0.161967 0.079895 -0.014540 0.211969 0.296076 0.261512 0.443147 0.159761
8 pain_09.nidm-1 -0.001670 0.137914 0.035074 0.097932 0.116861 0.050135 0.052896 0.194203 0.130848 0.149614 0.204474 0.038590 0.070815 -0.210534 -0.035012 0.083798 0.482140 0.021481
9 pain_10.nidm-1 -0.009491 -0.013666 -0.013066 0.144815 0.200053 0.128388 0.090841 0.136146 0.217259 0.165065 0.140350 0.138574 0.061967 0.024859 0.180287 0.338779 0.344745 0.249837
10 pain_11.nidm-1 0.050209 -0.157341 0.003094 -0.018572 -0.059207 -0.004407 -0.009320 0.006234 -0.025536 0.008306 -0.024148 -0.084454 -0.179472 -0.017843 0.008984 0.006923 -0.075410 -0.111777
11 pain_12.nidm-1 0.045802 0.320863 0.136787 0.039717 0.108284 0.053605 0.084053 0.058709 0.111067 0.072152 0.054955 0.111389 0.261434 0.029808 0.026058 -0.097322 0.182604 0.070083
12 pain_13.nidm-1 0.008978 -0.080524 -0.125419 0.192404 0.288651 0.209062 0.150831 0.187010 0.261995 0.246758 0.276226 0.315231 0.376150 0.352954 0.219619 0.283307 0.303938 0.508716
13 pain_14.nidm-1 0.100589 0.007060 -0.120453 0.034940 -0.011941 0.023414 0.013583 0.114220 0.001348 -0.014478 0.077895 0.038213 0.259563 0.195938 -0.281085 0.099131 -0.089986 -0.123177
14 pain_15.nidm-1 0.024432 0.178330 0.159972 0.067260 0.091142 0.118340 0.148285 0.080301 0.066949 0.090322 0.048790 0.091596 0.074734 0.193475 0.025513 0.150392 -0.045594 0.379477
15 pain_16.nidm-1 0.015565 0.098348 0.164393 0.105421 0.080735 0.156438 0.172758 0.065900 0.111050 0.121459 0.064766 0.127453 0.197971 0.146537 0.026861 0.217728 -0.092446 0.342748
16 pain_17.nidm-1 0.054668 -0.004090 -0.019185 -0.034648 -0.053506 -0.038580 -0.052521 -0.069203 -0.041145 -0.022483 -0.097677 -0.065811 -0.169725 -0.085163 -0.092886 -0.154125 0.126587 -0.122357
17 pain_18.nidm-1 -0.028247 0.093018 0.034509 0.027531 0.038943 0.032683 0.049695 0.027628 -0.009999 0.027553 0.033818 -0.018983 -0.024178 -0.038260 -0.088628 0.068720 -0.018120 -0.008647
18 pain_19.nidm-1 0.007936 0.142541 0.122732 0.085559 0.134296 0.050829 0.076631 0.000239 0.059443 0.066296 0.141709 0.160326 0.300466 0.186608 0.096348 0.046350 0.027553 0.371440
19 pain_20.nidm-1 0.056486 0.103683 0.155570 -0.027225 -0.136570 -0.062792 -0.058356 -0.049960 -0.110252 -0.077551 -0.042995 -0.073121 -0.041682 -0.057013 -0.073200 -0.005562 -0.203009 -0.202151
20 pain_21.nidm-1 0.004577 -0.032945 -0.007016 0.096103 -0.033635 0.013567 -0.007545 0.072874 0.064855 0.053788 0.107033 0.054250 0.265790 0.125479 -0.102536 0.149500 -0.099993 0.053540


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/plotting/html_stat_map.py:198: 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/plotting/img_plotting.py:1317: UserWarning:

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

Total running time of the script: (4 minutes 35.747 seconds)

Gallery generated by Sphinx-Gallery