Migrating from 0.4 to 0.5#

spm1d 0.5 is a complete, ground-up reimplementation of spm1d 0.4. Nevertheless most user-facing function names and processing commands remain identical. Only relatively minor changes exist in the API. Since these API changes can yield different results from 0.4, all users are encouraged to read this page to familiarize themselves with the most important changes in 0.5.

If you have upgraded to spm1d 0.5 and wish to downgrade back to 0.4 you can do so with:

pip install "spm1d<0.5"

Python version#

  • spm1d 0.5 requires Python 3.10 or later

  • spm1d 0.4 requires Python 3.7 or later

Datasets#

spm1d 0.4 contained several datasets that were accessible via spm1d.data. For various reasons the datasets have been migrated to a separate package called jiku-data. Several new datasets also exist there. To install jiku-data use:

pip install "spm1d[data]"

The datasets can then be accessed using:

import jikudata as jd
dataset = jd.SpeedGRF()

Arguments to spm1d.stats procedures#

Every spm1d.stats procedure returns a test statistic object. Probabilistic inferences regarding that test statistic are conducted in a separate inference step:

t  = spm1d.stats.ttest2( yA, yB )  # test statistic calculation
ti = t.inference( 0.05 )           # inference (probability calculations)

As in version 0.4, these can be chained in a single-line:

ti = spm1d.stats.ttest2( yA, yB ).inference( 0.05 )

The only differences in this processing chain are the arguments. The table below provides a brief summary of the changes. Click on a feature to see more details.

Feature

0.4

0.5

Variance model

equal_var=False

cov_model='unstructured'

Directional inference

two_tailed=True

dirn=0

Nonparametric inference

nonparam.ttest2

inference( 0.05, method='perm')

Region of interest

ttest2( y1, y0, roi=a )

inference( 0.05, roi=a )

Normality tests

normality.ttest2

ttest2( yA, yB ).test_normality()

Variance model#

In version 0.4 equal_var ℹ️ was used to specify whether an assumption of equal variance should be adopted. In version 0.5 this has been changed to cov_model='unstructured' to apply more generally to all ANOVA / ANCOVA / MANOVA / MANCOVA models.

spm1d.stats.ttest2( y1, y0, equal_var=False )  # v0.4
spm1d.stats.ttest2( y1, y0, cov_model='unstructured' )  # v0.5
ℹ️ equal_var
  • Version 0.5 still accepts equal_var but issues a deprecation warning.

  • The version 0.5 results for cov_model='unstructured' may differ slightly from the version 0.4 results for equal_var=False due to a different, more robust correction for heteroscedasticity

Back to summary table

Directional inference#

In version 0.4 the only option for directional inference was two_tailed. In 0.5 this functionality has been expanded with a new dirn keyword argument:

t  = spm1d.stats.ttest2( y1, y0 )

ti = t.inference(0.05, two_tailed=True)  # v0.4, two-tailed
ti = t.inference(0.05, two_tailed=False) # v0.4, one-tailed: y1 > y0

ti = t.inference(0.05, dirn=0)   # v0.5, two-tailed
ti = t.inference(0.05, dirn=1)   # v0.5, one-tailed: y1 > y0
ti = t.inference(0.05, dirn=-1)  # v0.5, one-tailed: y0 > y1

Back to summary table

Nonparametric inference#

In version 0.4 nonparametric procedures were accessed through spm1d.stats.nonparam. In 0.5 nonparametric inference and all other inference methods are specified using the method keyword argument:

t = spm1d.stats.nonparam.ttest2(y1, y0)   # v0.4 test stat calculation
ti = t.inference( 0.05, iterations=1000 ) # v0.4 nonparam inference

t = spm1d.stats.ttest2(y1, y0, cov_model='iid')   # v0.5 test stat calculation (all inference procedures)
ti = t.inference( 0.05, method='perm', nperm=1000 ) # v0.5 nonparam inference

Note that cov_model='iid' ℹ️ reproduces the v0.4 permutation procedures. Those procedures assumed equal variances.

ℹ️ cov_model
  • ttest2 and anova1 also accept cov_model='unstructured'.

  • anova1rm, anova2 and anova3 require cov_model='iid' for permutation.

  • ancova has no permutation inference.

Back to summary table

Region of interest analysis#

In version 0.4 ROI analysis was conducted by submitting an ROI array to the test statistic calculation. In 0.5 the ROI is handled instead at the inference stage.

a = np.asarray( [False]*101 )  # empty ROI array spanning whole domain
a[80:] = True                  # ROI specified as positions 80 to 100

t = spm1d.stats.ttest2(y1, y0, roi=a)    # v0.4

ti = spm1d.stats.ttest2(y1, y0).inference(0.05, roi=a)    # v0.5

Back to summary table

Normality tests#

In version 0.4 normality tests were accessed through spm1d.stats.normality. In 0.5 they are accessed as a method of the test statistic object.

spm = spm1d.stats.normality.ttest2( y1, y0 )  # v0.4

spm = spm1d.stats.ttest2( y1, y0 ).test_normality(0.05)  # v0.5

The Shapiro–Wilk diagnostic is not an inference procedure and is no longer an spm1d.stats function. The 0.4 functions in spm1d.stats.normality.sw still work but issue a warning. The recommended normality test is the test_normality() method.

Back to summary table


Default argument values#

  • ANOVA corrects for unequal variances and non-sphericity by default via cov_model='unstructured' ℹ️

    • Version 0.4 assumed equal variances and sphericity. Since corrections for unequal variances and non-sphericity affect the degrees of freedom df, the default ANOVA results generally have different df values and critical thresholds than in 0.4 unless cov_model='iid' is used to reproduce the 0.4 assumptions. See Non-sphericity.

    ℹ️ Unequal variances and non-sphericity corrections

    These corrections do not apply to the multi-factor repeated-measures designs (anova2rm, anova2onerm, anova3rm, anova3onerm and anova3tworm). These designs assume sphericity and equal variances as in 0.4 (see Multi-factor repeated-measures designs).

  • Smoothness for multivariate procedures is estimated with the multivariate estimator (Taylor & Worsley 2008). Version 0.4 averaged the component-wise estimates. Consequently thresholds for Hotelling’s T², MANOVA and CCA procedures differ slightly in 0.5 vs. 0.4.

  • Two-tailed permutation thresholds use the maximum of |z| at 1 − α as in 0.4.50 and later.

Other changes#

  • The critical threshold has been renamed from zstar in 0.4 to zc in 0.5

  • The 0.4 inference keyword argument cluster_size is not accepted in 0.5 (0.4 accepted this argument but did not implement any inference changes related to cluster size)

  • The 0.4 inference keyword argument interp is not accepted in 0.5. Cluster endpoints are always interpolated to the threshold crossings. t.inference(0.05, interp=False) raises an SPM1DKeywordError

    SPM1DKeywordError: Unknown keyword argument "interp" for inference with method="rft".
    Keyword arguments for method="rft": dirn, circular, withBonf  (plus alpha and roi).
    
  • anova1 no longer accepts a tuple of group arrays. Call spm1d.stats.anova1(y, A) with the stacked data y and the group labels A. spm1d.stats.anova1((Y1, Y2, Y3)) raises an SPM1DError

    SPM1DError: anova1(): missing a required argument: 'A'. Its arguments are: y, A, cov_model, roi, equal_var.
    
  • Regression coefficients have moved from t.beta in 0.4 to t.fit.b in 0.5, where t = spm1d.stats.regress(y, x). t.beta raises an SPM1DAttributeError

    SPM1DAttributeError: SPM1D object has no attribute "beta".
    
  • The critical height for confidence intervals has been renamed from hstar to hc. The 0.4 name hstar is still accessible but issues a warning

  • Nonparametric confidence intervals via spm1d.stats.nonparam.ci_* are no longer available. Parametric CIs remain available via spm1d.stats.ci_*. After release of version 0.5 all confidence interval calculations will be moved into a new package that will support nonparametric and other confidence regions.

  • Refer to the gallery for descriptions of additional new features.