knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE, comment="")
library(knitr)

compareGroups

package to create descriptive tables

CRAN version

Overview

compareGroups is an R package available on CRAN which performs descriptive tables displaying means, standard deviation, quantiles or frequencies of several variables. Also, p-value to test equality between groups is computed using the appropiate test.

With a very simple code, nice, compact and ready-to-publish descriptives table are displayed on R console. They can also be exported to different formats, such as Word, Excel, PDF or inserted in a R-Sweave or R-markdown document.

You will find an extensive manual describing all compareGropus capabilities with real examples in the vignette.

Also, compareGroups package has been published in Journal of Statistical Software [Subirana et al, 2014] (https://www.jstatsoft.org/v57/i12/).


Who we are

compareGroups is developed and maintained by Isaac Subirana, Hector Sanz, Joan Vila and collaborators at the cardiovascular epidemiology research unit (URLEC), located at Barcelona Biomedical Research Park (PRBB) .






As the driving force behind the REGICOR study, URLEC has extensive experience in statistical epidemiology, and is a national reference centre for research into cardiovascular diseases and their risk factors.




Gets started

Install the package from CRAN

install.packages("compareGroups")

or the lattest version from Github

library(devtools)
devtools::install_github("isubirana/compareGroups")

Building the descriptive table

library(compareGroups)

data(regicor)

tab <- descrTable(year ~ . -id , regicor, hide.no = "no", 
                  method=c(triglyc=2, tocv=2, todeath=2), sd.type = 3)

export2md(tab, header.background = "black", header.color = "white", 
          caption = "Summary by intervention group")

Stratified table

wzxhzdk:4

Visual exploration

plot(tab["sex"], "./man/figures/var1", type="png") 
plot(tab["age"], "./man/figures/var1", type="png")

| | | |:----------:|:------------:| | plot(tab["sex"]) | plot(tab["age"]) | | | |

Computing Odds Ratios

data(SNPs)

tabor <- descrTable(casco ~ .-id, SNPs, show.ratio=TRUE, show.p.overall=FALSE)

export2md(tabor[1:4])

Computing Hazard Ratios

library(survival)
regicor$tcv <- Surv(regicor$tocv, regicor$cv=="Yes")

tabhr <- descrTable(tcv ~ .-id-cv-tocv, regicor, 
           method=c(triglyc=2, tocv=2, todeath=2),
           hide.no="no", ref.no="no",
           show.ratio=TRUE, show.p.overall=FALSE)


export2md(tabhr[1:10], header.label=c("p.ratio"="p-value"),
          caption="Descriptives by cardiovascular event")  

Web-based User Interface

For those not familiar to R syntax, a Web User Interface (WUI) has been implemented using Shiny tools, which can be used off line by typing cGroupsWUI() after having compareGroups package installed and loaded, or remotely just accessing the application hosted in a shinyapp.io server.



isubirana/compareGroups documentation built on Jan. 31, 2024, 9:19 p.m.