knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(relper) library(dplyr)
stat_
functions apply statistical methods and show the results in an gt
table, let's create a example data.frame to apply them.
set.seed(1234);df <- data.frame( grp_var = sample(paste("group", letters[1:2]),size = 100,replace = TRUE), cat_var1 = sample(letters[1:3],size = 100,replace = TRUE), cat_var2 = sample(letters[25:26],size = 100,replace = TRUE), num_var1 = c(rnorm(66),rep(NA,34)), num_var2 = c(rpois(80,2),rep(NA,20)), num_var3 = c(rexp(40,2),rep(NA,60)) )
The goal of stat_missing_values
is to identify the variables with most missing values
stat_missing_values(df)
The goal of stat_normality
is to test the normality of the data.
set.seed(123);x <- rnorm(100) stat_normality(x,digits = 5)
You can also print as a gt
table, by setting the argument print
to TRUE
.
# gt::gtsave( # data = stat_normality(x = x,print = TRUE,digits = 5), # filename = "stat_normality.png", # path = file.path(getwd(),"figs"), # vwidth = 1500, # vheight = 1000 # )
{ height=10% }
The goal of stat_two_cat
is to create a frequency table with chi-square statistic, p-value and Cramer's V.
df %>% stat_two_cat( df = ., grp_var = grp_var, vars = c(cat_var1,cat_var2) )
# temp_table <- # df %>% # stat_two_cat( # df = ., # grp_var = grp_var, # vars = c(cat_var1,cat_var2) # ) # # gt::gtsave( # data = temp_table, # filename = "stat_two_cat.png", # path = file.path(getwd(),"figs"), # vwidth = 1500, # vheight = 1000 # )
The goal of stat_two_num
is to create a summary table comparing one or more numerical variables between two groups.
# temp_table <- # df %>% # stat_two_num( # df = ., # grp_var = grp_var, # num_vars = c(num_var1,num_var2,num_var3) # ) # # gt::gtsave( # data = temp_table, # filename = "stat_two_num.png", # path = file.path(getwd(),"figs"), # vwidth = 1500, # vheight = 1000 # )
df %>% stat_two_num( df = ., grp_var = grp_var, num_vars = c(num_var1,num_var2,num_var3) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.