# knitr::opts_chunk$set( # collapse = TRUE, # comment = "#>", # fig.path = "man/figures/README-", # out.width = "100%" # ) knitr::opts_chunk$set( warning = F, message = F ) options(tibble.print_min = 5, tibble.print_max = 5, tibble.width = Inf)
tidyreport is a pipeline to conduct common statistical analyses, especially those done in the field of epidemiology and biostatistics and generate clean/formatted tables from the statistical output. The analyses include sample descriptive statistics, univariable testing (Wilcoxon rank sum, KW tests, Chisq/Fisher), regression analysis (linear, logistic, tobit, ordinal, LME, Normal GEE, Logistic GEE, Poisson GEE, Ordinal GEE, cox). The generated tables can be readily copied into Excel or Word for scientific paper writing.
The main functions are:
get_desc_stat()
generates descrptive statistics of the sample.get_desc_stat_grouping()
generates descrptive statistics of the sample and stratified by a grouping variable, along with statistical testing of group differences.get_regression_estimates()
runs different types of regression and summarizes its results.cox_summary()
summarizes the results of cox regression. install.packages("devtools") devtools::install_github("JiyueQin/tidyreport")
library(tidyreport) # here is a sample dataset modified from the dataset starwars in tidyverse . str(sample_dat)
get_desc_stat(sample_dat)
# stratified by gender and testing for gender difference get_desc_stat_grouping(sample_dat, 'gender') # report median(IQR) instead of mean(SD) for height get_desc_stat_grouping(sample_dat, 'gender', median_vars = 'height') # get detailed descriptive statistics stratified by gender, sort the table by the order of variables in the data, no statistical testing get_desc_stat_grouping(sample_dat, 'gender', detail = T, sort = T, test = F)
# get formatted table for a logistic regression model get_regression_estimates(dplyr::mutate(sample_dat, gender = as.factor(gender)), outcome = 'gender', predictor_vec = c( 'height', 'haircolor'), outcome_type = 'binary', format =T) # perform linear regression for multiple outcomes with purrr and get tables with kableExtra purrr::map_df(c('height', 'mass'), ~get_regression_estimates(sample_dat, outcome = .x, predictor_vec = c( 'sex', 'haircolor'), outcome_type = 'linear')) %>% kableExtra::kable() %>% kableExtra::kable_styling(full_width = F) %>% kableExtra::collapse_rows(1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.