R logo

R package

tidystats is an R package designed to enable researchers to combine the output of their statistical 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 R 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 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.

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

add_stats() has two necessary arguments:

Optionally, you can also add meta-information about the analysis:

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

An example

Below you can find an example of how to use tidystats to combine the output of multiple statistical analyses.

The first step is to load the tidystats package.

library(tidystats)

The code below shows how to combine the output of three different types of analyses: a t-test, a linear regression, and an ANOVA. The output of each analysis is stored in their own variable, called sleep_t_test, D9_lm and npk_aov, respectively.

# t-test
sleep_wide <- reshape(
  sleep,
  direction = "wide",
  idvar = "ID",
  timevar = "group",
  sep = "_"
)
sleep_t_test <- t.test(
  sleep_wide$extra_1, 
  sleep_wide$extra_2, 
  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)
D9_lm <- lm(weight ~ group)

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

After storing the output in variables, create an empty list to collect the statistics of each analysis. Below an empty list is created using list() and stored in a variable called called statistics. Use the add_stats() function to add the output of each analysis to this list. Additional meta-information can be added such as whether the analysis was a primary analysis or preregistered.

# Create an empty list to store the statistics in
statistics <- list()
          
# Add statistics to the list
statistics <- statistics |>
  add_stats(sleep_t_test, type = "primary", preregistered = TRUE) |>
  add_stats(D9_lm) |>
  add_stats(npk_aov, notes = "An ANOVA example")

With the output of the the analyses stored in a single list, use thewrite_stats() function to save the list to a file. Remember to specify the file extension of the file as ".json".

write_stats(statistics, "statistics.json")

This produces a file with the output stored in the JSON format. This is a machine-readable format that makes it possible to easily extract statistics using software (like the Microsoft Word add-in). Click here if you want to check out what the file of this example looks like.

Supported R packages

tidystats has built-in support for a range of functions from various statistical analysis packages. This means that tidystats can automatically extract the statistics that are returned by these functions. See below for an overview of supported functions.

PackageFunction
afexaov_ez(), aov_car(), aov_4(), mixed()
BayesFactorgeneralTestBF(), lmBF(), regressionBF(), ttestBF(), anovaBF(), correlationBF(), contingencyTableBF(), proportionBF(), meta.ttestBF()
effectsizecohens_d(), hedges_g(), glass_delta()
effsizecohen.d(), VD.A(), cliff.delta()
emmeansemmeans(), contrast(), test(), mvcontrast(), eff_size(), emtrends(), joint_tests(), ref_grid()
Hmiscrcorr()
irricc()
lme4lmer(), anova()
lmerTestlmer(), anova()
tidystatscount_data(), describe_data()
statsanova(), ansari.test(), aov(), bartlett.test(), binom.test(), Box.test(), chisq.test(), confint(), cor.test(), fisher.test(), fligner.test(), friedman.test(), glm(), kruskal.test(), ks.test(), lm(), mantelhaen.test(), mauchly.test(), mcnemar.test(), mood.test(), oneway.test(), pairwise.t.test(), pairwise.prop.test(), pairwise.wilcox.test(), poisson.test(), PP.test(), prop.test(), prop.trend.test(), quade.test(), shapiro.test(), t.test(), var.test(), wilcox.test()

If a function is missing from the list you can request it to be added by contacting me (see the Support page) or creating an issue on GitHub.

tidystats does not require built-in support for a function for it to be used. You can use tidystats to store and report any statistic. For more on this, see the Tips section.