Mauchly's Test of Sphericity for a One-Way Within-Subjects Design
Source:R/mauchly_test.R
mauchly_test.RdTests the null hypothesis that the covariance matrix of the orthonormal contrasts among the \(k\) repeated measurements is proportional to the identity (the sphericity assumption underlying univariate repeated measures F-tests).
Arguments
- x
Either an \(n \times k\) numeric matrix or
data.frame(rows = subjects, columns = repeated measurements); or a long-formatdata.frametogether withid,time, andoutcomecolumn names.- id
Column name in
xidentifying the subject whenxis in long format (NULLotherwise).- time
Column name in
xidentifying the within-subjects factor level whenxis in long format (NULLotherwise).- outcome
Column name in
xidentifying the dependent variable whenxis in long format (NULLotherwise).
Value
A one-row data.frame with columns W (Mauchly's
statistic), statistic (the chi square approximation),
df, p_value, n_subjects, n_levels, and
method.
Details
Sphericity is the assumption that the variances of all pairwise
differences among the \(k\) levels are equal, equivalently, that the
covariance matrix \(\Sigma_C\) of any orthonormal set of \(k - 1\)
contrasts among the levels is proportional to the identity. Mauchly's
(1940) test statistic is
$$W = \frac{\det(\hat\Sigma_C)}{\bigl(\mathrm{tr}(\hat\Sigma_C) / (k - 1)\bigr)^{k - 1}},$$
and the chi square approximation
$$X^2 = -\,m \,\log W \quad \mathrm{with}\ m = (n - 1) - \frac{2(k - 1)^2 + (k - 1) + 2}{6\,(k - 1)}$$
has approximately \((k - 1)k/2 - 1\) degrees of freedom under
\(H_0\). The reported p-value uses Box's (1949) second-order
correction, a weighted combination of the chi square tails on
\((k - 1)k/2 - 1\) and \((k - 1)k/2 + 3\) degrees of freedom, which
improves the first-order approximation in small samples; this matches
mauchly.test.
When sphericity is rejected, the univariate F test is liberal;
correct using the Greenhouse-Geisser, Huynh-Feldt, or lower-bound
epsilon adjustments via epsilon_corrections or directly
via anova_within.
The test is only defined for \(k \ge 3\); with \(k = 2\), sphericity
is trivially true and the function returns W = 1, p = 1.
References
Mauchly, J. W. (1940). Significance test for sphericity of a normal \(n\)-variate distribution. Annals of Mathematical Statistics, 11(2), 204–209.
Box, G. E. P. (1949). A general distribution theory for a class of likelihood criteria. Biometrika, 36(3/4), 317–346.
Maxwell, S. E., Delaney, H. D., & Kelley, K. (2027). Designing experiments and analyzing data: A model comparison perspective (4th ed.). Routledge. (See Chapter 11 for sphericity in within-subjects designs.)
See also
epsilon_corrections, anova_within
Other within-subjects analysis:
anova_within(),
anova_within_two_way(),
epsilon_corrections(),
pairwise_within(),
plot_trajectories_fitted()
Other hypothesis tests:
adjusted_means(),
ancova(),
anova_within(),
ci_dunnett(),
ci_scheffe(),
ci_tukey_kramer(),
compare_cov_structures(),
contrast_test(),
correlations_test(),
equivalence_r(),
equivalence_smd(),
factorial_anova(),
manova_split_plot(),
mixed_anova(),
obrien_test(),
pairwise_within(),
randomization_test(),
randomization_test_paired(),
regions_of_significance(),
simple_effects_AB(),
summary_t_test(),
welch_t()
Author
Ken Kelley kkelley@nd.edu
Examples
# Wide-format example: simulated within-subjects data with 4 levels.
set.seed(113)
Y <- matrix(rnorm(20 * 4), nrow = 20)
mauchly_test(Y)
#> W statistic df p_value n_subjects n_levels method
#> 0.597 9.13 5 0.1045 20 4 Mauchly's test of sphericity
# Long-format example using built-in nlme::Orthodont (4 ages per subject).
mauchly_test(nlme::Orthodont, id = "Subject", time = "age",
outcome = "distance")
#> W statistic df p_value n_subjects n_levels method
#> 0.758 6.85 5 0.2326 27 4 Mauchly's test of sphericity