This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the user guide for the big picture.


nilearn.interfaces.bids.save_glm_to_bids(model, contrasts, contrast_types=None, out_dir='.', prefix=None)[source]#

Save GLM results to BIDS-like files.

New in version 0.9.2dev.

modelFirstLevelModel or SecondLevelModel

First- or second-level model from which to save outputs.

contrastsstr or array of shape (n_col) or list of (str or array of shape (n_col)) or dict

Contrast definitions. This may be one of the following:

  • A string

  • A list of strings

  • A dictionary of contrast name: contrast weight key-value pairs. The contrast weights may be strings, lists, or arrays. Arrays may be 1D or 2D, with 1D arrays typically being t-contrasts and 2D arrays typically being F-contrasts.

contrast_typesNone or dict of str, optional

An optional dictionary mapping some or all of the contrast names to specific contrast types (‘t’ or ‘F’). If None, all contrast types will be automatically inferred based on the contrast arrays (1D arrays are t-contrasts, 2D arrays are F-contrasts). Keys in this dictionary must match the keys in the contrasts dictionary, but only those contrasts for which contrast type must be explicitly set need to be included. Default is None.

out_dirstr, optional

Output directory for files. Default is current working directory.

prefixstr or None, optional

String to prepend to generated filenames. If a string is provided, ‘_’ will be added to the end. Default is None.


This function writes files for the following:

  • Modeling software information (dataset_description.json)

  • Model-level metadata (statmap.json)

  • Model design matrix (design.tsv)

  • Model design matrix figure (design.svg)

  • Model error (stat-errorts_statmap.nii.gz)

  • Model r-squared (stat-rSquare_statmap.nii.gz)

  • Contrast ‘parameter estimates’ (contrast-[name]_stat-effect_statmap.nii.gz)

  • Variance of the contrast parameter estimates (contrast-[name]_stat-variance_statmap.nii.gz)

  • Contrast test statistics (contrast-[name]_stat-[F|t]_statmap.nii.gz)

  • Contrast p- and z-values (contrast-[name]_stat-[p|z]_statmap.nii.gz)

  • Contrast weights figure (contrast-[name]_design.svg)

Examples using nilearn.interfaces.bids.save_glm_to_bids#

First level analysis of a complete BIDS dataset from openneuro

First level analysis of a complete BIDS dataset from openneuro

First level analysis of a complete BIDS dataset from openneuro