Non-sphericity#
In repeated-measures designs, “non-sphericity” means that the variances of the differences between any two conditions are not constant across condition pairs. It is the within-subjects analog of between-subjects heteroscedasticity. When non-sphericity exists, an uncorrected test is anti-conservative, rejecting a true null hypothesis too often.
In spm1d non-sphericity is summarized as the Greenhouse–Geisser scalar ε, where ε = 1 indicates perfect sphericity and ε = 1/(k − 1) indicates maximum non-sphericity for k conditions (e.g., ε = 0.5 for three conditions).
Covariance models#
spm1d.stats.anova1rm( y, A, SUBJ, cov_model='iid' ) # sphericity assumed
spm1d.stats.anova1rm( y, A, SUBJ, cov_model='unstructured' ) # corrected (default)
In spm1d 0.5 nonsphericity corrections are applied only to anova1rm ℹ️.
ℹ️ Nonsphericity corrections
Preliminary nonsphericity corrections have been implemented for other procedures but have not yet been thoroughly developed or tested so are not released with spm1d 0.5. More comprehensive nonsphericity correction implementations are planned for a future release.
For example, four conditions measured on 12 subjects with an autoregressive within-subject correlation (ρ = 0.7) give df = (3, 33) and \(z_c\) = 5.404 with cov_model='iid' and df = (2.247, 24.720) and \(z_c\) = 6.619 with the default. The implied ε is 0.75:
y, A, SUBJ = spm1d.rng.anova1rm( nlevels=4, nsubj=12, Q=101, fwhm=20, cov_model='ar1', rho=0.7, seed=0 )
Fi_iid = spm1d.stats.anova1rm( y, A, SUBJ, cov_model='iid' ).inference( 0.05 )
Fi_uns = spm1d.stats.anova1rm( y, A, SUBJ ).inference( 0.05 )
print( Fi_iid.dfs, Fi_iid.zc )
print( Fi_uns.dfs, Fi_uns.zc )
(3, 33) 5.403550479048307
(2.247, 24.720) 6.619316060601863
For cov_model='unstructured', spm1d uses restricted maximum likelihood (REML) to estimate within-subjects covariance. Following REML-based covariance estimation, the degrees of freedom (ν) become the Satterthwaite effective ν. The corrected error ν is equal to the Greenhouse–Geisser ν. spm1d v0.4 procedures assumed sphericity so generally yield different results from version 0.5.
For anova1rm with three conditions and nine subjects at α = 0.05, spm1d yields uncorrected false positive rates that rise from 0.049 to 0.097 for 0D data as ε decreases, and that rise to more than 0.2 for 1D data. Under correction the FPR remains between 0.035 and 0.053. See spm1d Performance for more details.
Small samples#
For 0D data the corrected test is conservative at small sample sizes ℹ️. For 1D data ν converges to the true Greenhouse–Geisser ν, so 1D results are unaffected.
ℹ️ Small sample, 0D data
The Satterthwaite ν is computed from an estimated covariance. The formula does not account for this estimation. For 0D data, ν is therefore biased low at small sample sizes.
Numerical simulation results show that spm1d yields proportionally lower FPRs as α decreases — exhibiting increasing conservatism — for 0D data with true sphericity. For example: FPR = 0.082 at α = 0.10, 0.037 at α = 0.05 and 0.005 at α = 0.01.
Testing sphericity#
Mauchly’s test of sphericity is available for anova1rm:
spm = spm1d.stats.anova1rm( y, A, SUBJ )
sph = spm.test_sphericity()
print( sph.p )
0.05600034951661703
This test requires at least three conditions. The dataset above yields p = 0.056, despite strong true nonsphericity of ε=0.75 in the simulated data, demonstrating low power with 12 subjects. For 1D data, the test statistic forms a continuum that is thresholded using random field theory. For fewer than 8 subjects this approximation is anti-conservative.
Multi-factor designs#
For spm1d’s multi-factor repeated-measures designs the sphericity test is a diagnostic only, because version 0.5 does not correct across factors. Multi-factor repeated-measures designs therefore yield one test per within-subject effect. Effects whose factors all have two levels (a single contrast) are omitted because sphericity is only testable across more than two levels.
y, A, B, SUBJ = spm1d.rng.anova2rm( nlevels=(3, 3), nsubj=12, Q=101, fwhm=20, seed=0 )
FF = spm1d.stats.anova2rm( y, A, B, SUBJ )
sph = FF.test_sphericity() # one result per within-subject effect
print( sph.effects )
print( sph['A:B'].p )
['A', 'B', 'A:B']
0.7000301643049033
anova3rm, anova2onerm, anova3onerm and anova3tworm work the same way.
In mixed designs (anova2onerm, anova3onerm, anova3tworm) spm1d pools within-cell covariance across between-subject groups, and reports nonsphericity results only for within-subject effects.
Recommendations#
situation |
covariance model |
|---|---|
1D data |
|
0D data, 20 or more subjects |
|
ℹ️ Default “unstructured”
Multi-factor repeated-measures designs (anova2rm, anova2onerm, anova3rm, anova3onerm, anova3tworm) assume sphericity and only accept cov_model='iid' (see Multi-factor repeated-measures designs).
Small-sample warning#
Requesting cov_model='unstructured' with five or fewer subjects when the estimated ε is above its lower bound of 1/(k − 1) raises the following SPM1DNonSphericityWarning:
SPM1DNonSphericityWarning: Non-sphericity correction applied with 5 subjects (estimated epsilon 0.91). Corrections have known limitations for small samples with high non-sphericity. Pass cov_model="iid" to assume sphericity instead. Refer to the non-sphericity page in the documentation.
The warning is raised once per Python session and can be filtered using:
spm1d.settings.enable_warnings( False )
or, to filter only this category of warning:
import warnings
from spm1d.exceptions import SPM1DNonSphericityWarning
warnings.filterwarnings( 'ignore', category=SPM1DNonSphericityWarning )
Known limitations#
ν has a small-sample bias as described above.
With a repeated-measures covariance model, a contrast that tests only part of a within-subjects effect (e.g., two of four conditions specified using
glm) is anti-conservative at small sample sizes. For four conditions and eight subjects, its false positive rate is 0.0685, whereas the omnibus test of the same effect is conservative (0.0307).