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.
tidystats is available on CRAN. This means the package can be installed using the following code:
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() has two necessary arguments:
results: A list you want to add the statistical output to. You can create an empty list with the
output: The output of a statistical analysis you want to add to the list (e.g., the output of
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.
identifier: A name used to identify the model (e.g., ‘weight_height_correlation’). If you do not provide one, one is automatically created for you based on the name of the variable containing the analysis.
type: A character string specifying the type of analysis as primary, secondary, or exploratory.
preregistered: A boolean (TRUE/FALSE) used to indicate whether the analysis was preregistered or not.
notes: A character string to add additional information which you may find fruitful.
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.
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.
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
# 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.
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.
tidystats supports the following R functions:
Do you have a question or comment, such as a feature request, about tidystats? Check out the support page for ways to contact me.