Read and use a tidystats file

2022-01-04

Besides using tidystats in combination with Microsoft Word to report statistics, you can also use tidystats to convert a list of statistics into a data frame. This enables researchers to then easily extract specific statistics to perform additional analyses with (e.g., meta-analyses). Below is an example of how to convert a list of statistics to a data frame and several simple operations.

# Load packages
library(tidystats)
library(dplyr)

# Read in a tidystats-produced .json file
results <- read_stats("results.json")

# Convert the list to a data frame
results_df <- tidy_stats_to_data_frame(results)

# Select the p-values
p_values <- filter(results_df, statistic == "p")

With the current example, this results in the following data frame:

identifier term statistic value method type preregistered
sleep_test p 0.003 Paired t-test primary
lm_D9 p 0.249 Linear regression no
lm_D9 (Intercept) p 0.000 Linear regression no
lm_D9 groupTrt p 0.249 Linear regression no
npk_aov block p 0.016 ANOVA
npk_aov N p 0.004 ANOVA
npk_aov P p 0.475 ANOVA
npk_aov K p 0.029 ANOVA
npk_aov N:P p 0.263 ANOVA
npk_aov N:K p 0.169 ANOVA
npk_aov P:K p 0.863 ANOVA

Alternatively, you can select all the significant p-values:

sig_p_values <- filter(results_df, statistic == "p" & value < .05)
identifier term statistic value method type preregistered
sleep_test p 0.003 Paired t-test primary
lm_D9 (Intercept) p 0.000 Linear regression no
npk_aov block p 0.016 ANOVA
npk_aov N p 0.004 ANOVA
npk_aov K p 0.029 ANOVA

This could be useful if you want to conduct a p-curve analysis. Although do note that you should not blindly select all p-values. You should select only the p-values that are relevant to a particular hypothesis. If researchers provide the correct meta-information for each test (e.g., by indicating whether it is a primary analysis), this could help meta-researchers make correct decisions about which statistics to include in their analyses.

In short, by reading a tidystats-produced file of statistics, you can convert the statistics to a data frame using the tidy_stats_to_data_frame function and apply common data transformation functions to extract specific statistics.