Skip to content

chupverse/descriptive-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 

Repository files navigation

descriptive-tools

Several functions for descriptive analyses (tables, figures, etc.)

    Descriptive table

    ‘TableDesc’ fonction

    TableDesc : To create a comparative table with a treatment and tests.

    Description

    This function calculates descriptive statistics for continuous and categorical variables.

    Usage

    TableDesc(data, vars=NULL, names=NULL, trt=NULL, virg=0, virg.percent=0, nolevels=NULL, nonnormal=NULL, nrpval=4, boldpval=0.05, boldsmd=0.1, reference=TRUE, export=FALSE, pvalue=TRUE, smd=FALSE, missing=FALSE, paired=FALSE, legend=TRUE, binary01=FALSE)

    Arguments

    data An object of the class data.frame containing the variables cited in vars.
    vars A list of variable names to be described. If NULL, all the variable in data will be described except those with more than 20 levels (date, subject id …).
    names A list of labels for the variables. If NULL, vars will be used.
    trt A character string with the name of the comparative variable.
    virg Number of decimal for continuous variables. The default value is 0.
    virg.percent Number of decimal for percentages. The default value is 0.
    nolevels A list of variables with only 2 levels which will be described on a single line and the first level will be described, thus relevel needed.
    nonnormal A list of variables not normally distributed. Specify "none" if every continuous variable is normally distributing and "all" if every continuous variable is non-normally distributing. See details to know how variables will be described according to their distribution.
    nrpval Number of decimals to be used for the pvalue. The default value is 4.
    boldpval The statistical significance for p-value. Pvalues lower than set level will be in bold. The default value is 0.05.
    boldsmd The SMD threshold to considering an unbalance. SMD upper than set level will be in bold. The default value is 0.1 (10%).
    reference TRUE by default, any other value will remove the ", n (%)" after the label for categorical variables.
    export A logical value specifying if a word document with the descriptive table should be exporting. Default is FALSE.
    pvalue A logical value specifying if the pvalue should be add to compared groups. See details to know which test will be used. Default is TRUE.
    smd A logical value specifying if the standardized differences should be estimating. Default is FALSE.
    missing A logical value specifying if the missing values should be describing. Default is TRUE.
    paired A logical value indicating whether you want paired test. Default is FALSE.
    legend A logical value indicating whether a footnote should be printed to indicate which tests were used. Default is TRUE.
    binary01 A logical value indicating if binary variables are expressed as 0/1. Default is FALSE.

    Details

    This function returns a flextable object. If the continuous variable is normally distributed, mean and standard deviation will be presented and groups compared using a Student t-test. Else, median and 25th-75th percentile will be presented and groups compared using a Mann-Whitney test. If nonnormal = NULL, a Shapiro test will be performed to qualify the distribution. Categorical variable will be presented as effectives and percentage and compared according to the group using a Chi-2 test or Fisher exact tests if expected numbers of patients are less than 5.

    Examples

    source("https://raw.githubusercontent.com/lisadurocher/TableDesc/main/TableDesc.R")
    
    data("mtcars")
    
    mtcars$am <- factor(mtcars$am, levels=c(0,1), labels = c("Automatic","Manual"))
    
    mtcars$cyl <- factor(mtcars$cyl, c(4,6,8))
    
    mtcars$vs <- factor(mtcars$vs, levels = c(1,0))
    
    vars <- c("mpg","cyl","hp","vs")
    
    names <- c("Miles/(US) gallon", "Number of cylinders", "Gross horsepower", "V/S")
    
    nolevels <- c("vs")
    
    TableDesc(data=mtcars, vars=vars, names=names, trt="am", virg=1, nolevels=nolevels, nonnormal = "none", smd = TRUE, export = FALSE)

    Simple version:

    TableDesc(data=mtcars, TRT="am")

About

Several functions for descriptive analyses (tables, figures, etc.)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors