Tests 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).
mauchly_test(x, id = NULL, time = NULL, outcome = NULL)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.
Either an \(n \times k\) numeric matrix or
data.frame (rows = subjects, columns = repeated measurements);
or a long-format data.frame together with id,
time, and outcome column names.
Column name in x identifying the subject when x is in long format (NULL otherwise).
Column name in x identifying the within-subjects factor level when x is in long format (NULL otherwise).
Column name in x identifying the dependent variable when x is in long format (NULL otherwise).
Ken Kelley [email protected]
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.
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.)
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()
# Wide-format example: simulated within-subjects data with 4 levels.
set.seed(113)
Y <- matrix(rnorm(20 * 4), nrow = 20)
mauchly_test(Y)
# Long-format example using built-in nlme::Orthodont (4 ages per subject).
mauchly_test(nlme::Orthodont, id = "Subject", time = "age",
outcome = "distance")
Run the code above in your browser using DataLab