Massively univariate analysis of a calculation task from the Localizer dataset

This example shows how to use the Localizer dataset in a basic analysis. A standard Anova is performed (massively univariate F-test) and the resulting Bonferroni-corrected p-values are plotted. We use a calculation task and 20 subjects out of the 94 available.

The Localizer dataset contains many contrasts and subject-related variates. The user can refer to the plot_localizer_mass_univariate_methods.py example to see how to use these.

Note

If you are using Nilearn with a version older than 0.9.0, then you should either upgrade your version or import maskers from the input_data module instead of the maskers module.

That is, you should manually replace in the following example all occurrences of:

from nilearn.maskers import NiftiMasker

with:

from nilearn.input_data import NiftiMasker
from nilearn._utils.helpers import check_matplotlib

check_matplotlib()

import matplotlib.pyplot as plt
import numpy as np

from nilearn import datasets
from nilearn.image import get_data
from nilearn.maskers import NiftiMasker

Load Localizer contrast

[get_dataset_dir] Dataset found in /home/remi/nilearn_data/brainomics_localizer

Mask data

nifti_masker = NiftiMasker(
    smoothing_fwhm=5, memory="nilearn_cache", memory_level=1
)
cmap_filenames = localizer_dataset.cmaps
fmri_masked = nifti_masker.fit_transform(cmap_filenames)

Anova (parametric F-scores)

/home/remi/github/nilearn/nilearn_doc_build/.tox/doc/lib/python3.9/site-packages/sklearn/utils/validation.py:1229: DataConversionWarning:

A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().

Visualization

from nilearn.plotting import plot_stat_map, show

# Various plotting parameters
plotted_slice = 45
threshold = -np.log10(0.1)  # 10% corrected

# Plot Anova p-values
fig = plt.figure(figsize=(5, 6), facecolor="w")
display = plot_stat_map(
    neg_log_pvals_anova_unmasked,
    threshold=threshold,
    display_mode="z",
    cut_coords=[plotted_slice],
    figure=fig,
)

masked_pvals = np.ma.masked_less(
    get_data(neg_log_pvals_anova_unmasked), threshold
)

title = (
    "Negative $\\log_{10}$ p-values"
    "\n(Parametric + Bonferroni correction)"
    f"\n{(~masked_pvals.mask).sum()} detections"
)

display.title(title, y=1, alpha=0.8)

show()
plot localizer simple analysis
/home/remi/github/nilearn/nilearn_doc_build/.tox/doc/lib/python3.9/site-packages/nilearn/plotting/displays/_slicers.py:1523: MatplotlibDeprecationWarning:

Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.

Total running time of the script: (0 minutes 4.014 seconds)

Estimated memory usage: 193 MB

Gallery generated by Sphinx-Gallery