Unequal variances#

Between-subjects designs (e.g., ttest2, anova1, anova2, etc.) traditionally assume homoscedasticity (i.e., all groups have identical variance). In heteroscedasticity (i.e., unequal group variances), a test that assumes equal variances generally does not maintain accurate control of the false positive rate.

Covariance models#

spm1d.stats.ttest2( y1, y0, cov_model='unstructured' )   # one variance per group (default)
spm1d.stats.ttest2( y1, y0, cov_model='iid' )            # equal variances assumed

When cov_model='unstructured' is used, spm1d estimates one variance component for each group in one-way designs and one per cell in higher-order designs. The degrees of freedom are then calculated as the Satterthwaite effective degrees of freedom. For two groups (i.e., a two-sample test) this is equivalent to Welch’s t test. The Satterthwaite effective degrees of freedom are generally not integers. They decrease as inter-group variances become more different. For example, three groups with sample sizes of 6, 15 and 15 and standard deviations of 2.0, 0.5 and 0.5 yield df = (2, 33) for cov_model='iid', df = (1.238, 11.709) for cov_model='unstructured', and the critical threshold rises from 6.731 to 12.278:

y, A   = spm1d.rng.anova1( nlevels=3, nsubj=[6, 15, 15], Q=101, fwhm=20, sd=[2.0, 0.5, 0.5], seed=0 )
Fi_iid = spm1d.stats.anova1( y, A, cov_model='iid' ).inference( 0.05 )
Fi_uns = spm1d.stats.anova1( y, A, cov_model='unstructured' ).inference( 0.05 )
print( Fi_iid.dfs, Fi_iid.zc )     # (2, 33)  6.731
print( Fi_uns.dfs, Fi_uns.zc )     # (1.238, 11.709)  12.278

Bartlett’s test rejects equal variances for these data (p < 0.00001, see below).

In spm1d v0.5 cov_model='unstructured' is used by default ℹ️. Setting cov_model='iid' will reproduce examples from v0.4. The equal_var=True argument from v0.4 is replaced with cov_model in v0.5.

ℹ️ ANOVA defaults

cov_model='iid' is the default for spm1d procedures which do not support corrections including mixed designs (e.g., anova2onerm, anova3onerm, anova3tworm). See Multi-factor repeated-measures designs for more details.

Effects on false positive rate (FPRs)#

Simulating 1000 two-sample datasets with no true effect, sample sizes of 6 and 18, standard deviations of 1.5 and 0.75 and 1D smoothness of FWHM = 20 gives an FPR of 0.315 at α = 0.05 when cov_model='iid' and 0.056 when cov_model='unstructured'.

Measured false positive rates for both covariance models are considered more systematically in spm1d Performance.

Testing equal variances#

The equal variance assumption can be explicitly tested with the test_eqvar() method of any test statistic object whose design has between-subject groups:

spm = spm1d.stats.anova1( y, A )
ev  = spm.test_eqvar()

For between-subjects designs (ttest2, anova1, anova2, etc.) spm1d uses Bartlett’s test. This test compares the error variances of all design cells using a test statistic that is approximately χ²-distributed with (number of cells − 1) degrees of freedom. For mixed designs (anova2onerm, anova3onerm, etc.) spm1d uses Box’s M test. This test compares the within-subject covariance matrices of the between-subject groups. This implies that each group needs more subjects than within-subject cells. Designs without between-subject groups have no group variances to compare. test_eqvar() therefore raises an error for them.

Simulating 1D data with three cells, equal variances, FWHM values from 10 to 25 and 300 datasets per condition yields spm1d false positive rates of 0.033–0.047 for Bartlett’s test and 0.033–0.05 for Box’s M. These results imply that the procedures are slightly conservative. Similar to normality tests, these tests should be regarded as diagnostic rather than a prerequisite for other analyses.