tidystats logo

R package

tidystats is an R package designed to enable researchers to combine the output of their analyses into a single file that can be shared with others or used to report statistics. This means that to use tidystats, you need to know R. There are many different places to learn R, such as this introduction or this book on using R for Data Science.

Below I explain how the tidystats package works and provide some example code to help you get started.

Installation

tidystats is available on CRAN. This means the package can be installed using the following code:

install.packages("tidystats")

Usage

tidystats is designed to have a minimal impact on the way you would normally conduct analyses in R. The idea behind tidystats is that you run the analyses and store the output of each analysis in a variable. You then add these variables to a list and save the list to a file on your computer.

The main functions are add_stats() and write_stats().

add_stats() has two necessary arguments:

Optionally, you can also specify an identifier, the type of analysis, whether the analysis was preregistered, and/or additional notes. This meta-information will be added to the analysis when you add it to the list.

write_stats() is the function to save the statistics to a file on your computer. It requires a list containing the analyses as its first argument and a path name to a file on your computer as its second argument.

An example

Below I show an example of how to use tidystats.

The first step is to load the necessary packages. I load the tidystats package to get access to the tidystats functions and I load the dplyr package for access to the %>% operator.

library(tidystats)
library(dplyr)

In the code below I conduct three different types of analyses: a t-test, a linear regression, and an ANOVA. I store the result of each analysis in their own variable, called sleep_test, lm_D9 and npk_aov, respectively.

# t-test:
sleep_test <- t.test(extra ~ group, data = sleep, paired = TRUE)

# lm:
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)

lm_D9 <- lm(weight ~ group)

# ANOVA:
npk_aov <- aov(yield ~ block + N*P*K, npk)

Next, I use tidystats to collect the statistics of each analysis. I start by creating an empty list called 'results' and then use the add_stats() function to add each analysis to this list. I also add some additional meta-information such as whether the analysis was a primary analysis or preregistered.

# Create an empty list
results <- list()

# Add the analyses to the empty list
results <- results %>%
  add_stats(sleep_test, type = "primary") %>%
  add_stats(lm_D9, preregistered = FALSE) %>%
  add_stats(npk_aov, notes = "An ANOVA example")

With all the analyses now stored in a single list, I use the write_stats() function to save the results to a file.

write_stats(results, "results.json")

This produces a JSON file. The JSON file contains all statistics in a machine-readable format. If you want to check out what the file of this example looks like, click here.

Supported functions

tidystats supports the following R functions:

stats
  • t.test()
  • cor.test()
  • chisq.test()
  • wilcox.test()
  • fisher.test()
  • oneway.test()
  • aov()
  • lm()
  • anova()
lme4
  • lmer()
lmerTest
  • lmer()
tidystats
  • describe_data()
  • count_data()
BayesFactor
  • generalTestBF()
  • lmBF()
  • regressionBF()
  • ttestBF()
  • anovaBF()
  • correlationBF()
  • contingencyTableBF()
  • meta.ttestBF()

Support

Do you have a question or comment, such as a feature request, about tidystats? Check out the support page for ways to contact me.