.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_meta-analyses/07_macm.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_02_meta-analyses_07_macm.py: .. _metas_macm: ============================================ Meta-analytic coactivation modeling analysis ============================================ Perform a MACM analysis with Neurosynth data. Meta-analytic coactivation modeling (MACM) is a common coordinate-based analysis in which task-independent "connectivity" is assessed by selecting studies within a larger database based on locations of report coordinates. .. GENERATED FROM PYTHON SOURCE LINES 15-25 .. code-block:: Python import nibabel as nib import numpy as np from nilearn import datasets, image, plotting from nimare.correct import FWECorrector from nimare.meta.cbma.ale import SCALE from nimare.meta.cbma.mkda import MKDAChi2 from nimare.nimads import Studyset .. GENERATED FROM PYTHON SOURCE LINES 26-30 Load dataset and create Studysets ----------------------------------------------------------------------------- We will assume that the Neurosynth database has already been downloaded and saved as a NiMARE Studyset. .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python studyset_file = "neurosynth_studyset_with_abstracts.json" studyset = Studyset(studyset_file, target="mni152_2mm") .. GENERATED FROM PYTHON SOURCE LINES 34-37 Define a region of interest ----------------------------------------------------------------------------- We'll use the right amygdala from the Harvard-Oxford atlas .. GENERATED FROM PYTHON SOURCE LINES 37-45 .. code-block:: Python atlas = datasets.fetch_atlas_harvard_oxford("sub-maxprob-thr50-2mm") img = atlas["maps"] roi_idx = atlas["labels"].index("Right Amygdala") img_vals = np.unique(img.get_fdata()) roi_val = img_vals[roi_idx] roi_img = image.math_img(f"img1 == {roi_val}", img1=img) .. GENERATED FROM PYTHON SOURCE LINES 46-48 Select studies with a reported coordinate in the ROI ----------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 48-54 .. code-block:: Python roi_ids = studyset.get_studies_by_mask(roi_img) studyset_sel = studyset.slice(roi_ids) print( f"{len(roi_ids)}/{len(studyset.ids)} studies report at least one coordinate in the ROI" ) .. GENERATED FROM PYTHON SOURCE LINES 55-57 Select studies with *no* reported coordinates in the ROI ----------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 57-64 .. code-block:: Python no_roi_ids = list(set(studyset.ids).difference(roi_ids)) studyset_unsel = studyset.slice(no_roi_ids) print( f"{len(no_roi_ids)}/{len(studyset.ids)} studies report zero coordinates in the ROI" ) .. GENERATED FROM PYTHON SOURCE LINES 65-67 MKDA Chi2 with FWE correction ----------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 67-82 .. code-block:: Python mkda = MKDAChi2(kernel__r=10) results = mkda.fit(studyset_sel, studyset_unsel) corr = FWECorrector(method="montecarlo", n_iters=10000) cres = corr.transform(results) # We want the "association" map (2-way chi-square between sel and unsel) plotting.plot_stat_map( cres.get_map("z_desc-uniformity_level-voxel_corr-FWE_method-montecarlo"), threshold=3.09, draw_cross=False, cmap="RdBu_r", symmetric_cbar=True, ) .. GENERATED FROM PYTHON SOURCE LINES 83-89 SCALE ----------------------------------------------------------------------------- Another good option for a MACM analysis is the SCALE algorithm, which was designed specifically for MACM. NiMARE supports voxel-level Monte Carlo FWE correction for SCALE, but not cluster-level correction. .. GENERATED FROM PYTHON SOURCE LINES 89-103 .. code-block:: Python # First, we must define our null model of reported coordinates in the literature. # We will use the coordinates in Neurosynth xyz = studyset.coordinates[["x", "y", "z"]].values scale = SCALE(xyz=xyz, n_iters=10000, n_cores=1, kernel__n=20) results = scale.fit(studyset_sel) corr = FWECorrector(method="montecarlo", n_iters=10000, n_cores=1) cres = corr.transform(results) plotting.plot_stat_map( cres.get_map("z_level-voxel_corr-FWE_method-montecarlo"), draw_cross=False, cmap="RdBu_r", symmetric_cbar=True, ) .. _sphx_glr_download_auto_examples_02_meta-analyses_07_macm.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 07_macm.ipynb <07_macm.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 07_macm.py <07_macm.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 07_macm.zip <07_macm.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_