NIPY logo

Site Navigation

NIPY Community

Table Of Contents

This Page

modalities.fmri.design

Module: modalities.fmri.design

Convenience functions for specifying a design in the GLM

Functions

nipy.modalities.fmri.design.event_design(event_spec, t, order=2, hrfs=[, glover])

Create a design matrix for a GLM analysis based on an event specification, evaluating it a sequence of time values. Each column in the design matrix will be convolved with each HRF in hrfs.

Parameters:

event_spec : np.recarray

A recarray having at least a field named ‘time’ signifying the event time, and all other fields will be treated as factors in an ANOVA-type model.

t : np.ndarray

An array of np.float values at which to evaluate the design. Common examples would be the acquisition times of an fMRI image.

order : int

The highest order interaction to be considered in constructing the contrast matrices.

hrfs : seq

A sequence of (symbolic) HRF that will be convolved with each event. If empty, glover is used.

nipy.modalities.fmri.design.fourier_basis(t, freq)

Create a design matrix with columns given by the Fourier basis with a given set of frequencies.

Parameters:

t : np.ndarray

An array of np.float values at which to evaluate the design. Common examples would be the acquisition times of an fMRI image.

freq : [float]

Frequencies for the terms in the Fourier basis.

Returns:

X : np.ndarray

Examples

>>> t = np.linspace(0,50,101)
>>> drift = fourier_basis(t, np.array([4,6,8]))
>>> drift.shape
(101, 6)
>>> 
nipy.modalities.fmri.design.natural_spline(t, knots=None, order=3, intercept=True)

Create a design matrix with columns given by a natural spline of a given order and a specified set of knots.

Parameters:

t : np.array

knots : None or sequence, optional

Sequence of float. Default None (same as empty list)

order : int, optional

Order of the spline. Defaults to a cubic (==3)

intercept : bool, optional

If True, include a constant function in the natural spline. Default is False

Returns:

X : np.ndarray

Examples

>>> t = np.linspace(0,50,101)
>>> drift = natural_spline(t, knots=[10,20,30,40])
>>> drift.shape
(101, 8)
>>> 
nipy.modalities.fmri.design.stack2designs(old_X, new_X, old_contrasts={}, new_contrasts={})

Add some columns to a design matrix that has contrasts matrices already specified, adding some possibly new contrasts as well.

This basically performs an np.hstack of old_X, new_X and makes sure the contrast matrices are dealt with accordingly.

If two contrasts have the same name, an exception is raised.

Parameters:

old_X : np.ndarray

A design matrix

new_X : np.ndarray

A second design matrix to be stacked with old_X

old_contrast : dict

Dictionary of contrasts in the old_X column space

new_contrasts : dict

Dictionary of contrasts in the new_X column space

nipy.modalities.fmri.design.stack_contrasts(contrasts, name, keys)

Create a new F-contrast matrix called ‘name’ based on a sequence of keys. The contrast is added to contrasts, in-place.

Parameters:

contrasts : dict

Dictionary of contrast matrices

name : str

Name of new contrast. Should not already be a key of contrasts.

keys : [str]

Keys of contrasts that are to be stacked.

nipy.modalities.fmri.design.stack_designs(*pairs)

Stack a sequence of design / contrast dictionary pairs. Uses multiple calls to stack2designs

Parameters:pairs : sequence filled with (np.ndarray, dict) or np.ndarray