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
aovorlmmodel, a repeated-measuresaovmodel with anError()term (classaovlist), anafexmodel (classafex_aov), a linear mixed model fromlme4::lmer()orlmerTest::lmer(), a multivariate model fromstats::manova()or fromstats::lm()with several outcomes (classmlm), or an ANOVA table fromstats::anova(),car::Anova(), or lmerTest'sanova().- anova_parameters
columns to display.
"Effect_Size"stands for whichever effect sizeeffect_size,partial, andgeneralizedselect, 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\)). IfNULL, 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 foreffect_size = "eta".- type
type of sums of squares for
aovandlmmodels:1(sequential, default, as instats::anova()),2, or3. Types 2 and 3 are computed withcar::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, or1. Ignored for ANOVA tables, which already have a type.- ci
confidence level for the effect size interval, shown if
anova_parametersincludes"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 byeffectsizecan 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". Forcar::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 withcbind()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.
References
Greenhouse, S. W., & Geisser, S. (1959). On methods in the analysis of profile data. Psychometrika, 24(2), 95–112. 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. 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. 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. 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. 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. doi:10.1214/aoms/1177728599
Wilks, S. S. (1932). Certain generalizations in the analysis of variance. Biometrika, 24(3/4), 471–494. 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)
#> # A tibble: 4 × 7
#> Source `*SS*` `*df*` `*MS*` `*F*` `*p*` `*η*^2^~p~`
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Cyl 824.78 2 412.39 "44.85" "<.001" ".78"
#> 2 Am 36.77 1 36.77 " 4.00" " .06 " ".13"
#> 3 Cyl × Am 25.44 2 12.72 " 1.38" " .27 " ".10"
#> 4 Error 239.06 26 9.19 "" "" ""
# 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
)
#> # A tibble: 4 × 8
#> Source `*SS*` `*df*` `*MS*` `*F*` `*p*` `*ω*^2^~p~` `90% CI`
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Cyl 824.78 2 412.39 "44.85" "<.001" ".73" "[.56, .82]"
#> 2 Am 36.77 1 36.77 " 4.00" " .06 " ".09" "[.00, .29]"
#> 3 Cyl × Am 25.44 2 12.72 " 1.38" " .27 " ".02" "[.00, .13]"
#> 4 Error 239.06 26 9.19 "" "" "" ""
# Type 2 sums of squares (requires the car package)
if (requireNamespace("car", quietly = TRUE)) {
apa_anova(fit, type = 2)
}
#> # A tibble: 4 × 7
#> Source `*SS*` `*df*` `*MS*` `*F*` `*p*` `*η*^2^~p~`
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Cyl 456.40 2 228.20 "24.82" "<.001" ".66"
#> 2 Am 36.77 1 36.77 " 4.00" " .06 " ".13"
#> 3 Cyl × Am 25.44 2 12.72 " 1.38" " .27 " ".10"
#> 4 Error 239.06 26 9.19 "" "" ""
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)
}
#> Registered S3 method overwritten by 'lme4':
#> method from
#> na.action.merMod car
#> Contrasts set to contr.sum for the following variables: treatment
#> # A tibble: 3 × 7
#> Effect `*df*~effect~` `*df*~error~` `*MSE*` `*F*` `*p*` `*η*^2^~G~`
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Treatment 2.00 13.00 6.41 2.91 .09 .27
#> 2 Phase 1.74 22.64 0.81 19.29 <.001 .21
#> 3 Treatment × … 3.48 22.64 0.81 5.43 .004 .13
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)
}
#> # A tibble: 1 × 5
#> Effect `*df*~effect~` `*df*~error~` `*F*` `*p*`
#> <chr> <chr> <chr> <chr> <chr>
#> 1 Days 1 17.00 45.85 <.001
# 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)
}
#> # A tibble: 9 × 7
#> Source `*SS*` `*df*` `*MS*` `*F*` `*p*` `*η*^2^`
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Post Test 1 "" "" "" "" "" ""
#> 2 Group "108.12" " 2" "54.06" "5.32" ".007" ".14"
#> 3 Error "640.50" "63" "10.17" "" "" ""
#> 4 Post Test 2 "" "" "" "" "" ""
#> 5 Group " 95.12" " 2" "47.56" "8.41" "<.001" ".21"
#> 6 Error "356.41" "63" " 5.66" "" "" ""
#> 7 Post Test 3 "" "" "" "" "" ""
#> 8 Group " 357.30" " 2" "178.65" "4.48" ".01" ".12"
#> 9 Error "2,511.68" "63" " 39.87" "" "" ""