knitr::opts_chunk$set(echo = TRUE)

The tidy_anova() function can be used to create an ANOVA table that is outputted as a data frame. This is useful for implementation with kable() and other R functions. The function takes as its input an lm object.

# Fit model with lm()
lm.1 = lm(mpg ~ 1 + wt + hp, data = mtcars)

# Load educate package
library(educate)

# Obtain ANOVA table
tidy_anova(lm.1)

Model-Level Output

The function takes an optional argument of model=TRUE. This argument will create the model-level ANOVA table that is commonly presented in APA publications.

# Obtain model-level ANOVA table
tidy_anova(lm.1, model = TRUE)

Pretty Tables with kable()

Since tidy_anova() outputs a data frame, you can use knitr's kable() function to make it look great in a knitted document.

#Load libraries
library(dplyr)
library(knitr)

# Set knitr options to remove NA values
options(knitr.kable.NA = '')

# Obtain model-level ANOVA table and make it pretty
tidy_anova(lm.1, model = TRUE) %>%
  kable(digits = 2)


zief0002/educate documentation built on July 27, 2023, 9:25 a.m.