APA Tables and Psychology Oriented Analysis in R with the rempsyc Package

The rempsyc package in R provides a number of useful tools for researchers, including producing APA formatted tables and exporting them to Word for publication, testing regression assumptions, presenting contrasts, moderation, slope analysis, and other useful analysis and presentation tools, particularly for those working in Psychology or fields that use APA styled formatting and analysis.

In this video I demonstrate how to produce APA tables of t-test results (with and without a Bonferroni correction), how to produce tables of regression assumption tests and regression results, tables of contrasts, and violin plots showing those contrasts.

Subscribe below to get updates on my latest videos, courses, and other useful information.


# reformatted t-test results (can be single or multiple)
t.test.results<- nice_t_test(data = mtcars,
            response = names(mtcars)[1:6],
            group = "am", warning = FALSE) 

# with Bonferroni correction
nice_t_test(data = mtcars, response = names(mtcars)[1:6],
            group = "am", correction = "bonferroni", warning = FALSE)

# APA table (2nd one highlights rows with p<.05)
nice_table(t.test.results, highlight=TRUE)

#save to Word
my_table <- nice_table(t.test.results)
save_as_docx(my_table, path = "t-tests.docx")

# regression example using mtcars data
model <- lm(mpg ~ wt * cyl + gear, data = mtcars)
nice_table(nice_assumptions(model), col.format.p = 2:4)
nice_table(nice_lm(model, b.label="B"))

# contrasts and violin plots with iris data
table.stats <- nice_contrasts(response = "Sepal.Length",
                              group = "Species", data = iris)

figure <- nice_violin(group = "Species", 
    response = "Sepal.Length", data = iris,
    ytitle = "Length of Sepal", 
    signif_annotation = c("***", "***", "***"),
    signif_yposition = c(8.7, 7.3, 8.2),
    signif_xmin = c("setosa", "setosa", "versicolor"),
    signif_xmax = c("virginica", "versicolor", "virginica"))

# save figure as pdf
ggplot2::ggsave('Figure 1.pdf', figure, width = 7, height = 7, 
                unit = 'in', dpi = 300)