NIPY logo

Site Navigation

NIPY Community

Table Of Contents

This Page

algorithms.statistics.models.model

Module: algorithms.statistics.models.model

Inheritance diagram for nipy.algorithms.statistics.models.model:

Classes

FContrastResults

class nipy.algorithms.statistics.models.model.FContrastResults(effect, covariance, F, df_num, df_den=None)

Bases: object

Results from looking at a particular contrast of coefficients in a parametric model. The class does nothing, it is a container for the results from F contrasts, and returns the F-statistics when np.asarray is called.

__init__(effect, covariance, F, df_num, df_den=None)

LikelihoodModel

class nipy.algorithms.statistics.models.model.LikelihoodModel

Bases: nipy.algorithms.statistics.models.model.Model

Methods

fit() Fit a model to data.
information(theta[, nuisance]) Fisher information matrix: the inverse of the expected value of
initialize() Initialize (possibly re-initialize) a Model instance. For
logL(theta, Y[, nuisance]) Log-likelihood of model.
predict([design]) After a model has been fit, results are (assumed to be) stored
score(theta, Y[, nuisance]) Score function of model = gradient of logL with respect to
__init__()
fit()

Fit a model to data.

information(theta, nuisance=None)

Fisher information matrix: the inverse of the expected value of - d^2 logL / dtheta^2.

initialize()

Initialize (possibly re-initialize) a Model instance. For instance, the design matrix of a linear model may change and some things must be recomputed.

logL(theta, Y, nuisance=None)

Log-likelihood of model.

predict(design=None)

After a model has been fit, results are (assumed to be) stored in self.results, which itself should have a predict method.

score(theta, Y, nuisance=None)

Score function of model = gradient of logL with respect to theta.

LikelihoodModelResults

class nipy.algorithms.statistics.models.model.LikelihoodModelResults(theta, Y, model, cov=None, dispersion=1.0, nuisance=None, rank=None)

Bases: object

Class to contain results from likelihood models

Methods

AIC() Akaike Information Criterion
BIC() Schwarz’s Bayesian Information Criterion
Fcontrast(matrix[, dispersion, invcov]) Compute an Fcontrast for a contrast matrix.
Tcontrast(matrix[, store, dispersion]) Compute a Tcontrast for a row vector matrix
conf_int([alpha, cols, dispersion]) Returns the confidence interval of the specified theta estimates.
logL() The maximized log-likelihood
t([column]) Return the (Wald) t-statistic for a given parameter estimate.
vcov([matrix, column, dispersion, other]) Variance/covariance matrix of linear contrast
__init__(theta, Y, model, cov=None, dispersion=1.0, nuisance=None, rank=None)

Set up results structure

Parameters :

theta : ndarray

parameter estimates from estimated model

Y : ndarray

data

model : LikelihoodModel instance

model used to generate fit

cov : None or ndarray, optional

covariance of thetas

dispersion : scalar, optional

multiplicative factor in front of cov

nuisance : None of ndarray

parameter estimates needed to compute logL

rank : None or scalar

rank of the model. If rank is not None, it is used for df_model instead of the usual counting of parameters.

Notes

The covariance of thetas is given by:

dispersion * cov

For (some subset of models) dispersion will typically be the mean square error from the estimated model (sigma^2)

static AIC()

Akaike Information Criterion

static BIC()

Schwarz’s Bayesian Information Criterion

Fcontrast(matrix, dispersion=None, invcov=None)

Compute an Fcontrast for a contrast matrix.

Here, matrix M is assumed to be non-singular. More precisely:

M pX pX' M'

is assumed invertible. Here, pX is the generalized inverse of the design matrix of the model. There can be problems in non-OLS models where the rank of the covariance of the noise is not full.

See the contrast module to see how to specify contrasts. In particular, the matrices from these contrasts will always be non-singular in the sense above.

Parameters :

matrix : 1D array-like

contrast matrix

dispersion : None or float

If None, use self.dispersion

invcov : None or array

Known inverse of variance covariance matrix. If None, calculate this matrix.

Returns :

f_res : FContrastResults instance

with attributes F, df_den, df_num

Tcontrast(matrix, store=('t', 'effect', 'sd'), dispersion=None)

Compute a Tcontrast for a row vector matrix

To get the t-statistic for a single column, use the ‘t’ method.

Parameters :

matrix : 1D array-like

contrast matrix

store : sequence

components of t to store in results output object. Defaults to all components (‘t’, ‘effect’, ‘sd’).

dispersion : float

Returns :

res : TContrastResults object

conf_int(alpha=0.05, cols=None, dispersion=None)

Returns the confidence interval of the specified theta estimates.

Parameters :

alpha : float, optional

The alpha level for the confidence interval. ie., alpha = .05 returns a 95% confidence interval.

cols : tuple, optional

cols specifies which confidence intervals to return

dispersion : None or scalar

scale factor for the variance / covariance (see class docstring and vcov method docstring)

Returns :

cis : ndarray

cis is shape (len(cols), 2) where each row contains [lower, upper] for the given entry in cols

Notes

Confidence intervals are two-tailed. TODO: tails : string, optional

tails can be “two”, “upper”, or “lower”
static logL()

The maximized log-likelihood

t(column=None)

Return the (Wald) t-statistic for a given parameter estimate.

Use Tcontrast for more complicated (Wald) t-statistics.

vcov(matrix=None, column=None, dispersion=None, other=None)

Variance/covariance matrix of linear contrast

Parameters :

matrix: array of shape (dim, self.theta.shape[0]), optional :

numerical contrast specification, where dim refers to the ‘dimension’ of the contrast i.e. 1 for t contrasts, 1 or more for F contrasts.

column: int, optional, :

alternative way of specifying contrasts (column index)

dispersion: float or array of shape (n_voxels), optional, :

value(s) for the dispersion parameters

other:array of shape (dim, self.theta.shape[0]), optional :

alternative contrast specification (?)

Returns :

cov: array of shape(dim, dim) or (n_voxels, dim, dim), :

the estimated covariance matrix/matrices

Returns the variance/covariance matrix of a linear contrast of the :

estimates of theta, multiplied by `dispersion` which will often be an :

estimate of `dispersion`, like, sigma^2. :

The covariance of interest is either specified as a (set of) column(s) :

or a matrix. :

Model

class nipy.algorithms.statistics.models.model.Model

Bases: object

A (predictive) statistical model. The class Model itself does nothing but lays out the methods expected of any subclass.

Methods

fit() Fit a model to data.
initialize() Initialize (possibly re-initialize) a Model instance. For
predict([design]) After a model has been fit, results are (assumed to be) stored
__init__()
fit()

Fit a model to data.

initialize()

Initialize (possibly re-initialize) a Model instance. For instance, the design matrix of a linear model may change and some things must be recomputed.

predict(design=None)

After a model has been fit, results are (assumed to be) stored in self.results, which itself should have a predict method.

TContrastResults

class nipy.algorithms.statistics.models.model.TContrastResults(t, sd, effect, df_den=None)

Bases: object

Results from looking at a particular contrast of coefficients in a parametric model. The class does nothing, it is a container for the results from T contrasts, and returns the T-statistics when np.asarray is called.

__init__(t, sd, effect, df_den=None)