.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/07_advanced/plot_localizer_simple_analysis.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_auto_examples_07_advanced_plot_localizer_simple_analysis.py>`
        to download the full example code or to run this example in your browser via Binder

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_07_advanced_plot_localizer_simple_analysis.py:


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.

.. GENERATED FROM PYTHON SOURCE LINES 16-24

.. code-block:: default

    # Author: Virgile Fritsch, <virgile.fritsch@inria.fr>, May. 2014
    import numpy as np
    import matplotlib.pyplot as plt
    from nilearn import datasets
    from nilearn.maskers import NiftiMasker
    from nilearn.image import get_data









.. GENERATED FROM PYTHON SOURCE LINES 25-26

Load Localizer contrast

.. GENERATED FROM PYTHON SOURCE LINES 26-33

.. code-block:: default

    n_samples = 20
    localizer_dataset = datasets.fetch_localizer_calculation_task(
        n_subjects=n_samples, legacy_format=False
    )
    tested_var = np.ones((n_samples, 1))









.. GENERATED FROM PYTHON SOURCE LINES 34-35

Mask data

.. GENERATED FROM PYTHON SOURCE LINES 35-42

.. code-block:: default

    nifti_masker = NiftiMasker(
        smoothing_fwhm=5,
        memory='nilearn_cache', memory_level=1)  # cache options
    cmap_filenames = localizer_dataset.cmaps
    fmri_masked = nifti_masker.fit_transform(cmap_filenames)









.. GENERATED FROM PYTHON SOURCE LINES 43-44

Anova (parametric F-scores)

.. GENERATED FROM PYTHON SOURCE LINES 44-54

.. code-block:: default

    from sklearn.feature_selection import f_regression
    _, pvals_anova = f_regression(fmri_masked, tested_var,
                                  center=False)  # do not remove intercept
    pvals_anova *= fmri_masked.shape[1]
    pvals_anova[np.isnan(pvals_anova)] = 1
    pvals_anova[pvals_anova > 1] = 1
    neg_log_pvals_anova = - np.log10(pvals_anova)
    neg_log_pvals_anova_unmasked = nifti_masker.inverse_transform(
        neg_log_pvals_anova)





.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none

    /home/nicolas/GitRepos/scikit-learn-fork/sklearn/utils/validation.py:1095: 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().





.. GENERATED FROM PYTHON SOURCE LINES 55-56

Visualization

.. GENERATED FROM PYTHON SOURCE LINES 56-80

.. code-block:: default

    from nilearn.plotting import plot_stat_map, show

    # Various plotting parameters
    z_slice = 45  # plotted slice

    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=[z_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)'
             '\n%d detections' % (~masked_pvals.mask).sum())

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

    show()



.. image-sg:: /auto_examples/07_advanced/images/sphx_glr_plot_localizer_simple_analysis_001.png
   :alt: plot localizer simple analysis
   :srcset: /auto_examples/07_advanced/images/sphx_glr_plot_localizer_simple_analysis_001.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

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

**Estimated memory usage:**  9 MB


.. _sphx_glr_download_auto_examples_07_advanced_plot_localizer_simple_analysis.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example


  .. container:: binder-badge

    .. image:: images/binder_badge_logo.svg
      :target: https://mybinder.org/v2/gh/nilearn/nilearn.github.io/main?filepath=examples/auto_examples/07_advanced/plot_localizer_simple_analysis.ipynb
      :alt: Launch binder
      :width: 150 px


  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: plot_localizer_simple_analysis.py <plot_localizer_simple_analysis.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: plot_localizer_simple_analysis.ipynb <plot_localizer_simple_analysis.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_