Univariate procedures#

Univariate dependent variables must be arranged as (J,) arrays for 0D data or as (J, Q) arrays for 1D data, where J is the number of observations and Q the number of domain nodes.

t tests and regression#


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

One-sample t test.

Parameters:

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

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

  • roi — DEPRECATED (use inference)

Dimensions:
  • J — number of observations

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

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the “morley” dataset from R (100 measurements of the speed of light). The test is one-tailed with a null value of 792.

>>> import spm1d
>>> import jikudata as jd
>>> y    = jd.R_Morley().y  # (100,) array
>>> spmi = spm1d.stats.ttest( y, 792 ).inference( 0.05, dirn=1 )
>>> print( spmi )
SPM{t} (0D) inference
    fn_name : ttest
    STAT    : T
    z       : 7.64455
    df      : (1, 99)
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    dirn         : 1
    zc           : 1.66039
    h0reject     : True
    p            : <0.00001

The 1D example uses ten simulated responses from Pataky et al. (2015).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> y    = jd.SimulatedPataky2015b().y  # (10,101) array
>>> spmi = spm1d.stats.ttest( y, 0 ).inference( 0.05, dirn=1 )
>>> print( spmi.h0reject, round( spmi.p_zmax, 3 ) )
True 0.019
>>> spmi.plot()
>>> plt.show()

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

Note:

  • Inference is two-tailed by default.

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

Paired t test.

Parameters:

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

  • y1 — Condition B data as a (J,) array for 0D data or a (J,Q) 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)

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the “sleep” dataset from R (10 participants and two conditions).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.R_SleepPairedTest()
>>> y, A    = dataset.y, dataset.x  # (20,) arrays of responses and condition labels
>>> y0, y1  = y[ A == 0 ], y[ A == 1 ]  # same participants in the same order
>>> spmi    = spm1d.stats.ttest_paired( y0, y1 ).inference( 0.05 )
>>> print( spmi )
SPM{t} (0D) inference
    fn_name : ttest_paired
    STAT    : T
    z       : -4.06213
    df      : (1, 9)
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    dirn         : 0
    zc           : 2.26216
    h0reject     : True
    p            : 0.00283

The 1D example uses plantar arch angle from Caravaggi et al. (2010) (ten participants and two conditions).

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

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

ttest2(y0, y1, cov_model='unstructured', roi=None, equal_var=None)[source]#

Two-sample t test.

Parameters:

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

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

  • cov_model — iid, unstructured (default) or a list of covariance component matrices

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the “sleep” dataset from R (two groups of 10).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.R_Sleep2Test()
>>> y, A    = dataset.y, dataset.x  # (20,) arrays of responses and group labels
>>> y0, y1  = y[ A == 0 ], y[ A == 1 ]
>>> spmi    = spm1d.stats.ttest2( y0, y1 ).inference( 0.05 )
>>> print( spmi )
SPM{t} (0D) inference
    fn_name : ttest2
    STAT    : T
    z       : -1.86081
    df0     : (1, 18)
    df      : (1, 17.776)
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    dirn         : 0
    zc           : 2.10282
    h0reject     : False
    p            : 0.07939

The 1D example uses two simulated groups of six responses.

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.SimulatedTwoLocalMax()
>>> y, A    = dataset.y, dataset.x  # (12,101) array and (12,) array
>>> y0, y1  = y[ A == 0 ], y[ A == 1 ]
>>> spmi    = spm1d.stats.ttest2( 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]".

Note:

  • ttest2(y0, y1) tests y0 - y1 (dirn=1 tests y0 > y1).

  • Degrees of freedom are corrected using Welch’s rule for 0D data and trRV**2/trRVRV for 1D data. spm1d.settings.enable_spm12_compatibility() applies the 1D rule to 0D data (for reproducing SPM12 results).

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

Linear regression.

Parameters:

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

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

  • roi — DEPRECATED (use inference)

Dimensions:
  • J — number of observations

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

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the “cars” dataset from R (speed and stopping distance of 50 cars).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.R_Cars()
>>> y, x    = dataset.y, dataset.x  # (50,) arrays of response and independent variable
>>> spmi    = spm1d.stats.regress( y, x ).inference( 0.05 )
>>> print( spmi )
SPM{t} (0D) inference
    fn_name : regress
    STAT    : T
    z       : 9.46399
    r       : 0.80689
    df      : (1, 48)
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    dirn         : 0
    zc           : 2.01063
    h0reject     : True
    p            : <0.00001

The 1D example uses ground reaction force vs. walking speed from Pataky et al. (2008) (60 trials).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.SpeedGRF()
>>> y, x    = dataset.y, dataset.x  # (60,101) array and (60,) array
>>> spmi    = spm1d.stats.regress( 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:

  • Correlation coefficient: spm.r.

ANOVA#


anova1(y, A, cov_model='unstructured', roi=None, equal_var=None)[source]#

One-way ANOVA (between-subject).

Parameters:

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

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

  • cov_model — iid, unstructured (default) or a list of covariance component matrices

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the R “PlantGrowth” dataset (three groups of ten).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.R_PlantGrowth()
>>> y, A    = dataset.y, dataset.x  # (30,) arrays of responses and group labels
>>> spmi    = spm1d.stats.anova1( y, A, cov_model='iid' ).inference( 0.05 )  # one pooled variance as in the classical ANOVA
>>> print( spmi )
SPM{F} (0D) inference
    fn_name    : anova1
    STAT       : F
    z          : 4.84609
    df         : (2, 27)
    ss         : 3.76634
    sse        : 10.49209
    ms         : 1.88317
    mse        : 0.38860
    name       : Main A
    name_short : A
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    zc           : 3.35413
    h0reject     : True
    p            : 0.01591

The 1D example uses ground reaction force at three walking speeds from Pataky et al. (2008) (60 trials).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.SpeedGRFcategorical()
>>> y, A    = dataset.y, dataset.x  # (60,101) array and (60,) array
>>> spmi    = spm1d.stats.anova1( 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:

  • Group sizes need not be equal.

  • Default cov_model='unstructured' estimates one variance per group.

anova1rm(y, A, SUBJ, cov_model='unstructured', roi=None, equal_var=None)[source]#

One-way repeated-measures ANOVA.

Parameters:

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

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

  • SUBJ — (J,) array of integer subject labels

  • cov_model — unstructured (default) or iid (sphericity assumed)

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the “selfesteem” dataset from the R package datarium (ten subjects and three time points).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.DatariumSelfesteem()
>>> y       = dataset.y     # (30,) array
>>> A, SUBJ = dataset.x.T   # (30,) arrays of condition and subject labels
>>> spmi    = spm1d.stats.anova1rm( y, A, SUBJ, cov_model='iid' ).inference( 0.05 )  # sphericity assumed as in the classical repeated-measures ANOVA
>>> print( spmi )
SPM{F} (0D) inference
    fn_name    : anova1rm
    STAT       : F
    z          : 55.46903
    df         : (2, 18)
    ss         : 102.45582
    sse        : 16.62374
    ms         : 51.22791
    mse        : 0.92354
    name       : Main A
    name_short : A
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    zc           : 3.55456
    h0reject     : True
    p            : <0.00001

The 1D example uses ground reaction force for ten subjects at three walking speeds from Pataky et al. (2008).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.SpeedGRFcategoricalRM()
>>> y       = dataset.y     # (30,101) array
>>> A, SUBJ = dataset.x.T   # (30,) arrays
>>> spmi    = spm1d.stats.anova1rm( y, A, SUBJ ).inference( 0.05 )
>>> print( spmi.h0reject )
True
>>> spmi.plot()
>>> plt.show()

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

Note:

  • Sphericity is not assumed by default (Satterthwaite degrees of freedom correction).

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

Two-way ANOVA (both factors between-subject).

Parameters:

  • y — (J,) array for 0D data or (J,Q) 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 or unstructured (default)

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPMList object

Example:

The 0D example uses the R “ToothGrowth” dataset (2 x 3 design with ten observations per cell).

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

The 1D example uses a simulated 2 x 3 design (ten observations per cell).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.SPM1D_ANOVA2_2x3()
>>> y       = dataset.y     # (60,101) array
>>> A, B    = dataset.x.T   # (60,) arrays
>>> spmi    = spm1d.stats.anova2( y, A, B ).inference( 0.05 )
>>> for spm in spmi:
...     print( spm.name, spm.h0reject )
Main A False
Main B True
Interaction A:B False
>>> spmi.plot()
>>> plt.show()

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

Note:

  • Default cov_model='unstructured' estimates one variance per A-by-B cell.

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

Two-way nested ANOVA with factor B nested within factor A.

Parameters:

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

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

  • B — (J,) array of integer labels for Factor B (nested in A)

  • cov_model — iid only (the default)

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPMList object

Example:

The 0D example uses the “Pastes” dataset from the R package lme4 (ten batches with three casks nested in each batch).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.Lme4Pastes()
>>> y       = dataset.y     # (60,) array
>>> A, B    = dataset.x.T   # (60,) arrays of factor A and nested factor B labels
>>> spmi    = spm1d.stats.anova2nested( y, A, B ).inference( 0.05 )
>>> print( spmi )
SPMiList
    STAT     : F
    fn_name  : anova2nested
    nfactors : 2
    neffects : 2
Effects
    A     z=1.567    df=(9, 20)          p=0.19255
    B     z=25.878   df=(20, 30)         p=<0.001

The 1D example uses a simulated nested design (two levels of A and three levels of B within each).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.SPM1D_ANOVA2NESTED_2x3()
>>> y       = dataset.y     # (60,101) array
>>> A, B    = dataset.x.T   # (60,) arrays
>>> spmi    = spm1d.stats.anova2nested( y, A, B ).inference( 0.05 )
>>> for spm in spmi:
...     print( spm.name, spm.h0reject )
Main A False
Main B True
>>> spmi.plot()
>>> plt.show()

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

Note:

  • A is tested against B(A) rather than against the residual.

  • Requires a balanced design (the same number of B levels in every level of A and at least two).

  • Requires cov_model='iid'.

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

Two-way mixed ANOVA with A between subjects and B within subjects.

Parameters:

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

  • A — (J,) array of integer labels for the between-subject factor

  • B — (J,) array of integer labels for the within-subject factor

  • SUBJ — (J,) array of integer subject labels

  • cov_model — iid only (the default)

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPMList object

Example:

The 0D example uses the “anxiety” dataset from the R package datarium (three groups of 15 participants and three time points).

>>> import spm1d
>>> import jikudata as jd
>>> dataset    = jd.DatariumAnxietyRM()
>>> y          = dataset.y     # (135,) array
>>> A, B, SUBJ = dataset.x.T   # (135,) arrays of between-subject, within-subject and subject labels
>>> spmi       = spm1d.stats.anova2onerm( y, A, B, SUBJ ).inference( 0.05 )
>>> print( spmi )
SPMiList
    STAT     : F
    fn_name  : anova2onerm
    nfactors : 2
    neffects : 3
Effects
    A     z=4.352    df=(2, 42)          p=0.01916
    B     z=394.909  df=(2, 84)          p=<0.001
    A:B   z=110.188  df=(4, 84)          p=<0.001

The 1D example uses a simulated 2 x 3 mixed design.

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset    = jd.SPM1D_ANOVA2ONERM_2x3()
>>> y          = dataset.y     # (54,101) array
>>> A, B, SUBJ = dataset.x.T   # (54,) arrays
>>> spmi       = spm1d.stats.anova2onerm( y, A, B, SUBJ ).inference( 0.05 )
>>> for spm in spmi:
...     print( spm.name, spm.h0reject )
Main A False
Main B False
Interaction A:B True
>>> spmi.plot()
>>> plt.show()

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

Note:

  • Error terms are subjects-within-A for A and subject-by-B for B and A-by-B.

  • Requires a balanced design (equal subjects per level of A and every subject measured at every level of B).

  • Requires cov_model='iid'.

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

Two-way repeated-measures ANOVA (both factors within-subject).

Parameters:

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

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

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

  • SUBJ — (J,) array of integer subject labels

  • cov_model — iid only (the default)

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPMList object

Example:

The 0D example uses the “Rabbit” dataset from the R package MASS (five rabbits, two treatments and six doses).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.MASS_Rabbit()
>>> y       = dataset.y     # (60,) array
>>> A, B, S = dataset.x.T   # (60,) arrays of factor A, factor B and subject labels
>>> spmi    = spm1d.stats.anova2rm( y, A, B, S ).inference( 0.05 )
>>> print( spmi )
SPMiList
    STAT     : F
    fn_name  : anova2rm
    nfactors : 2
    neffects : 3
Effects
    A     z=13.649   df=(1, 4)           p=0.02094
    B     z=66.175   df=(5, 20)          p=<0.001
    A:B   z=8.773    df=(5, 20)          p=<0.001

The 1D example uses a simulated 2 x 3 repeated-measures design.

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.SPM1D_ANOVA2RM_2x3()
>>> y       = dataset.y     # (72,101) array
>>> A, B, S = dataset.x.T   # (72,) arrays
>>> spmi    = spm1d.stats.anova2rm( y, A, B, S ).inference( 0.05 )
>>> for spm in spmi:
...     print( spm.name, spm.h0reject )
Main A True
Main B False
Interaction A:B False
>>> spmi.plot()
>>> plt.show()

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

Note:

  • Error terms are SxA for A, SxB for B and SxAxB for the interaction. Requires cov_model='iid'.

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

Three-way fully-crossed between-subject ANOVA.

Parameters:

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

  • A, B, C — (J,) arrays of integer factor labels

  • cov_model — iid or unstructured (default)

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPMList object

Example:

The 0D example uses the “npk” dataset from R (2 x 2 x 2 design).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.R_Npk()
>>> y       = dataset.y     # (24,) array
>>> A, B, C = dataset.x.T   # (24,) arrays of factor labels
>>> spmi    = spm1d.stats.anova3( y, A, B, C, cov_model='iid' ).inference( 0.05 )  # one pooled variance as in the classical ANOVA
>>> print( spmi )
SPMiList
    STAT     : F
    fn_name  : anova3
    nfactors : 3
    neffects : 7
Effects
    A     z=6.161    df=(1, 16)          p=0.02454
    B     z=0.273    df=(1, 16)          p=0.60819
    C     z=3.099    df=(1, 16)          p=0.09746
    A:B   z=0.693    df=(1, 16)          p=0.41750
    A:C   z=1.078    df=(1, 16)          p=0.31448
    B:C   z=0.016    df=(1, 16)          p=0.90192
    A:B:C z=1.204    df=(1, 16)          p=0.28870

The 1D example uses a simulated 2 x 2 x 2 design.

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.SPM1D_ANOVA3_2x2x2()
>>> y       = dataset.y     # (40,101) array
>>> A, B, C = dataset.x.T   # (40,) arrays
>>> spmi    = spm1d.stats.anova3( y, A, B, C ).inference( 0.05 )
>>> for spm in spmi:
...     print( spm.name, spm.h0reject )
Main A False
Main B True
Main C False
Interaction A:B False
Interaction A:C False
Interaction B:C False
Interaction A:B:C False
>>> spmi.plot()
>>> plt.show()

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

Note:

  • Every effect is tested against the residual.

  • cov_model='unstructured' estimates one variance per cell.

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

Three-way nested ANOVA with C nested within B nested within A.

Parameters:

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

  • A, B, C — (J,) arrays of integer labels

  • cov_model — iid only (the default)

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPMList object

Example:

The 0D example uses the “Oxide” dataset from the R package nlme (two sources, four lots nested in each source and three wafers nested in each lot).

>>> import spm1d
>>> import jikudata as jd
>>> import warnings
>>> warnings.filterwarnings( "ignore", category=spm1d.exceptions.SPM1DDimensionWarning )
>>> dataset = jd.Nlme_Oxide()
>>> y       = dataset.y     # (72,) array
>>> A, B, C = dataset.x.T   # (72,) arrays of factor labels, C nested in B nested in A
>>> spmi    = spm1d.stats.anova3nested( y, A, B, C ).inference( 0.05 )
>>> print( spmi )
SPMiList
    STAT     : F
    fn_name  : anova3nested
    nfactors : 3
    neffects : 3
Effects
    A     z=1.526    df=(1, 6)           p=0.26287
    B     z=9.979    df=(6, 16)          p=<0.001
    C     z=9.560    df=(16, 48)         p=<0.001

The 1D example uses a simulated 2 x 2 x 2 nested design.

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.SPM1D_ANOVA3NESTED_2x2x2()
>>> y       = dataset.y     # (64,101) array
>>> A, B, C = dataset.x.T   # (64,) arrays
>>> spmi    = spm1d.stats.anova3nested( y, A, B, C ).inference( 0.05 )
>>> for spm in spmi:
...     print( spm.name, spm.h0reject )
Main A False
Main B False
Main C True
>>> spmi.plot()
>>> plt.show()

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

Note:

  • Error terms are B(A) for A, C(B) for B and the residual for C.

  • Requires a balanced design at both levels.

  • Requires cov_model='iid'.

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

Three-way mixed ANOVA with A and B between subjects and C within subjects.

Parameters:

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

  • A — (J,) array of integer labels for the first between-subject factor

  • B — (J,) array of integer labels for the second between-subject factor

  • C — (J,) array of integer labels for the within-subject factor

  • SUBJ — (J,) array of integer subject labels

  • cov_model — iid only (the default)

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPMList object

Example:

The 0D example uses the “CO2” dataset from R (12 plants, two origins, two treatments and seven concentrations).

>>> import spm1d
>>> import jikudata as jd
>>> dataset       = jd.R_CO2()
>>> y             = dataset.y     # (84,) array
>>> A, B, C, SUBJ = dataset.x.T   # (84,) arrays for two between-subject factors, one within-subject factor and subject labels
>>> spmi          = spm1d.stats.anova3onerm( y, A, B, C, SUBJ ).inference( 0.05 )
>>> print( spmi )
SPMiList
    STAT     : F
    fn_name  : anova3onerm
    nfactors : 3
    neffects : 7
Effects
    A     z=95.195   df=(1, 8)           p=<0.001
    B     z=27.949   df=(1, 8)           p=0.00074
    C     z=172.562  df=(6, 48)          p=<0.001
    A:B   z=6.385    df=(1, 8)           p=0.03543
    A:C   z=15.880   df=(6, 48)          p=<0.001
    B:C   z=4.283    df=(6, 48)          p=0.00156
    A:B:C z=4.748    df=(6, 48)          p=0.00072

The 1D example uses a simulated 2 x 2 x 2 mixed design.

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset       = jd.SPM1D_ANOVA3ONERM_2x2x2()
>>> y             = dataset.y     # (40,101) array
>>> A, B, C, SUBJ = dataset.x.T   # (40,) arrays
>>> spmi          = spm1d.stats.anova3onerm( y, A, B, C, SUBJ ).inference( 0.05 )
>>> for spm in spmi:
...     print( spm.name, spm.h0reject )
Main A False
Main B True
Main C False
Interaction A:B False
Interaction A:C False
Interaction B:C False
Interaction A:B:C False
>>> spmi.plot()
>>> plt.show()

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

Note:

  • Error terms are subjects-within-AB for A, B and AxB and subject-by-C for every effect involving C.

  • Requires a balanced design (equal subjects per A-by-B cell and every subject measured at every level of C).

  • Requires cov_model='iid'.

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

Three-way repeated-measures ANOVA (all three factors within-subject).

Parameters:

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

  • A — (J,) array of integer labels for the first within-subject factor

  • B — (J,) array of integer labels for the second within-subject factor

  • C — (J,) array of integer labels for the third within-subject factor

  • SUBJ — (J,) array of integer subject labels

  • cov_model — iid only (the default)

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPMList object

Example:

The 0D example uses the datarium “weightloss” dataset (12 subjects in a 2 x 2 x 3 within-subject design).

>>> import spm1d
>>> import jikudata as jd
>>> dataset    = jd.DatariumWeightloss()
>>> y          = dataset.y     # (144,) array
>>> A, B, C, S = dataset.x.T   # (144,) arrays of three factors and subject labels
>>> spmi       = spm1d.stats.anova3rm( y, A, B, C, S ).inference( 0.05 )
>>> print( spmi )
SPMiList
    STAT     : F
    fn_name  : anova3rm
    nfactors : 3
    neffects : 7
Effects
    A     z=6.021    df=(1, 11)          p=0.03203
    B     z=58.928   df=(1, 11)          p=<0.001
    C     z=110.942  df=(2, 22)          p=<0.001
    A:B   z=75.356   df=(1, 11)          p=<0.001
    A:C   z=0.603    df=(2, 22)          p=0.55619
    B:C   z=20.826   df=(2, 22)          p=<0.001
    A:B:C z=14.246   df=(2, 22)          p=<0.001

The 1D example uses a simulated 2 x 2 x 2 repeated-measures design.

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset    = jd.SPM1D_ANOVA3RM_2x2x2()
>>> y          = dataset.y     # (40,101) array
>>> A, B, C, S = dataset.x.T   # (40,) arrays
>>> spmi       = spm1d.stats.anova3rm( y, A, B, C, S ).inference( 0.05 )
>>> for spm in spmi:
...     print( spm.name, spm.h0reject )
Main A False
Main B True
Main C False
Interaction A:B False
Interaction A:C False
Interaction B:C False
Interaction A:B:C False
>>> spmi.plot()
>>> plt.show()

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

Note:

  • Each effect is tested against its own subject-by-effect interaction (SxA for A through SxAxBxC for AxBxC).

  • Requires cov_model='iid'.

  • Requires a balanced design (every subject measured once at every A-by-B-by-C combination).

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

Three-way mixed ANOVA with A between subjects and B and C within subjects.

Parameters:

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

  • A — (J,) array of integer labels for the between-subject factor

  • B — (J,) array of integer labels for the first within-subject factor

  • C — (J,) array of integer labels for the second within-subject factor

  • SUBJ — (J,) array of integer subject labels

  • cov_model — iid only (the default)

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPMList object

Example:

The 0D example uses a generated 2 x 3 x 2 dataset with 12 subjects.

>>> import spm1d
>>> import jikudata as jd
>>> dataset       = jd.Gen0D_anova3tworm()
>>> y             = dataset.y     # (72,) array
>>> A, B, C, SUBJ = dataset.x.T   # (72,) arrays for one between-subject factor, two within-subject factors and subject labels
>>> spmi          = spm1d.stats.anova3tworm( y, A, B, C, SUBJ ).inference( 0.05 )
>>> print( spmi )
SPMiList
    STAT     : F
    fn_name  : anova3tworm
    nfactors : 3
    neffects : 7
Effects
    A     z=1.596    df=(1, 10)          p=0.23517
    B     z=16.229   df=(2, 20)          p=<0.001
    C     z=3.403    df=(1, 10)          p=0.09487
    A:B   z=1.439    df=(2, 20)          p=0.26067
    A:C   z=0.295    df=(1, 10)          p=0.59891
    B:C   z=1.934    df=(2, 20)          p=0.17071
    A:B:C z=0.052    df=(2, 20)          p=0.94918

The 1D example uses a simulated 2 x 2 x 2 mixed design.

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset       = jd.SPM1D_ANOVA3TWORM_2x2x2()
>>> y             = dataset.y     # (40,101) array
>>> A, B, C, SUBJ = dataset.x.T   # (40,) arrays
>>> spmi          = spm1d.stats.anova3tworm( y, A, B, C, SUBJ ).inference( 0.05 )
>>> for spm in spmi:
...     print( spm.name, spm.h0reject )
Main A False
Main B True
Main C False
Interaction A:B False
Interaction A:C False
Interaction B:C False
Interaction A:B:C False
>>> spmi.plot()
>>> plt.show()

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

Note:

  • Error terms are subjects-within-A for A, subject-by-B for B and AxB, subject-by-C for C and AxC and subject-by-B-by-C for BxC and AxBxC.

  • Requires a balanced design (equal subjects per level of A and every subject measured at every B-by-C combination).

  • Requires cov_model='iid'.

ANCOVA#


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

One-way analysis of covariance (ANCOVA).

Parameters:

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

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

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

  • cov_model — iid or unstructured (default)

  • roi — DEPRECATED (use inference)

  • equal_var — DEPRECATED (use cov_model)

Dimensions:
  • J — number of observations

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

Returns:

  • SPM0D or SPM1D object

Example:

The 0D example uses the datarium “anxiety” dataset (45 participants in three groups with a pre-test covariate).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.DatariumAnxiety()
>>> y       = dataset.y     # (45,) array
>>> A, x    = dataset.x.T   # (45,) arrays of group labels and covariate
>>> spmi    = spm1d.stats.ancova( y, A, x, cov_model='iid' ).inference( 0.05 )  # one pooled variance as in the classical ANCOVA
>>> print( spmi )
SPM{F} (0D) inference
    fn_name    : ancova
    STAT       : F
    z          : 218.62926
    df         : (2, 41)
    ss         : 74.02259
    sse        : 6.94081
    ms         : 37.01130
    mse        : 0.16929
    name       : Main A
    name_short : A
Inference results:
    method       : param
    isparametric : True
    alpha        : 0.05
    zc           : 3.22568
    h0reject     : True
    p            : <0.00001

The 1D example uses simulated data with one covariate.

>>> import spm1d
>>> from matplotlib import pyplot as plt
>>> y, A, x = spm1d.rng.ancova( nlevels=3, nsubj=10, Q=101, fwhm=20, seed=0 )
>>> spmi    = spm1d.stats.ancova( y, A, x ).inference( 0.05 )
>>> spmi.plot()
>>> plt.show()

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

Note:

  • Covariates are mean-centered internally.

  • Equal slopes across groups are assumed (no group-by-covariate interaction).

  • Default cov_model='unstructured' estimates one variance per group.

GLM#


glm(y, X, C, QQ=None, roi=None)[source]#

General Linear Model with an explicit design matrix and contrast(s).

spm = spm1d.stats.glm( y, X, c )            # one contrast
FF  = spm1d.stats.glm( y, X, [c0, c1, C2] )  # several contrasts

1D and 2D contrast arrays correspond to t and F contrasts, respectively.

One SPM object is returned for each contrast.

Parameters:

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

  • X — (J,n) design matrix

  • C — Contrast or contrast list

  • QQ — list of (J,J) covariance component matrices (default iid)

  • roi — DEPRECATED (use inference)

Dimensions:
  • J — number of observations

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

Returns:

  • SPM or SPMList object

Example:

Two-sample t test using spm1d.stats.glm:

>>> import numpy as np
>>> import spm1d
>>> rng  = np.random.default_rng( 0 )
>>> y    = rng.standard_normal( 20 )
>>> X    = np.zeros( (20, 2) )
>>> X[:10, 0] = 1
>>> X[10:, 1] = 1
>>> spm  = spm1d.stats.glm( y, X, [1, -1] )
>>> print( spm )
SPM{t} (0D)
    fn_name : glm
    STAT    : T
    name    : contrast 0
    z       : 1.40714
    df      : (1, 18)

Equal variance#


eqvartest(y0, y1, alt='unequal')[source]#

F test for equal variance.

Adapted from the MATLAB script in the supplementary material of Kowalski et al. (2021).

Parameters:

  • y0 — One group as a (J0,Q) array of 1D data

  • y1 — Other group as a (J1,Q) array of 1D data

  • alt — alternative hypothesis: unequal (default) or greater ( var(y0) > var(y1) )

Dimensions:
  • J — number of observations

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

Returns:

  • Variance-ratio field object (not an SPM1D object)

Example:

The 1D example uses two simulated groups of six responses.

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.SimulatedTwoLocalMax()
>>> y, A    = dataset.y, dataset.x  # (12,101) array and (12,) array
>>> y0, y1  = y[ A == 0 ], y[ A == 1 ]
>>> results = spm1d.stats.eqvartest( y0, y1 ).inference( 0.05 )
>>> print( results.h0reject )
False

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

Note:

  • Height-level inference only.

  • 1D data only. alt='unequal' requires equal sample sizes.

Confidence intervals#


ci_onesample(y, alpha=0.05, mu=None)[source]#

One-sample confidence interval.

Parameters:

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

  • alpha — Type I error rate. Default 0.05

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

Dimensions:
  • J — number of observations

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

Returns:

  • A CIOneSample0D or CIOneSample1D object

Example:

The 0D example uses the “morley” dataset from R (100 measurements of the speed of light).

>>> import spm1d
>>> import jikudata as jd
>>> y  = jd.R_Morley().y  # (100,) array
>>> ci = spm1d.stats.ci_onesample( y, 0.05 )
>>> print( ci )
0D Confidence Interval (95.0%)
   kind          :  One sample
   datum         :  mean  (852.40000)
   Probability
      alpha      :  0.050
      df         :  (1, 99)
      zc         :  1.98422
   Confidence interval
      hc         :  15.67741
      ci         :  (836.72259, 868.07741)

The 1D example uses ten simulated responses from Pataky et al. (2015).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> y  = jd.SimulatedPataky2015a().y  # (10,101) array
>>> ci = spm1d.stats.ci_onesample( y, 0.05 )
>>> ci.plot()
>>> plt.show()

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

Note:

  • For 1D data this is a confidence region based on the random field theory threshold (not a pointwise interval).

ci_pairedsample(yA, yB, alpha=0.05, datum='difference', mu=None)[source]#

Paired-sample confidence interval.

Parameters:

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

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

  • alpha — Type I error rate. Default 0.05

  • datum — Interval center: difference (default) or meanA

  • mu — Hypothesized mean difference for datum='difference' as a scalar for 0D data or a scalar or (Q,) array for 1D data (default 0). Criterion 'meanB' (default) or 'tailB' for datum='meanA'.

Dimensions:
  • J — number of observations

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

Returns:

  • Confidence interval object

Example:

The 0D example uses the “sleep” dataset from R (10 participants and two conditions).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.R_SleepPairedTest()
>>> y, A    = dataset.y, dataset.x  # (20,) arrays of responses and condition labels
>>> yA, yB  = y[ A == 0 ], y[ A == 1 ]  # same participants in the same order
>>> ci      = spm1d.stats.ci_pairedsample( yA, yB, 0.05 )
>>> print( ci )
0D Confidence Interval (95.0%)
   kind          :  Paired difference
   datum         :  mean  (-1.58000)
   Probability
      alpha      :  0.050
      df         :  (1, 9)
      zc         :  2.26216
   Confidence interval
      hc         :  0.87989
      ci         :  (-2.45989, -0.70011)

The 1D example uses plantar arch angle from Caravaggi et al. (2010) (ten participants and two conditions).

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.PlantarArchAngle()
>>> y, A    = dataset.y, dataset.x  # (20,101) array and (20,) array
>>> yA, yB  = y[ A == 0 ], y[ A == 1 ]
>>> ci      = spm1d.stats.ci_pairedsample( yA, yB, 0.05 )
>>> ci.plot()
>>> plt.show()

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

ci_twosample(yA, yB, alpha=0.05, datum='difference', mu=None)[source]#

Two-sample confidence interval.

Parameters:

  • yA — Group A data as a (JA,) array for 0D data or a (JA,Q) array for 1D data

  • yB — Group B data as a (JB,) array for 0D data or a (JB,Q) array for 1D data.

  • alpha — Type I error rate. Default 0.05

  • datum — difference (default) or meanA

  • mu — Hypothesized mean difference for datum='difference' as a scalar for 0D data or a scalar or (Q,) array for 1D data (default 0). Criterion 'meanB' (default) or 'tailB' for datum='meanA'.

Dimensions:
  • J — number of observations

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

Returns:

  • Confidence interval object

Example:

The 0D example uses the “sleep” dataset from R (two groups of 10).

>>> import spm1d
>>> import jikudata as jd
>>> dataset = jd.R_Sleep2Test()
>>> y, A    = dataset.y, dataset.x  # (20,) arrays of responses and group labels
>>> yA, yB  = y[ A == 0 ], y[ A == 1 ]
>>> ci      = spm1d.stats.ci_twosample( yA, yB, 0.05 )
>>> print( ci )
0D Confidence Interval (95.0%)
   kind          :  Two-sample difference
   datum         :  mean  (-1.58000)
   Probability
      alpha      :  0.050
      df         :  (1, 18)
      zc         :  2.10092
   Confidence interval
      hc         :  1.78387
      ci         :  (-3.36387, 0.20387)

The 1D example uses two simulated groups of six responses.

>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> dataset = jd.SimulatedTwoLocalMax()
>>> y, A    = dataset.y, dataset.x  # (12,101) array and (12,) array
>>> yA, yB  = y[ A == 0 ], y[ A == 1 ]
>>> ci      = spm1d.stats.ci_twosample( yA, yB, 0.05 )
>>> ci.plot()
>>> plt.show()

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