Creates an ANOVA table in APA style based output of ezANOVA command from ez package
Source:R/apaEZANOVA.R
apa.ezANOVA.table.Rd
Creates an ANOVA table in APA style based output of ezANOVA command from ez package
Usage
apa.ezANOVA.table(
ez.output,
correction = "GG",
table.title = "",
filename,
table.number = 0
)
Arguments
- ez.output
Output object from ezANOVA command from ez package
- correction
Type of sphercity correction: "none", "GG", or "HF" corresponding to none, Greenhouse-Geisser and Huynh-Feldt, respectively.
- table.title
String containing text for table title
- filename
(optional) Output filename document filename (must end in .rtf or .doc only)
- table.number
Integer to use in table number output line
Examples
if (requireNamespace("ez", quietly = TRUE)){
if (requireNamespace("apaTables", quietly = TRUE)){
if (requireNamespace("tidyr", quietly = TRUE)){
#
# ** Example 1: Between Participant Predictors
#
goggles <- apaTables::goggles
# Use ezANOVA
# Be sure use the options command, as below, to ensure sufficient digits
options(digits = 10)
goggles_results <- ez::ezANOVA(data = goggles,
dv = attractiveness,
between = .(gender, alcohol),
participant ,
detailed = TRUE)
# Make APA table - save after all 3 examples
goggles_table <- apa.ezANOVA.table(goggles_results)
# Create a table for your PDF
# Include the lines below in your rmarkdown or Quarto document
apa.knit.table.for.pdf(goggles_table)
#
# ** Example 2: Within Participant Predictors
#
drink_attitude_wide <- apaTables::drink_attitude_wide
# Convert data from wide format to long format where one row represents one OBSERVATION.
# Wide format column names MUST represent levels of each variable separated by an underscore.
# See vignette for further details.
drink_attitude_long <- tidyr::pivot_longer(drink_attitude_wide,
cols = beer_positive:water_neutral,
names_to = c("drink", "imagery"),
names_sep = "_",
values_to = "attitude")
drink_attitude_long$drink <- as.factor(drink_attitude_long$drink)
drink_attitude_long$imagery <- as.factor(drink_attitude_long$imagery)
# Set contrasts to match Field et al. (2012) textbook output
alcohol_vs_water <- c(1, 1, -2)
beer_vs_wine <- c(-1, 1, 0)
negative_vs_other <- c(1, -2, 1)
positive_vs_neutral <- c(-1, 0, 1)
contrasts(drink_attitude_long$drink) <- cbind(alcohol_vs_water, beer_vs_wine)
contrasts(drink_attitude_long$imagery) <- cbind(negative_vs_other, positive_vs_neutral)
# Use ezANOVA
# Be sure use the options command, as below, to ensure sufficient digits
options(digits = 10)
drink_attitude_results <- ez::ezANOVA(data = drink_attitude_long,
dv = .(attitude), wid = .(participant),
within = .(drink, imagery),
type = 3, detailed = TRUE)
# Make APA table - save after all 3 examples
drink_table <- apa.ezANOVA.table(drink_attitude_results)
# Create a table for your PDF
# Include the lines below in your rmarkdown or Quarto document
apa.knit.table.for.pdf(drink_table)
#
# ** Example 3: Between and Within Participant Predictors
#
dating_wide <- apaTables::dating_wide
# Convert data from wide format to long format where one row represents one OBSERVATION.
# Wide format column names MUST represent levels of each variable separated by an underscore.
# See vignette for further details.
dating_long <- tidyr::pivot_longer(dating_wide,
cols = attractive_high:ugly_none,
names_to = c("looks", "personality"),
names_sep = "_",
values_to = "date_rating")
#'
dating_long$looks <- as.factor(dating_long$looks)
dating_long$personality <- as.factor(dating_long$personality)
# Set contrasts to match Field et al. (2012) textbook output
some_vs_none <- c(1, 1, -2)
hi_vs_av <- c(1, -1, 0)
attractive_vs_ugly <- c(1, 1, -2)
attractive_vs_average <- c(1, -1, 0)
contrasts(dating_long$personality) <- cbind(some_vs_none, hi_vs_av)
contrasts(dating_long$looks) <- cbind(attractive_vs_ugly, attractive_vs_average)
# Use ezANOVA
options(digits = 10)
dating_results <-ez::ezANOVA(data = dating_long, dv = .(date_rating),
wid = .(participant),
between = .(gender),
within = .(looks, personality),
type = 3, detailed = TRUE)
# Make APA table - save after all 3 examples
dating_table <- apa.ezANOVA.table(dating_results)
# Create a table for your PDF
# Include the lines below in your rmarkdown or Quarto document
apa.knit.table.for.pdf(dating_table)
#
# Saving all three tables
#
apa.save("tables_ezANOVA.doc",
goggles_table,
drink_table,
dating_table)
# delete demo file
if (file.exists("tables_ezANOVA.doc")) {
file.remove("tables_ezANOVA.doc")
}
}}}
#> Coefficient covariances computed by hccm()
#> [1] TRUE