apa_anova: Format ANOVA tables in APA style

View source: R/anova.R

apa_anovaR Documentation

Format ANOVA tables in APA style

Description

Makes an analysis of variance source table with sums of squares, degrees of freedom, mean squares, F tests, p-values, and effect sizes. Values come from parameters::model_parameters(), and effect sizes come from the effectsize package (e.g., effectsize::eta_squared()).

Usage

apa_anova(
  fit,
  anova_parameters = c("Parameter", "Sum_Squares", "df", "Mean_Square", "F", "p",
    "Effect_Size"),
  effect_size = c("eta", "omega", "epsilon"),
  partial = TRUE,
  generalized = FALSE,
  type = NULL,
  ci = 0.95,
  residual_label = "Error",
  starred = NA,
  bolded = NA,
  column_formats = NULL,
  ...
)

## S3 method for class 'lm'
apa_anova(
  fit,
  anova_parameters = c("Parameter", "Sum_Squares", "df", "Mean_Square", "F", "p",
    "Effect_Size"),
  effect_size = c("eta", "omega", "epsilon"),
  partial = TRUE,
  generalized = FALSE,
  type = NULL,
  ci = 0.95,
  residual_label = "Error",
  starred = NA,
  bolded = NA,
  column_formats = NULL,
  ...
)

## S3 method for class 'aovlist'
apa_anova(
  fit,
  anova_parameters = c("Parameter", "Sum_Squares", "df", "Mean_Square", "F", "p",
    "Effect_Size"),
  effect_size = c("eta", "omega", "epsilon"),
  partial = TRUE,
  generalized = FALSE,
  type = NULL,
  ci = 0.95,
  residual_label = "Error",
  starred = NA,
  bolded = NA,
  column_formats = NULL,
  ...
)

## S3 method for class 'anova'
apa_anova(
  fit,
  anova_parameters = c("Parameter", "Sum_Squares", "df", "Mean_Square", "F", "p",
    "Effect_Size"),
  effect_size = c("eta", "omega", "epsilon"),
  partial = TRUE,
  generalized = FALSE,
  type = NULL,
  ci = 0.95,
  residual_label = "Error",
  starred = NA,
  bolded = NA,
  column_formats = NULL,
  ...
)

## S3 method for class 'afex_aov'
apa_anova(
  fit,
  anova_parameters = c("Parameter", "df", "df_error", "Mean_Square", "F", "p",
    "Effect_Size"),
  effect_size = c("eta", "omega", "epsilon"),
  partial = TRUE,
  generalized = TRUE,
  type = NULL,
  ci = 0.95,
  residual_label = "Error",
  starred = NA,
  bolded = NA,
  column_formats = NULL,
  ...
)

## S3 method for class 'merMod'
apa_anova(
  fit,
  anova_parameters = mixed_anova_parameters,
  effect_size = NULL,
  partial = TRUE,
  generalized = FALSE,
  type = NULL,
  ci = 0.95,
  residual_label = "Error",
  starred = NA,
  bolded = NA,
  column_formats = NULL,
  ddf = c("Kenward-Roger", "Satterthwaite"),
  ...
)

## Default S3 method:
apa_anova(fit, ...)

## S3 method for class 'mlm'
apa_anova(
  fit,
  anova_parameters = manova_anova_parameters,
  effect_size = c("eta", "omega", "epsilon"),
  partial = TRUE,
  generalized = FALSE,
  type = NULL,
  ci = 0.95,
  residual_label = "Error",
  starred = NA,
  bolded = NA,
  column_formats = NULL,
  test = c("Pillai", "Wilks", "Hotelling-Lawley", "Roy"),
  univariate = FALSE,
  ...
)

## S3 method for class 'manova'
apa_anova(
  fit,
  anova_parameters = manova_anova_parameters,
  effect_size = c("eta", "omega", "epsilon"),
  partial = TRUE,
  generalized = FALSE,
  type = NULL,
  ci = 0.95,
  residual_label = "Error",
  starred = NA,
  bolded = NA,
  column_formats = NULL,
  test = c("Pillai", "Wilks", "Hotelling-Lawley", "Roy"),
  univariate = FALSE,
  ...
)

## S3 method for class 'Anova.mlm'
apa_anova(
  fit,
  anova_parameters = manova_anova_parameters,
  effect_size = c("eta", "omega", "epsilon"),
  partial = TRUE,
  generalized = FALSE,
  type = NULL,
  ci = 0.95,
  residual_label = "Error",
  starred = NA,
  bolded = NA,
  column_formats = NULL,
  test = NULL,
  univariate = FALSE,
  ...
)

Arguments

fit

an aov or lm model, a repeated-measures aov model with an Error() term (class aovlist), an afex model (class afex_aov), a linear mixed model from lme4::lmer() or lmerTest::lmer(), a multivariate model from stats::manova() or from stats::lm() with several outcomes (class mlm), or an ANOVA table from stats::anova(), car::Anova(), or lmerTest's anova().

anova_parameters

columns to display. "Effect_Size" stands for whichever effect size effect_size, partial, and generalized select, and "CI" adds its confidence interval as [LL, UL]. Columns not in the ANOVA table are silently dropped.

effect_size

effect size to display: "eta" (\eta^2, default), "omega" (\omega^2), or "epsilon" (\epsilon^2). If NULL, no effect size is computed.

partial

if TRUE (default), partial effect sizes (e.g., \eta^2_p) are displayed. For one-way designs, partial and non-partial effect sizes are the same.

generalized

if TRUE, generalized \eta^2 (\eta^2_G) is displayed instead, which is comparable across between- and within-subjects designs. Only for effect_size = "eta".

type

type of sums of squares for aov and lm models: 1 (sequential, default, as in stats::anova()), 2, or 3. Types 2 and 3 are computed with car::Anova(). Type 3 tests are interpretable only when factors have sum-to-zero contrasts (e.g., contr.sum) and covariates are centered. For linear mixed models, the type of hypothesis tests: 3 (default, as in lmerTest), 2, or 1. Ignored for ANOVA tables, which already have a type.

ci

confidence level for the effect size interval, shown if anova_parameters includes "CI". Intervals are two-sided, so a 90% interval excludes 0 when the F test is significant at \alpha = .05, and its lower bound is 0 otherwise. Intervals are not shown for generalized \eta^2, because those computed by effectsize can exclude the point estimate.

residual_label

label for residual (error) rows

starred

columns to star with significant p-values (e.g., "F")

bolded

columns to bold, if significant

column_formats

column_formats object to format columns. If NULL, the default column_formats is used.

...

further arguments passed to parameters::model_parameters()

ddf

for linear mixed models, method of approximating the denominator degrees of freedom: "Kenward-Roger" (default) or "Satterthwaite"

test

for multivariate models, the multivariate test statistic: "Pillai" (default), "Wilks", "Hotelling-Lawley", or "Roy". For car::Anova() tables, the statistic of the table by default.

univariate

for multivariate models, if TRUE, the univariate ANOVA of each outcome instead of the multivariate tests. The outcomes must be given with cbind() in the model formula.

Details

For repeated-measures models fit with aov(y ~ a * b + Error(id / b)), each error stratum is introduced by a heading row ("Between subjects" or "Within subjects"), and each stratum's error term follows its effects.

Model comparisons (e.g., anova(m1, m2)) are not ANOVA source tables. Use apa_performance_comparison() for them.

For afex models (afex::aov_car(), afex::aov_ez(), afex::aov_4()), each effect has its own error term, so the table shows each effect's degrees of freedom (df~effect~, df~error~), mean squared error (MSE), F, p, and effect size, as in afex's own nice() tables. Degrees of freedom and p-values reflect the sphericity correction set in afex (Greenhouse-Geisser by default), and generalized \eta^2 is the default effect size, as in afex.

For linear mixed models fit with lme4::lmer() or lmerTest::lmer(), F tests of the fixed effects come from the lmerTest package, which approximates the denominator degrees of freedom with Kenward-Roger's method (default, as in apa_parameters(), which requires the pbkrtest package) or Satterthwaite's method (ddf = "Satterthwaite"). Tests are Type III by default, as in lmerTest, whose Type III tests do not depend on how factors are coded. The table shows each effect's degrees of freedom (df~effect~, df~error~), F, and p. Sums of squares and effect sizes have no agreed-upon definition in mixed models, so they are not shown by default. With effect_size = "eta" (or "omega" or "epsilon"), partial effect sizes are computed from F and its degrees of freedom (e.g., effectsize::F_to_eta2()), which only approximates them. ANOVA tables made by lmerTest's anova() are displayed the same way. Generalized linear mixed models (lme4::glmer()) have no F tests; use apa_parameters() for them.

For multivariate analyses of variance, from stats::manova() or from stats::lm() with several outcomes (lm(cbind(y1, y2) ~ x)), the table has a row for each effect with its multivariate test statistic (Pillai's trace by default; test chooses Wilks's lambda, the Hotelling–Lawley trace, or Roy's largest root), its approximate F test (df~1~, df~2~, p), and partial \eta^2, computed from the approximate F and its degrees of freedom (e.g., effectsize::F_to_eta2()). Sums of squares are sequential (Type I) by default, as in stats::summary.manova(); type = 2 or 3 gives car::Anova() tests. car::Anova() tables of such models (class Anova.mlm) are displayed the same way. The intercept is not shown. With univariate = TRUE, the table instead shows the univariate ANOVA of each outcome, under a heading row for each outcome, as a follow-up to the multivariate tests.

Value

apa7_tbl (tibble)

References

Greenhouse, S. W., & Geisser, S. (1959). On methods in the analysis of profile data. Psychometrika, 24(2), 95–112. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/BF02289823")}

Huynh, H., & Feldt, L. S. (1976). Estimation of the Box correction for degrees of freedom from sample data in randomized block and split-plot designs. Journal of Educational Statistics, 1(1), 69–82. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.3102/10769986001001069")}

Kenward, M. G., & Roger, J. H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53(3), 983–997. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/2533558")}

Olejnik, S., & Algina, J. (2003). Generalized eta and omega squared statistics: Measures of effect size for some common research designs. Psychological Methods, 8(4), 434–447. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1037/1082-989X.8.4.434")}

Satterthwaite, F. E. (1946). An approximate distribution of estimates of variance components. Biometrics Bulletin, 2(6), 110–114. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/3002019")}

Pillai, K. C. S. (1955). Some new test criteria in multivariate analysis. The Annals of Mathematical Statistics, 26(1), 117–121. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1214/aoms/1177728599")}

Wilks, S. S. (1932). Certain generalizations in the analysis of variance. Biometrika, 24(3/4), 471–494. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/biomet/24.3-4.471")}

Examples

d <- mtcars
d$cyl <- factor(d$cyl)
d$am <- factor(d$am)
fit <- aov(mpg ~ cyl * am, data = d)
apa_anova(fit)

# Omega squared with a 90% confidence interval
apa_anova(
  fit,
  anova_parameters = c(
    "Parameter", "Sum_Squares", "df", "Mean_Square", "F", "p",
    "Effect_Size", "CI"
  ),
  effect_size = "omega",
  ci = .90
)

# Type 2 sums of squares (requires the car package)
if (requireNamespace("car", quietly = TRUE)) {
  apa_anova(fit, type = 2)
}
if (requireNamespace("afex", quietly = TRUE)) {
  data(obk.long, package = "afex")
  fit_afex <- afex::aov_ez(
    "id", "value", obk.long,
    between = "treatment", within = "phase", fun_aggregate = mean
  )
  apa_anova(fit_afex)
}
if (requireNamespace("lme4", quietly = TRUE) &&
  requireNamespace("lmerTest", quietly = TRUE) &&
  requireNamespace("pbkrtest", quietly = TRUE)) {
  fit_lmer <- lme4::lmer(
    Reaction ~ Days + (Days | Subject),
    data = lme4::sleepstudy
  )
  apa_anova(fit_lmer)
}
# Multivariate analysis of variance
if (requireNamespace("carData", quietly = TRUE)) {
  fit_manova <- manova(
    cbind(post.test.1, post.test.2, post.test.3) ~ group,
    data = carData::Baumann
  )
  apa_anova(fit_manova)
  apa_anova(fit_manova, test = "Wilks")
  # Univariate follow-ups
  apa_anova(fit_manova, univariate = TRUE)
}

apa7 documentation built on Dec. 1, 2026, 5:06 p.m.