Learn R Programming

DMAR (version 1.0.0)

anova_within: One Way Within-Subjects ANOVA With Sphericity Diagnostics and Corrections

Description

Performs the univariate one-way within-subjects F test together with Mauchly's test of sphericity and the three standard \(\varepsilon\)-corrected p-values (Greenhouse-Geisser, Huynh-Feldt, and lower-bound). Returns everything in a single tidy data.frame so the user can decide which adjustment to report.

Usage

anova_within(x, id = NULL, time = NULL, outcome = NULL)

Value

A data.frame with one row per reported F test:

adjustment ("none", "Greenhouse-Geisser",

"Huynh-Feldt", "lower_bound"), F_value,

df_1, df_2, p_value, and epsilon (the correction factor used; NA for the unadjusted row).

attr(<output>, "mauchly") contains the row from

mauchly_test, and the partial \(\eta^2\) is attached as attr(<output>, "partial_eta_squared").

Arguments

x

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.

id

Column name in x identifying the subject when x is in long format (NULL otherwise).

time

Column name in x identifying the within-subjects factor level when x is in long format (NULL otherwise).

outcome

Column name in x identifying the dependent variable when x is in long format (NULL otherwise).

Author

Ken Kelley [email protected]

Details

The unadjusted within-subjects F statistic is the same regardless of sphericity; corrections shrink the numerator and denominator degrees of freedom by a factor of \(\hat\varepsilon \in [1/(k - 1),\, 1]\), and the p-value is recomputed against the adjusted reference F distribution. When Mauchly's test rejects, prefer the Huynh-Feldt-corrected p-value (less conservative than Greenhouse-Geisser).

For multi-factor within-subjects designs or mixed designs, fit the model with stats::aov(... + Error(id/within)) or with lme4::lmer() directly.

References

Maxwell, S. E., Delaney, H. D., & Kelley, K. (2027). Designing experiments and analyzing data: A model comparison perspective (4th ed.). Routledge. (See Chapter 11.)

See Also

mauchly_test, epsilon_corrections, aov

Other within-subjects analysis: anova_within_two_way(), epsilon_corrections(), mauchly_test(), pairwise_within(), plot_trajectories_fitted()

Other hypothesis tests: adjusted_means(), ancova(), ci_dunnett(), ci_scheffe(), ci_tukey_kramer(), compare_cov_structures(), contrast_test(), correlations_test(), equivalence_r(), equivalence_smd(), factorial_anova(), manova_split_plot(), mauchly_test(), mixed_anova(), obrien_test(), pairwise_within(), randomization_test(), randomization_test_paired(), regions_of_significance(), simple_effects_AB(), summary_t_test(), welch_t()

Examples

Run this code
# Simulated within-subjects data with no real effect.
set.seed(113)
Y <- matrix(rnorm(20 * 4), nrow = 20)
anova_within(Y)

# Built-in within-subjects example: nlme::Orthodont (distance ~ age).
res <- anova_within(nlme::Orthodont,
                    id = "Subject", time = "age", outcome = "distance")
res
attr(res, "mauchly")
attr(res, "partial_eta_squared")

Run the code above in your browser using DataLab