The Analysis of Variance (ANOVA) is used to explore the relationship between a continuous dependent variable, and one or more categorical explanatory variables.

ANOVA assumes that the residuals are normally distributed, and that the variances of all groups are equal. If one is unwilling to assume that the variances are equal, then a Welch’s test can be used instead (However, the Welch’s test does not support more than one explanatory factor). Alternatively, if one is unwilling to assume that the data is normally distributed, a non-parametric approach (such as Kruskal-Wallis) can be used.

Example usage


ANOVA(formula = len ~ dose * supp, data = ToothGrowth)

#  ───────────────────────────────────────────────────────────────────────
#                 Sum of Squares    df    Mean Square    F        p
#  ───────────────────────────────────────────────────────────────────────
#    dose                   2426     2         1213.2    92.00    < .001
#    supp                    205     1          205.4    15.57    < .001
#    dose:supp               108     2           54.2     4.11     0.022
#    Residuals               712    54           13.2
#  ───────────────────────────────────────────────────────────────────────

    formula = len ~ dose * supp,
    data = ToothGrowth,
    emMeans = ~ supp + dose:supp, # est. marginal means for supp and dose:supp
    emmPlots = TRUE,              # produce plots of those marginal means
    emmTables = TRUE)             # produce tables of those marginal means


data the data as a data frame
dep the dependent variable from data, variable must be numeric (not necessary when providing a formula, see examples)
factors the explanatory factors in data (not necessary when providing a formula, see examples)
effectSize one or more of 'eta', 'partEta', or 'omega'; use η², partial η², and ω² effect sizes, respectively
modelTest TRUE or FALSE (default); perform an overall model test
modelTerms a formula describing the terms to go into the model (not necessary when providing a formula, see examples)
ss '1', '2' or '3' (default), the sum of squares to use
homo TRUE or FALSE (default), perform homogeneity tests
norm TRUE or FALSE (default), perform Shapiro-Wilk tests of normality
qq TRUE or FALSE (default), provide a Q-Q plot of residuals
contrasts a list of lists specifying the factor and type of contrast to use, one of 'deviation', 'simple', 'difference', 'helmert', 'repeated' or 'polynomial'
postHoc a formula containing the terms to perform post-hoc tests on (see the examples)
postHocCorr one or more of 'none', 'tukey', 'scheffe', 'bonf', or 'holm'; provide no, Tukey, Scheffe, Bonferroni, and Holm Post Hoc corrections respectively
postHocES a possible value of 'd'; provide cohen's d measure of effect size for the post-hoc tests
postHocEsCi TRUE or FALSE (default), provide confidence intervals for the post-hoc effect sizes
postHocEsCiWidth a number between 50 and 99.9 (default: 95), the width of confidence intervals for the post-hoc effect sizes
emMeans a formula containing the terms to estimate marginal means for (see the examples)
emmPlots TRUE (default) or FALSE, provide estimated marginal means plots
emmPlotData TRUE or FALSE (default), plot the data on top of the marginal means
emmPlotError 'none', 'ci' (default), or 'se'. Use no error bars, use confidence intervals, or use standard errors on the marginal mean plots, respectively
emmTables TRUE or FALSE (default), provide estimated marginal means tables
emmWeights TRUE (default) or FALSE, weigh each cell equally or weigh them according to the cell frequency
ciWidthEmm a number between 50 and 99.9 (default: 95) specifying the confidence interval width for the estimated marginal means


A results object containing:

results$main a table
results$assump$homo a table
results$assump$norm a table
results$contrasts an array of tables
results$postHoc an array of tables
results$emm an array of groups

Tables can be converted to data frames with asDF or For example:


Elements in arrays can be accessed with [[n]]. For example:

results$contrasts[[1]] # accesses the first element