Multivariate procedures#

Multivariate data should be arranged as (J, I) arrays for 0D data or (J, Q, I) arrays for 1D data, where J is the number of observations, Q the number of domain nodes and I the number of vector components. Effects tested using Wilks’ Λ (i.e., MANOVA, MANCOVA and CCA effects) are reported as Rao’s F statistic. Refer to Multivariate tests for details.

Hotelling’s T²#


hotellings(y, mu=None, roi=None)[source]#

One-sample Hotelling’s T2 test.

Parameters:

  • y — (J,I) array for 0D data or (J,Q,I) array for 1D data

  • mu — Datum as a scalar or (I,) array for 0D data or a scalar or (Q,I) array for 1D data (default zero)

  • roi — DEPRECATED (use inference)

Dimensions:
  • J — number of observations

  • Q — number of domain nodes (1D data)

  • I — number of vector components

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the setosa flowers of the “iris” dataset from R (50 observations and four components).

>>> import spm1d
>>> import jikudata as jd
>>> y    = jd.R_IrisSetosa().y  # (50,4) array
>>> mu   = [5.0, 3.4, 1.5, 0.2]
>>> spmi = spm1d.stats.hotellings( y, mu ).inference( 0.05 )
>>> print( spmi )
SPM{T2} (0D) inference
    fn_name : hotellings
    STAT    : T2
    z       : 17.17196
    df      : (4, 49)
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    zc           : 10.96763
    h0reject     : True
    p            : 0.00695

The example datasets require the jiku-data package: pip install "spm1d[data]".

hotellings_paired(y0, y1, roi=None)[source]#

Paired Hotelling’s T2 test.

Parameters:

  • y0 — Condition A data as a (J,I) array for 0D data or a (J,Q,I) array for 1D data

  • y1 — Condition B data as a (J,I) array for 0D data or a (J,Q,I) array for 1D data. Rows must match condition A.

  • roi — DEPRECATED (use inference)

Dimensions:
  • J — number of observations

  • Q — number of domain nodes (1D data)

  • I — number of vector components

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses a generated paired dataset (20 pairs and three components).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.Gen0D_hotellings_paired()
>>> y, A    = dataset.y, dataset.x  # (40,3) array and (40,) array
>>> y0, y1  = y[ A == 0 ], y[ A == 1 ]  # same participants in the same order
>>> spmi    = spm1d.stats.hotellings_paired( y0, y1 ).inference( 0.05 )
>>> print( spmi )
SPM{T2} (0D) inference
    fn_name : hotellings_paired
    STAT    : T2
    z       : 8.15846
    df      : (3, 19)
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    zc           : 10.71860
    h0reject     : False
    p            : 0.10040

The 1D example uses center-of-pressure trajectories from Pataky et al. (2014) (ten participants, two conditions and two components).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.Pataky2014cop()
>>> y, A    = dataset.y, dataset.x  # (20,101,2) array and (20,) array
>>> y0, y1  = y[ A == 0 ], y[ A == 1 ]
>>> spmi    = spm1d.stats.hotellings_paired( y0, y1 ).inference( 0.05 )
>>> print( spmi.h0reject )
True
>>> spmi.plot()
>>> plt.show()

The example datasets require the jiku-data package: pip install "spm1d[data]".

hotellings2(y0, y1, cov_model='iid', roi=None, equal_var=None)[source]#

Two-sample Hotelling’s T2 test.

Parameters:

  • y0 — Group A data as a (J0,I) array for 0D data or a (J0,Q,I) array for 1D data

  • y1 — Group B data as a (J1,I) array for 0D data or a (J1,Q,I) array for 1D data.

  • roi — DEPRECATED (use inference)

  • cov_model — iid only (the default)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

  • Q — number of domain nodes (1D data)

  • I — number of vector components

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the “crabs” dataset from the R package MASS (two groups of 100 and five components).

>>> import spm1d
>>> import jikudata as jd
>>> import warnings
>>> warnings.filterwarnings( "ignore", category=spm1d.exceptions.SPM1DDimensionWarning )
>>> dataset = jd.MASS_Crabs()
>>> y, A    = dataset.y, dataset.x  # (200,5) array and (200,) array
>>> y0, y1  = y[ A == 0 ], y[ A == 1 ]
>>> spmi    = spm1d.stats.hotellings2( y0, y1 ).inference( 0.05 )
>>> print( spmi )
SPM{T2} (0D) inference
    fn_name : hotellings2
    STAT    : T2
    z       : 1363.65777
    df      : (5, 198)
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    zc           : 11.53629
    h0reject     : True
    p            : <0.00001

The 1D example uses joint angles during walking from Fukuchi et al. (2018) (two groups and three components).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.Fukuchi2018walking()
>>> y, A    = dataset.y, dataset.x  # (51,101,3) array and (51,) array
>>> y0, y1  = y[ A == 0 ], y[ A == 1 ]
>>> spmi    = spm1d.stats.hotellings2( y0, y1 ).inference( 0.05 )
>>> print( spmi.h0reject )
False
>>> spmi.plot()
>>> plt.show()

The example datasets require the jiku-data package: pip install "spm1d[data]".

Note:

  • Covariance is pooled across samples. Requires cov_model='iid'.

  • Post hoc component tests and loadings are signed first minus second (y0 - y1).

MANOVA#


manova1(y, A, cov_model='iid', roi=None, equal_var=None)[source]#

One-way multivariate analysis of variance.

Parameters:

  • y — (J,I) array for 0D data or (J,Q,I) array for 1D data

  • A — (J,) array of integer group labels

  • cov_model — iid only

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

  • Q — number of domain nodes (1D data)

  • I — number of vector components

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the “iris” dataset from R (three groups and four components).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.R_Iris()
>>> y, A    = dataset.y, dataset.x  # (150,4) array and (150,) array
>>> spmi    = spm1d.stats.manova1( y, A ).inference( 0.05 )
>>> print( spmi )
SPM{F} (Wilks' Λ) (0D) inference
    fn_name : manova1
    STAT    : F
    z       : 199.14534
    df      : (8, 288)
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    zc           : 1.97062
    h0reject     : True
    p            : <0.00001

The 1D example uses ground reaction force vectors from Dorn et al. (2012) (four speeds and three components).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.Dorn2012manova()
>>> y, A    = dataset.y, dataset.x  # (8,100,3) array and (8,) array
>>> spmi    = spm1d.stats.manova1( y, A ).inference( 0.05 )
>>> print( spmi.h0reject )
True
>>> spmi.plot()
>>> plt.show()

The example datasets require the jiku-data package: pip install "spm1d[data]".

Note:

  • Statistic: Wilks’ lambda transformed to Rao’s F (available as spm.fit.wilks).

manova2(y, A, B, cov_model='iid', roi=None, equal_var=None)[source]#

Two-way multivariate analysis of variance.

Parameters:

  • y — (J,I) array for 0D data or (J,Q,I) array for 1D data

  • A — (J,) array of integer labels for factor A

  • B — (J,) array of integer labels for factor B

  • cov_model — iid only

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

  • Q — number of domain nodes (1D data)

  • I — number of vector components

Returns:

  • SPMList object

Example:

The 0D example uses the “crabs” dataset from the R package MASS (2 x 2 design with five components).

>>> import spm1d
>>> import jikudata as jd
>>> import warnings
>>> warnings.filterwarnings( "ignore", category=spm1d.exceptions.SPM1DDimensionWarning )
>>> dataset = jd.MASS_CrabsTwoWay()
>>> y       = dataset.y     # (200,5) array
>>> A, B    = dataset.x.T   # (200,) arrays of factor labels
>>> spmi    = spm1d.stats.manova2( y, A, B ).inference( 0.05 )
>>> print( spmi )
SPMiList
    STAT     : F (Wilks' Λ)
    fn_name  : manova2
    nfactors : 2
    neffects : 3
Effects
    A     z=280.559  df=(5, 192)         p=<0.001
    B     z=128.754  df=(5, 192)         p=<0.001
    A:B   z=11.373   df=(5, 192)         p=<0.001

The example datasets require the jiku-data package: pip install "spm1d[data]".

Note:

  • Design matrix and effect contrasts as in anova2.

  • Supports between-subject factors and one pooled covariance only.

manova3(y, A, B, C, cov_model='iid', roi=None, equal_var=None)[source]#

Three-way multivariate analysis of variance.

Parameters:

  • y — (J,I) array for 0D data or (J,Q,I) array for 1D data

  • A, B, C — (J,) arrays of integer labels for the three factors

  • cov_model — iid only

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

  • Q — number of domain nodes (1D data)

  • I — number of vector components

Returns:

  • SPMList object

Example:

The 0D example uses the Palmer penguins dataset (species x island x sex design with four components).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.R_Penguins()
>>> y       = dataset.y     # (333,4) array
>>> A, B, C = dataset.x.T   # (333,) arrays of factor labels
>>> spmi    = spm1d.stats.manova3( y, A, B, C ).inference( 0.05 )
>>> print( spmi )
SPMiList
    STAT     : F (Wilks' Λ)
    fn_name  : manova3
    nfactors : 3
    neffects : 7
Effects
    A     z=583.115  df=(8, 624)         p=<0.001
    B     z=136.646  df=(4, 312)         p=<0.001
    C     z=8.309    df=(8, 624)         p=<0.001
    A:B   z=5.129    df=(8, 624)         p=<0.001
    A:C   z=2.969    df=(16, 953.813)    p=<0.001
    B:C   z=0.773    df=(8, 624)         p=0.62654
    A:B:C z=0.923    df=(16, 953.813)    p=0.54246

The example datasets require the jiku-data package: pip install "spm1d[data]".

Note:

  • Design matrix and effect contrasts as in anova3.

  • Supports between-subject factors and one pooled covariance only.

MANCOVA#


mancova(y, A, x, cov_model='iid', roi=None, equal_var=None)[source]#

One-way multivariate analysis of covariance.

Parameters:

  • y — (J,I) array for 0D data or (J,Q,I) array for 1D data

  • A — (J,) array of integer group labels

  • x — (J,) array of covariate values or (J,k) array of k covariates

  • cov_model — iid only

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

  • Q — number of domain nodes (1D data)

  • I — number of vector components

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the Rohwer dataset (two groups, three achievement scores and five covariates).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.Rohwer()
>>> y       = dataset.y          # (69,3) array
>>> A       = dataset.x[:, 0]    # (69,) array of group labels
>>> x       = dataset.x[:, 1:]   # (69,5) array of covariates
>>> spmi    = spm1d.stats.mancova( y, A, x ).inference( 0.05 )
>>> print( spmi )
SPM{F} (Wilks' Λ) (0D) inference
    fn_name : mancova
    STAT    : F
    z       : 12.18176
    df      : (3, 60)
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    zc           : 2.75808
    h0reject     : True
    p            : <0.00001

The example datasets require the jiku-data package: pip install "spm1d[data]".

Note:

  • Design as in ancova (common slopes).

  • Field covariates are not supported.

CCA#


cca(y, x, roi=None)[source]#

Canonical correlation analysis (CCA).

Parameters:

  • y — (J,I) array for 0D data or (J,Q,I) array for 1D data

  • x — Independent variable as a (J,) array

  • roi — DEPRECATED (use inference)

Dimensions:
  • J — number of observations

  • Q — number of domain nodes (1D data)

  • I — number of vector components

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the “trees” dataset from R (31 observations and two components).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.R_Trees()
>>> y, x    = dataset.y, dataset.x  # (31,2) array and (31,) array
>>> spmi    = spm1d.stats.cca( y, x ).inference( 0.05 )
>>> print( spmi )
SPM{F} (Wilks' Λ) (0D) inference
    fn_name : cca
    STAT    : F
    z       : 222.47135
    df      : (2, 28)
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    zc           : 3.34039
    h0reject     : True
    p            : <0.00001

The 1D example uses ground reaction force vectors vs. running speed from Dorn et al. (2012) (eight trials and three components).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.Dorn2012()
>>> y, x    = dataset.y, dataset.x  # (8,100,3) array and (8,) array
>>> spmi    = spm1d.stats.cca( y, x ).inference( 0.05 )
>>> print( spmi.h0reject )
True
>>> spmi.plot()
>>> plt.show()

The example datasets require the jiku-data package: pip install "spm1d[data]".

Note:

  • Supports univariate 0D independent variables only.

  • Statistic: maximum canonical correlation r transformed to Rao’s F.

Multivariate GLM#


formula(formula, data, subject=None, cov_model=None, roi=None, multivariate=None)[source]

Formula-based model specification.

spm = spm1d.stats.formula( 'y ~ A * B + x', data )
FF  = spm1d.stats.formula( 'y ~ A * B', data, subject='SUBJ' )

The response (left of ~) must be a variable in data (dict). Integer-, boolean- and string-valued variables are factors. Float-valued variables are covariates. C(name) forces a factor. Integer-valued covariates must be converted using x.astype(float).

Formulas describing named designs build those designs with factors named after the formula variables (e.g., Main supp, Interaction supp:dose, supp0 - supp1). Other formulas fit fixed effects on independent observations with one adjusted F test per term. See Formulas.

Single-term formulas return an SPM object. Multi-term formulas return an SPMList.

Multivariate formula:

FF = spm1d.stats.formula( 'Y ~ A * B + x', data )            # Y: (J, Q, I)
FF = spm1d.stats.formula( 'Y ~ A + x', data, multivariate=True )   # Y: (J, I), 0D

Responses with an extra dimension (e.g., (J, Q, I) for 1D data) are tested with Wilks’ lambda (as Rao’s F) with one pooled covariance (MANOVA, MANCOVA or multivariate regression). subject is not supported for vector responses. A (J, I) response is read as 1D univariate data unless multivariate=True.

Parameters:

  • formula — Model formula such as 'y ~ A * B + x'

  • data — mapping from variable names to per-observation arrays

  • subject — Subject variable name in data (repeated-measures formulas)

  • cov_model — 'iid' or 'unstructured'. Default None uses the named design default (otherwise 'unstructured' with factors and 'iid' without).

  • roi — DEPRECATED (use inference)

  • multivariate — True to read a (J,I) response as 0D multivariate data

Dimensions:
  • J — number of observations

  • Q — number of domain nodes (1D data)

  • I — number of vector components

Returns:

  • An SPM (one term) or an SPMList (several terms)

Example:

A formula on the R “ToothGrowth” dataset (2 x 3 design):

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.R_ToothGrowth()
>>> A, B    = dataset.x.T   # (60,) arrays of factor labels
>>> data    = dict( y=dataset.y, supp=A, dose=B )
>>> spmi    = spm1d.stats.formula( 'y ~ supp * dose', data, cov_model='iid' ).inference( 0.05 )  # one pooled variance as in the classical ANOVA
>>> print( spmi )
SPMiList
    STAT     : F
    fn_name  : formula
    formula  : y ~ supp * dose
    nfactors : 2
    neffects : 3
Effects
    supp       z=15.572   df=(1, 54)          p=<0.001
    dose       z=92.000   df=(2, 54)          p=<0.001
    supp:dose  z=4.107    df=(2, 54)          p=0.02186

The example datasets require the jiku-data package: pip install "spm1d[data]".