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#
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_varbut issues a deprecation warning.The version 0.5 results for
cov_model='unstructured'may differ slightly from the version 0.4 results forequal_var=Falsedue to a different, more robust correction for heteroscedasticity
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
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
ttest2andanova1also acceptcov_model='unstructured'.anova1rm,anova2andanova3requirecov_model='iid'for permutation.ancovahas no permutation inference.
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
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.
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 differentdfvalues and critical thresholds than in 0.4 unlesscov_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,anova3onermandanova3tworm). 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
zstarin 0.4 tozcin 0.5The 0.4 inference keyword argument
cluster_sizeis 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
interpis not accepted in 0.5. Cluster endpoints are always interpolated to the threshold crossings.t.inference(0.05, interp=False)raises anSPM1DKeywordErrorSPM1DKeywordError: Unknown keyword argument "interp" for inference with method="rft". Keyword arguments for method="rft": dirn, circular, withBonf (plus alpha and roi).
anova1no longer accepts a tuple of group arrays. Callspm1d.stats.anova1(y, A)with the stacked datayand the group labelsA.spm1d.stats.anova1((Y1, Y2, Y3))raises anSPM1DErrorSPM1DError: anova1(): missing a required argument: 'A'. Its arguments are: y, A, cov_model, roi, equal_var.
Regression coefficients have moved from
t.betain 0.4 tot.fit.bin 0.5, wheret = spm1d.stats.regress(y, x).t.betaraises anSPM1DAttributeErrorSPM1DAttributeError: SPM1D object has no attribute "beta".
The critical height for confidence intervals has been renamed from
hstartohc. The 0.4 namehstaris still accessible but issues a warningNonparametric confidence intervals via
spm1d.stats.nonparam.ci_*are no longer available. Parametric CIs remain available viaspm1d.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.