scipy.stats.

obrientransform#

scipy.stats.obrientransform(*samples)[source]#

Compute the O’Brien transform on input data (any number of arrays).

Used to test for homogeneity of variance prior to running one-way stats. Each array in *samples is one level of a factor. If f_oneway is run on the transformed data and found significant, the variances are unequal. From Maxwell and Delaney [1], p.112.

Parameters:
sample1, sample2, …array_like

Any number of arrays.

Returns:
obrientransformndarray

Transformed data for use in an ANOVA. The first dimension of the result corresponds to the sequence of transformed arrays. If the arrays given are all 1-D of the same length, the return value is a 2-D array; otherwise it is a 1-D array of type object, with each element being an ndarray.

Raises:
ValueError

If the mean of the transformed data is not equal to the original variance, indicating a lack of convergence in the O’Brien transform.

Notes

Array API Standard Support

obrientransform has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

Library

CPU

GPU

NumPy

n/a

CuPy

n/a

PyTorch

JAX

Dask

n/a

See Support for the array API standard for more information.

References

[1]

S. E. Maxwell and H. D. Delaney, “Designing Experiments and Analyzing Data: A Model Comparison Perspective”, Wadsworth, 1990.

Examples

We’ll test the following data sets for differences in their variance.

>>> x = [10, 11, 13, 9, 7, 12, 12, 9, 10]
>>> y = [13, 21, 5, 10, 8, 14, 10, 12, 7, 15]

Apply the O’Brien transform to the data.

>>> from scipy.stats import obrientransform
>>> tx, ty = obrientransform(x, y)

Use scipy.stats.f_oneway to apply a one-way ANOVA test to the transformed data.

>>> from scipy.stats import f_oneway
>>> F, p = f_oneway(tx, ty)
>>> p
0.1314139477040335

If we require that p < 0.05 for significance, we cannot conclude that the variances are different.