NIPY logo

Site Navigation

NIPY Community

Github repo

Table Of Contents

Previous topic

modalities.fmri.fmristat.outputters

This Page

modalities.fmri.glm

Module: modalities.fmri.glm

Inheritance diagram for nipy.modalities.fmri.glm:

This module presents an interface to use the glm implemented in nipy.algorithms.statistics.models.regression It contains the GLM and contrast classes that are meant to be the main objects of fMRI data analyses.

It is important to note that the GLM is meant as a one-session General Linear Model. But inference can be performed on multiple sessions by computing fixed effects on contrasts

>>> from nipy.modalities.fmri.glm import GeneralLinearModel
>>> import numpy as np
>>> n, p, q = 100, 80, 10
>>> X, Y = np.random.randn(p, q), np.random.randn(p, n)
>>> cval = np.hstack((1, np.zeros(9)))
>>> model = GeneralLinearModel(X)
>>> model.fit(Y)
>>> z_vals = model.contrast(cval).z_score() # z-transformed statistics
>>> # example of fixed effects statistics across two contrasts
>>> cval_ = cval.copy()
>>> np.random.shuffle(cval_)
>>> z_ffx = (model.contrast(cval) + model.contrast(cval_)).z_score()

Classes

Contrast

class nipy.modalities.fmri.glm.Contrast(effect, variance, dof=10000000000.0, contrast_type='t', tiny=1e-50, dofmax=10000000000.0)

Bases: object

The contrast class handles the estimation of statistical contrasts After application of the GLM. The important feature is that it supports addition, thus opening the possibility of fixed-effects models.

The current implementation is meant to be simple, and could be enhanced in the future on the computational side (high-dimensional F constrasts may lead to memory breakage)

Methods

p_value([baseline]) Return a parametric estimate of the p-value associated
stat([baseline]) Return the decision statistic associated with the test of the
z_score([baseline]) Return a parametric estimation of the z-score associated
__init__(effect, variance, dof=10000000000.0, contrast_type='t', tiny=1e-50, dofmax=10000000000.0)
Parameters :

effect: array of shape (contrast_dim, n_voxels) :

the effects related to the contrast

variance: array of shape (contrast_dim, contrast_dim, n_voxels) :

the associated variance estimate

dof: scalar, the degrees of freedom :

contrast_type: string to be chosen among ‘t’ and ‘F’ :

p_value(baseline=0.0)

Return a parametric estimate of the p-value associated with the null hypothesis: (H0) ‘contrast equals baseline’

Parameters :

baseline: float, optional, :

Baseline value for the test statistic :

stat(baseline=0.0)

Return the decision statistic associated with the test of the null hypothesis: (H0) ‘contrast equals baseline’

Parameters :

baseline: float, optional, :

Baseline value for the test statistic

z_score(baseline=0.0)

Return a parametric estimation of the z-score associated with the null hypothesis: (H0) ‘contrast equals baseline’

Parameters :

baseline: float, optional, :

Baseline value for the test statistic

GeneralLinearModel

class nipy.modalities.fmri.glm.GeneralLinearModel(X)

Bases: object

This class handles the so-called on General Linear Model

Most of what it does in the fit() and contrast() methods fit() performs the standard two-step (‘ols’ then ‘ar1’) GLM fitting contrast() returns a contrast instance, yileding statistics and p-values. The link between fit() and constrast is done vis the two class members: glm_results: dictionary of nipy.algorithms.statistics.models. regression.RegressionResults instances,

describing results of a GLM fit
labels: array of shape(n_voxels),
labels that associate each voxel with a results key

Methods

contrast(con_val[, contrast_type]) Specify and estimate a linear contrast
fit(Y[, model, steps]) GLM fitting of a dataset using ‘ols’ regression or the two-pass
__init__(X)
Parameters :

X: array of shape(n_time_points, n_regressors), :

the design matrix

contrast(con_val, contrast_type=None)

Specify and estimate a linear contrast

Parameters :

con_val: numpy.ndarray of shape (p) or (q, p), :

where q = number of contrast vectors and p = number of regressors

contrast_type: string, optional, either ‘t’ or ‘F’, :

type of the contrast

Returns :

con: Contrast instance :

fit(Y, model='ar1', steps=100)

GLM fitting of a dataset using ‘ols’ regression or the two-pass

Parameters :

Y: array of shape(n_time_points, n_samples), the fMRI data :

model: string, to be chosen in [‘ar1’, ‘ols’], optional, :

the temporal variance model. Defaults to ‘ar1’

steps: int, optional, :

Maximum number of discrete steps for the AR(1) coef histogram

Function

nipy.modalities.fmri.glm.data_scaling(Y)

Scaling of the data to have pourcent of baseline change columnwise

Parameters :

Y: array of shape(n_time_points, n_voxels) :

the input data

Returns :

Y: array of shape(n_time_points, n_voxels), :

the data after mean-scaling, de-meaning and multiplication by 100

mean: array of shape(n_voxels), the data mean :