pingouin.sphericity

pingouin.sphericity(data, method='mauchly', alpha=0.05)[source]

Mauchly and JNS test for sphericity.

Parameters
datapd.DataFrame

DataFrame containing the repeated measurements. data must be in wide-format. To convert from wide to long format, use the pandas.pivot_table() function.

methodstr

Method to compute sphericity

'jns' : John, Nagao and Sugiura test.
'mauchly' : Mauchly test.
alphafloat

Significance level

Returns
spherboolean

True if data have the sphericity property.

Wfloat

Test statistic

chi_sqfloat

Chi-square statistic

ddofint

Degrees of freedom

pfloat

P-value.

See also

homoscedasticity

Test equality of variance.

normality

Test the univariate normality of one or more array(s).

Notes

The Mauchly \(W\) statistic is defined by:

\[W = \frac{\prod_{j=1}^{r-1} \lambda_j}{(\frac{1}{r-1} \cdot \sum_{j=1}^{^{r-1}} \lambda_j)^{r-1}}\]

where \(\lambda_j\) are the eigenvalues of the population covariance matrix (= double-centered sample covariance matrix) and \(r\) is the number of conditions.

From then, the \(W\) statistic is transformed into a chi-square score using the number of observations per condition \(n\)

\[f = \frac{2(r-1)^2+r+1}{6(r-1)(n-1)}\]
\[\chi_w^2 = (f-1)(n-1) log(W)\]

The p-value is then approximated using a chi-square distribution:

\[\chi_w^2 \sim \chi^2(\frac{r(r-1)}{2}-1)\]

The JNS \(V\) statistic is defined by:

\[V = \frac{(\sum_j^{r-1} \lambda_j)^2}{\sum_j^{r-1} \lambda_j^2}\]
\[\chi_v^2 = \frac{n}{2} (r-1)^2 (V - \frac{1}{r-1})\]

and the p-value approximated using a chi-square distribution

\[\chi_v^2 \sim \chi^2(\frac{r(r-1)}{2}-1)\]

References

1

Mauchly, J. W. (1940). Significance test for sphericity of a normal n-variate distribution. The Annals of Mathematical Statistics, 11(2), 204-209.

2

Nagao, H. (1973). On some test criteria for covariance matrix. The Annals of Statistics, 700-709.

3

Sugiura, N. (1972). Locally best invariant test for sphericity and the limiting distributions. The Annals of Mathematical Statistics, 1312-1316.

4

John, S. (1972). The distribution of a statistic used for testing sphericity of normal distributions. Biometrika, 59(1), 169-173.

5

http://www.real-statistics.com/anova-repeated-measures/sphericity/

Examples

  1. Mauchly test for sphericity

>>> import pandas as pd
>>> from pingouin import sphericity
>>> data = pd.DataFrame({'A': [2.2, 3.1, 4.3, 4.1, 7.2],
...                      'B': [1.1, 2.5, 4.1, 5.2, 6.4],
...                      'C': [8.2, 4.5, 3.4, 6.2, 7.2]})
>>> sphericity(data)
(True, 0.21, 4.677, 2, 0.09649016283209666)
  1. JNS test for sphericity

>>> sphericity(data, method='jns')
(False, 1.118, 6.176, 2, 0.04560424030751982)