Computes the classical F-ratios for one- and two-way ANOVA
designs when one or more factors are random rather than fixed,
using the expected-mean-square (EMS) rules that determine the
correct denominator for each test (Searle, Casella, & McCulloch,
1992). The function is the closed-form alternative to fitting via
lmer and is the standard treatment in
classical psychometrics and design-of-experiments texts (Maxwell,
Delaney, & Kelley, 2027, Ch. 10).
mixed_anova(
data,
outcome,
factor_A,
factor_B = NULL,
A_type = c("fixed", "random"),
B_type = c("random", "fixed")
)A data.frame with one row per testable effect.
Columns: effect, ss, df, ms,
denominator, F_value, p_value.
A data.frame containing the response, the
factor(s), and (when both factors are crossed) the subject
identifier.
Character name of the response column.
Character name of factor A.
Character name of factor B, or NULL
for one-way designs. Default NULL.
One of "fixed" (default) or "random":
the EMS classification of factor A.
One of "fixed" or "random" (default):
the EMS classification of factor B. Ignored when
factor_B is NULL.
Ken Kelley [email protected]
One way design (only factor_A).
Both A fixed and A random use the same observed F-ratio \(MS_A / MS_{\mathrm{within}}\); the test of "is there an effect of A?" is identical. The interpretation differs: the random-effects test asks whether the variance component \(\sigma^2_A\) is zero.
Two-way design, both fixed (Model I).
\(F_A = MS_A / MS_{AB}\) (when interaction is present in the model and treated as error) or \(F_A = MS_A / MS_{\mathrm{within}}\) (when interaction is pooled into error). The function uses \(MS_{\mathrm{within}}\) as the denominator throughout for Model I.
Two-way design, both random (Model II).
\(F_A = MS_A / MS_{AB}\), \(F_B = MS_B / MS_{AB}\), \(F_{AB} = MS_{AB} / MS_{\mathrm{within}}\).
Two-way mixed design (Model III, e.g., A fixed, B random).
\(F_A = MS_A / MS_{AB}\) (fixed factor against the interaction with the random factor)
\(F_B = MS_B / MS_{\mathrm{within}}\) (random factor against the within-cell residual)
\(F_{AB} = MS_{AB} / MS_{\mathrm{within}}\).
Balanced data assumed. The classical EMS rules require
equal cell sizes. The function errors out on unbalanced data and
recommends a mixed-effects fit via lmer.
Sums of squares. For the balanced designs this function
targets, the Type I, Type II, and Type III sums of squares for each
effect coincide, so the decomposition is unambiguous and no
sums-of-squares type needs to be chosen (Maxwell, Delaney, &
Kelley, 2027, Ch. 7). The returned object carries a numeric
sum_of_squares_type attribute equal to 3, with the
understanding that it equals Types I and II here; it records the
convention without implying a choice that would matter for these
designs.
Maxwell, S. E., Delaney, H. D., & Kelley, K. (2027). Designing experiments and analyzing data: A model comparison perspective (4th ed.). Routledge. (See Chapter 7 on the sums of squares for balanced designs and Chapter 10 on random and mixed effects.)
Searle, S. R., Casella, G., & McCulloch, C. E. (1992). Variance components. Wiley.
anova_within, anova_within_two_way,
lmer
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(),
mauchly_test(),
obrien_test(),
pairwise_within(),
randomization_test(),
randomization_test_paired(),
regions_of_significance(),
simple_effects_AB(),
summary_t_test(),
welch_t()
Other mixed models:
R2_mixed_effects(),
R2_mixed_effects_decomposition(),
icc_lmer(),
manova_split_plot(),
ss_aipe_mixed_effects(),
ss_aipe_mixed_effects_sensitivity(),
ss_power_mixed_effects(),
ss_power_split_plot_anova()
# 1. Two-way mixed design: A fixed, B random.
set.seed(113)
grid <- expand.grid(A = factor(1:3), B = factor(1:5), rep = 1:4)
grid$y <- with(grid, 0.8 * as.integer(A) + rep(rnorm(5, 0, 1.5), each = 1)[as.integer(B)] +
rnorm(nrow(grid), 0, 1))
mixed_anova(grid, outcome = "y", factor_A = "A", factor_B = "B",
A_type = "fixed", B_type = "random")
Run the code above in your browser using DataLab