spm1d.stats

Statistics module.

This module contains functions for conducting classical hypothesis testing on a set of 1D continua.

For all tests the dependent variable Y must be a NumPy array, with dimensions:

* J :  number of observations
* Q :  number of field nodes
* I :  number of vector components

Specifically:

  • Univariate 0D tests: Y should be ( J x 1 )

  • Multivariate 0D tests: Y should be ( J x I )

  • Univariate 1D tests: Y should be ( J x Q )

  • Multivariate 1D tests: Y should be ( J x Q x I )


anova1

spm1d.stats.anova1(Y, A=None, equal_var=False, roi=None)[source]

One-way ANOVA.

Parameters (Option 1):
  • Y — A list or tuple of (J x Q) numpy arrays

  • equal_var — If True, equal group variance will be assumed

Parameters (Option 2):
  • Y — (J x Q) numpy array

  • A — (J x 1) vector of integer group labels

  • equal_var — If True, equal group variance will be assumed

Returns:
  • F : An spm1d._spm.SPM_F instance

Example:

>>> F = spm1d.stats.anova1((Y0,Y1,Y2))
>>> Fi = F.inference(alpha=0.05)
>>> Fi.plot()

anova1rm

spm1d.stats.anova1rm(Y, A, SUBJ, equal_var=True, roi=None, _force_approx0D=False)[source]

One-way repeated-measures ANOVA.

Parameters:
  • Y — (J x Q) numpy array

  • A — (J x 1) vector of integer group labels

  • SUBJ — (J x 1) vector of subject labels

  • equal_var — If True, equal group variance will be assumed

Returns:
  • F : An spm1d._spm.SPM_F instance

Example:

>>> Y = np.random.randn(9, 101)
>>> A = np.array([1,1,1, 2,2,2, 3,3,3])
>>> SUBJ = np.array([1,2,3, 1,2,3, 1,2,3])
>>> F = spm1d.stats.anova1(Y, A, SUBJ)
>>> Fi = F.inference(alpha=0.05)
>>> Fi.plot()

anova2

spm1d.stats.anova2(Y, A, B, equal_var=True, roi=None)[source]

Two-way ANOVA.

Parameters:
  • Y — (J x Q) numpy array

  • A — (J x 1) vector of integer labels for Factor A

  • B — (J x 1) vector of integer labels for Factor B

  • equal_var — If True, equal group variance will be assumed

Returns:
  • List of three spm1d._spm.SPM_F instances in the following order:
    1. Main effect A

    2. Main effect B

    3. Interaction AB


anova2nested

spm1d.stats.anova2nested(Y, A, B, equal_var=True, roi=None)[source]

Two-way nested ANOVA.

Parameters:
  • Y — (J x Q) numpy array

  • A — (J x 1) vector of integer labels for Factor A

  • B — (J x 1) vector of integer labels for Factor B (nested in A)

  • equal_var — If True, equal group variance will be assumed

Returns:
  • List of two spm1d._spm.SPM_F instances in the following order:
    1. Main effect A

    2. Main effect B

Note:
  • there is no interaction term in nested designs.


anova2rm

spm1d.stats.anova2rm(Y, A, B, SUBJ, equal_var=True, roi=None, _force_approx0D=False)[source]

Two-way repeated-measures ANOVA.

Parameters:
  • Y — (J x Q) numpy array

  • A — (J x 1) vector of integer labels for Factor A

  • B — (J x 1) vector of integer labels for Factor B

  • SUBJ — (J x 1) vector of integer subject labels

  • equal_var — If True, equal group variance will be assumed

Returns:
  • List of three spm1d._spm.SPM_F instances in the following order:
    1. Main effect A

    2. Main effect B

    3. Interaction AB

Note:
  • Non-sphericity correction not implemented. Equal variance must be assumed by setting “equal_var=True”.


anova2onerm

spm1d.stats.anova2onerm(Y, A, B, SUBJ, equal_var=True, roi=None, _force_approx0D=False)[source]

Two-way ANOVA with repeated-measures on one factor.

Parameters:
  • Y — (J x Q) numpy array

  • A — (J x 1) vector of integer labels for Factor A

  • B — (J x 1) vector of integer labels for Factor B (the repeated-measures factor)

  • SUBJ — (J x 1) vector of integer subject labels

  • equal_var — If True, equal group variance will be assumed

Returns:
  • List of three spm1d._spm.SPM_F instances in the following order:
    1. Main effect A

    2. Main effect B

    3. Interaction AB

Note:
  • Non-sphericity correction not implemented. Equal variance must be assumed by setting “equal_var=True”.


anova3

spm1d.stats.anova3(Y, A, B, C, equal_var=True, roi=None)[source]

Three-way ANOVA.

Parameters:
  • Y — (J x Q) numpy array

  • A — (J x 1) vector of integer labels for Factor A

  • B — (J x 1) vector of integer labels for Factor B

  • C — (J x 1) vector of integer labels for Factor C

  • equal_var — If True, equal group variance will be assumed

Returns:
  • List of seven spm1d._spm.SPM_F instances in the following order:
    1. Main effect A

    2. Main effect B

    3. Main effect C

    4. Interaction AB

    5. Interaction AC

    6. Interaction BC

    7. Interaction ABC


anova3nested

spm1d.stats.anova3nested(Y, A, B, C, equal_var=True, roi=None)[source]

Three-way fully nested ANOVA.

Parameters:
  • Y — (J x Q) numpy array

  • A — (J x 1) vector of integer labels for Factor A

  • B — (J x 1) vector of integer labels for Factor B (nested in A)

  • C — (J x 1) vector of integer labels for Factor C (nested in B)

  • equal_var — If True, equal group variance will be assumed

Returns:
  • List of three spm1d._spm.SPM_F instances in the following order:
    1. Main effect A

    2. Main effect B

    3. Main effect C

Note:
  • there are no interaction terms in fully-nested designs.


anova3tworm

spm1d.stats.anova3tworm(Y, A, B, C, SUBJ, equal_var=True, roi=None, _force_approx0D=False)[source]

Three-way ANOVA with repeated-measures on two factors.

Parameters:
  • Y — (J x Q) numpy array

  • A — (J x 1) vector of integer labels for Factor A

  • B — (J x 1) vector of integer labels for Factor B (a repeated-measures factor)

  • C — (J x 1) vector of integer labels for Factor C (a repeated-measures factor)

  • SUBJ — (J x 1) vector of integer subject labels

  • equal_var — If True, equal group variance will be assumed

Returns:
  • List of seven spm1d._spm.SPM_F instances in the following order:
    1. Main effect A

    2. Main effect B

    3. Main effect C

    4. Interaction AB

    5. Interaction AC

    6. Interaction BC

    7. Interaction ABC

Note:
  • Non-sphericity correction not implemented. Equal variance must be assumed by setting “equal_var=True”.


anova3onerm

spm1d.stats.anova3onerm(Y, A, B, C, SUBJ, equal_var=True, roi=None, _force_approx0D=False)[source]

Three-way ANOVA with repeated-measures on one factor.

Parameters:
  • Y — (J x Q) numpy array

  • A — (J x 1) vector of integer labels for Factor A

  • B — (J x 1) vector of integer labels for Factor B

  • C — (J x 1) vector of integer labels for Factor C (the repeated-measures factor)

  • SUBJ — (J x 1) vector of integer subject labels

  • equal_var — If True, equal group variance will be assumed

Returns:
  • List of seven spm1d._spm.SPM_F instances in the following order:
    1. Main effect A

    2. Main effect B

    3. Main effect C

    4. Interaction AB

    5. Interaction AC

    6. Interaction BC

    7. Interaction ABC

Note:
  • Non-sphericity correction not implemented. Equal variance must be assumed by setting “equal_var=True”.


cca

spm1d.stats.cca(Y, x, roi=None)[source]

Canonical correlation analysis (CCA).

Parameters:
  • Y — A list or tuple of (J x Q) numpy arrays

  • x — (J x 1) list or array (independent variable)

Returns:
  • X2 : An spm1d._spm.SPM_X2 instance

Note:
  • Currently only a univariate 0D independent variable (x) is supported.


hotellings

spm1d.stats.hotellings(Y, mu=None, roi=None)[source]

One-sample Hotelling’s T2 test.

Parameters:
  • Y — (J x Q x I) numpy array

  • mu — scalar or (Q x I) array (datum)

Returns:
  • T2 : An spm1d._spm.SPM_T2 instance


hotellings_paired

spm1d.stats.hotellings_paired(YA, YB, roi=None)[source]

Paired Hotelling’s T2 test.

Parameters:
  • YA — (J x Q x I) numpy array

  • YB — (J x Q x I) numpy array

Returns:
  • T2 : An spm1d._spm.SPM_T2 instance

Note:
  • A paired Hotelling’s test on (YA,YB) is equivalent to a one-sample Hotelling’s test on (YB-YA)


hotellings2

spm1d.stats.hotellings2(YA, YB, equal_var=True, roi=None)[source]

Two-sample Hotelling’s T2 test.

Parameters:
  • YA — (J x Q x I) numpy array

  • YB — (J x Q x I) numpy array

Returns:
  • T2 : An spm1d._spm.SPM_T2 instance

Note:
  • Non-sphericity correction not implemented. Equal variance must be assumed by setting “equal_var=True”.


glm

spm1d.stats.glm(Y, X, c, Q=None, roi=None)[source]

General linear model (for t contrasts).

Parameters:

  • Y — (J x Q) numpy array (dependent variable)

  • X — (J x B) design matrix (J responses, B parameters)

  • c — B-component contrast vector (list or array)

  • Q — non-sphericity specifiers (not currently supported for glm)

Note

Non-sphericity estimates are not supported for spm1d.stats.glm

Returns:

  • An spm1d._spm.SPM_T object.

Example:

>>> t  = spm1d.stats.glm(Y, X, (-1,1))
>>> ti = t.inference(alpha=0.05, two_tailed=True)
>>> ti.plot()

manova1

spm1d.stats.manova1(Y, A, equal_var=True, roi=None)[source]

Two-way repeated-measures ANOVA.

Parameters:
  • Y — (J x Q x I) numpy array

  • A — (J x 1) vector of integer labels for Factor A

  • equal_var — If True, equal group variance will be assumed

Returns:
  • X2 : An spm1d._spm.SPM_X2 instance

Note:
  • Non-sphericity correction not implemented. Equal variance must be assumed by setting “equal_var=True”.


regress

spm1d.stats.regress(Y, x, roi=None)[source]

Simple linear regression.

Parameters:

  • Y — (J x Q) numpy array (dependent variable)

  • x — J-component list or array (independent variable)

Returns:

  • An spm1d._spm.SPM_T object.

Example:

>>> Y  = np.random.rand(10, 101)
>>> Y  = spm1d.util.smooth(Y, fwhm=10)
>>> x  = np.random.rand(10)
>>> t  = spm1d.stats.regress(Y, x)
>>> ti = t.inference(alpha=0.05)
>>> ti.plot()
Notes:
  • the correlation coefficient is retrievable as “t.r” where “t” is the output from spm1d.stats.regress

  • statistical inferences are based on t, not on r


ttest

spm1d.stats.ttest(Y, y0=None, roi=None)[source]

One-sample t test.

Parameters:

  • Y — (J x Q) data array (J responses, Q nodes)

  • y0 — optional Q-component datum array (default is the null continuum)

Returns:

  • An spm1d._spm.SPM_T object.

Example:

>>> Y  = np.random.randn(8, 101)
>>> Y  = spm1d.util.smooth(Y, fwhm=15)
>>> t  = spm1d.stats.ttest(Y)
>>> ti = t.inference(alpha=0.05, two_tailed=True)
>>> ti.plot()

ttest_paired

spm1d.stats.ttest_paired(YA, YB, roi=None)[source]

Paired t test.

Parameters:

  • YA — (J x Q) data array (J responses, Q nodes)

  • YB — (J x Q) data array (J responses, Q nodes)

Returns:

  • An spm1d._spm.SPM_T object.

Example:

>>> YA,YB  = np.random.randn(8, 101), np.random.randn(8, 101)
>>> YA,YB  = spm1d.util.smooth(Y, fwhm=10), spm1d.util.smooth(Y, fwhm=10)
>>> t      = spm1d.stats.ttest_paired(YA, YB)
>>> ti = t.inference(alpha=0.05)
>>> ti.plot()

ttest2

spm1d.stats.ttest2(YA, YB, equal_var=False, roi=None)[source]

Two-sample t test.

Parameters:

  • YA — (J x Q) data array (J responses, Q nodes)

  • YB — (J x Q) data array (J responses, Q nodes)

  • equal_var — If True, equal group variance will be assumed

Returns:

  • An spm1d._spm.SPM_T object.

Example:

>>> YA,YB  = np.random.randn(8, 101), np.random.randn(8, 101)
>>> YA,YB  = spm1d.util.smooth(Y, fwhm=10), spm1d.util.smooth(Y, fwhm=10)
>>> t  = spm1d.stats.ttest2(YA, YB)
>>> ti = t.inference(alpha=0.05)
>>> ti.plot()