{"id":13425194,"url":"https://github.com/isubirana/compareGroups","last_synced_at":"2025-03-15T19:32:48.143Z","repository":{"id":61794508,"uuid":"100396090","full_name":"isubirana/compareGroups","owner":"isubirana","description":"R package to easily build publication-ready univariate or bivariate descriptive tables from a data set.","archived":false,"fork":false,"pushed_at":"2025-02-26T09:36:32.000Z","size":16755,"stargazers_count":35,"open_issues_count":11,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-26T10:34:03.370Z","etag":null,"topics":["comparegroups","descriptive-statistics","plot","report","table"],"latest_commit_sha":null,"homepage":"https://isubirana.github.io/compareGroups/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/isubirana.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-15T16:17:40.000Z","updated_at":"2025-02-26T09:36:36.000Z","dependencies_parsed_at":"2023-01-22T16:15:19.650Z","dependency_job_id":"b09af619-1e45-4876-8c9e-1affd7cb8bee","html_url":"https://github.com/isubirana/compareGroups","commit_stats":{"total_commits":182,"total_committers":5,"mean_commits":36.4,"dds":"0.027472527472527486","last_synced_commit":"bd5d082dda8d7f612d0a68218783cbdee798016d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isubirana%2FcompareGroups","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isubirana%2FcompareGroups/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isubirana%2FcompareGroups/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isubirana%2FcompareGroups/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isubirana","download_url":"https://codeload.github.com/isubirana/compareGroups/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243781893,"owners_count":20347160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["comparegroups","descriptive-statistics","plot","report","table"],"created_at":"2024-07-31T00:01:07.075Z","updated_at":"2025-03-15T19:32:48.137Z","avatar_url":"https://github.com/isubirana.png","language":"HTML","funding_links":[],"categories":["HTML"],"sub_categories":[],"readme":"---\nmd_document:\n  variant: markdown_github\ntitle: \"compareGroups\"\noutput: md_document\nalways_allow_html: true\n---\n\n\n\n```{r setup, include=FALSE}\nknitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE, comment=\"\")\nlibrary(knitr)\n```\n\ncompareGroups \u003cimg src=\"man/figures/logo.png\" align=\"right\" style=\"margin-top:30px\" width=\"80px\"/\u003e\n=========\n\n**_package to create descriptive tables_**\n\n[![CRAN version](https://www.r-pkg.org/badges/version/compareGroups)](https://cran.r-project.org/package=compareGroups) ![](https://cranlogs.r-pkg.org/badges/grand-total/compareGroups) ![](https://cranlogs.r-pkg.org/badges/last-month/compareGroups)\n\n-   [Overview](#overview)\n-   [News](#news)\n-   [Package installation](#package-installation)\n-   [Costumizing the table](#costumizing-the-table)\n-   [Visual exploration](#visual-exploration)\n-   [Exporting the table](#exporting-the-table)\n-   [Stratified tables](#stratified-tables)\n-   [Odds Ratios and Hazard Ratios](#odds-ratios-and-hazard-ratios)\n-   [Web-based User Interface](#web-based-user-interface)\n-   [Citation](#citation)\n\n\n\n## Overview\n\n**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. \u003cbr\u003e\n\nWith 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.\u003cbr\u003e\n\nYou will find an extensive manual describing all **compareGropus** capabilities with real examples in the [vignette](http://htmlpreview.github.io/?https://github.com/isubirana/compareGroups/blob/master/compareGroups_vignette.html).\u003cbr\u003e\n\n\nAlso, **compareGroups** package has been published in Journal of Statistical Software [Subirana et al, 2014 [http://www.jstatsoft.org/v57/i12/.](https://www.jstatsoft.org/v57/i12/.)].\n\n\n## News\n\n**_Version 4.9_**\n\n- new argument `nmax.method` to compute the N shown in the header. By default N is computed as the number of rows with at least one valid value in the described variables, but also N can be computed as the total number of rows in the data set or in each group regardless the available data in the described variables. \n\n- new argument `stars` to show significance levels asterisks beside p-values.\n\n- new argument `p.trend.method`  to choose between Spearman, Kendall or \"Cuzick's trend test for non-normal numerical variables.\n\n\n\n**_Version 4.8_**\n\n- new argument added \"lab.ref\" to change label for reference category.\n\n\n**_Version 4.7_**\n\n- WUI: new functionality to convert to factors integer variables. Useful to plot numeric variables with few values as bar plots.\n\n\n**_Version 4.6_**\n\n- new function `padjustCompareGroups` to adjust p-values for multiple testing.\n\n- new arguments `header.background` and `header.color` to change header colors when exporting to PDF.\n\n\n**_Version 4.5_**\n\n- new argument 'lab.missing' to specify label for missing category.\n\n\n**_Version 4.4_**\n\n- new argument 'compute.prop' to compute proportions instead of percentages for categorical row-variables.\n\n- new argument 'all.last' added to place descriptives of the whole sample after descriptives by groups.\n\n\n**_Version 4.3_**\n\n- `export2word` supports stratified tables\n\n- Risk Ratios are now computed.\n\n\n**_Version 4.2_**\n\n- **`flextable`** package dependency\n\n- `export2md` supports tables and stratified tables to export to word in nicer format using flextable.\n\n\n\n**_Version 4.1_**\n\n- Compute confidence intervals of means, medians, proporcions or incidences\n\n- Proportions can be computed by rows as well as by columns, or by combinations of rows and columns (i.e. to sum up 100%).\n\n- New argument \"position\" to place tables justified to the left, centered or to the right using Rmarkdown.\n\n- When exporting tables to Excel, `export2xls` no longer uses `xlsx` package and uses `write_xlsx` function from writexl pacakge, instead.\n\n- The web-based user interface , `cGroupsWUI()`, has been improved and updated.\n\n**_Version 4.0_**\n\n- New argument `var.equal` to consider unequal variances when performing ANOVA tests.\n\n- Date variables are supported.\n\n- New **`strataTable`** function: to create stratified tables without having to use cbind.\n\n- package vignette improved.\n\n- New **`descrTable`** function that builds a descriptive table in one step.\n\n- New options added in `export2md`, to export tables in nicer format.\n\n- New options added in `compareGroups` to control permutated chisquared test.\n\n\n## Package installation\n\n\nInstall the **`compareGroups`** package from CRAN and then load it by typing:\n\n```{r, eval=FALSE}\ninstall.packages(\"compareGroups\")\n```\n\nor from github to get the latest version\n\n```{r, eval=FALSE}\nlibrary(devtools)\ndevtools::install_github(repo = \"isubirana/compareGroups\")\n```\n\n## Costumizing the table\n\nIn the following table, some variables from the REGICOR (\"Registre Gironí del Cor\") project ([www.regicor.cat](https://www.regicor.cat)) data set available in the package are analysed. We illustrate the syntax of **`compareGroups`** functions to display tables containing descriptives or possible tests to compare groups.\n\n\nFollowing, to describe all the variables of the data set just type:\n\n```{r}\nlibrary(compareGroups) # load compareGroups package\ndata(regicor) # load example data\ndescrTable(regicor)\n```\n\n\n**Example**\n\nIn the following table, variables are described by year of recruitment. \nSome variables such as tryglicerides (`triglyc`), physical activity (`phyact`), days to cardiovascular event (`tocv`) or days to death (`todeath`) have been treated as non-normal distributed, and medians and quantiles within square brackets instead of means and standard deviations within round brackets are displayed.\nAlso, individuals older than 55 years old are selected. Appropiate tests to compare means, medians or proportions are performed.\nFor those binary variables of type \"yes/no\", you may desire to show only the proportion of \"yes\" category without showing \"yes\" but only the variable name or label. For example, for \"Cholesterol treatment\" you may want to see simply \"Cholesterol treatment\" instead of \"Cholesterol treatment: yes\". This is possible by `hide.no` argument.\nFinally, patient id (`id`) has been removed using `-` from the formula environment.\n\nNote the simplicity of the syntax. Also, note the use of `formula` to select the variables, and the use of `subset` to filter some individuals as usual in many other R funcions.\n\n\n```{r}\ntab \u003c- descrTable(year ~ . - id, regicor, hide.no=\"no\", method=c(triglyc=2, tocv=2, todeath=2), \n                  subset=age\u003e55)\ntab\n```\n\n\n\nAlso, number of decimals and much more options can be changed to costumize the table as desired (see the  [package manual](https://CRAN.R-project.org/package=compareGroups))\n\n\n\n## Visual exploration\n\nWith **`compareGroups`** it is also possible to visualize the distribution of analysed variables. This can be done by the `plot` function applied on the table:\n\n```{r, eval=FALSE}\nplot(tab[\"sex\"]) # barplot\nplot(tab[\"age\"]) # histogram and normality plot\n```\n\n```{r, echo=FALSE}\nplot(tab[\"sex\"],file=\"./man/figures/var1\") # barplot\nplot(tab[\"age\"],file=\"./man/figures/var1\") # histogram and normality plot\n```\n\n\n|                                     |                                      |\n|:-----------------------------------:|:------------------------------------:|\n|![](./man/figures/var1sex.png) | ![](./man/figures/var1age.png) |\n\n\n\n## Exporting the table\n\nOnce the table is created, it can be printed on the R console in a nice and compact format, or it can be exported to different formats, such as PDF, Excel, Word or LaTex code.\n\n```{r, eval=FALSE}\nexport2pdf(tab, file = \"example.pdf\")\nexport2xls(tab, file = \"example.xlsx\")\nexport2word(tab, file = \"example.docx\")\nexport2latex(tab, file = \"example.tex\")\n```\n\nThis is how the table looks like in PDF:\n\n![](./man/figures/examplePDF.png)\n\n\nAlso, by using `export2md` function a descriptive table can be inserted in a Rmarkdown chunk to be compiled in HTML, PDF or Word report. Here there is an example of a Rmarkdown compiled to HTML.\n\n```{r, results=\"asis\"}\nexport2md(tab, strip = TRUE, first = TRUE, \n          header.background = \"blue\", header.color = \"white\", \n          caption = \"Description of variables by recruitment year\",\n          size=10)\n```\n\n\n## Stratified tables\n\n\nAfter creating a table you may want to repeat the descriptives within stratas. For example, you may want to compare the groups for men and for women. This is very easy using the `strataTable` function:\n\n```{r}\n# stratify by sex\ntabestr \u003c- strataTable(tab, strata=\"sex\")\n\n# remove sex variable from the table\ntabestr[-2]\n```\n\n\nor when is complied in HTML \n\n```{r, results=\"asis\"}\nexport2md(tabestr, strip = TRUE, first = TRUE, \n          header.background = \"blue\", header.color = \"white\", size=8)\n```\n\n\n## Odds Ratios and Hazard Ratios\n\n\nUsing **`compareGroups`** package you can compute Odds Ratios for transversal or case-control studies, or Hazard Ratios for cohort studies\n\n- **Example of case-control study: Odds Ratios**\n\n```{r}\ndata(SNPs)\ndescrTable(casco ~ .-id, SNPs, show.ratio=TRUE, show.p.overall=FALSE)[1:4]\n```\n\n\n- **Example of cohort study: Hazard Ratios**\n\n\n```{r, eval=FALSE}\n# create a Surv response:\nlibrary(survival)\nregicor$tcv \u003c- Surv(regicor$tocv, regicor$cv==\"Yes\")\n\n# perform descriptive table placing the Surv object as the response (left side of ~):\ntab \u003c- descrTable(tcv ~ .-id-cv-tocv, regicor, \n           method=c(triglyc=2, tocv=2, todeath=2),\n           hide.no=\"no\", ref.no=\"no\",\n           show.ratio=TRUE, show.p.overall=FALSE)\n\n# print table on R console\nprint(tab, header.label=c(\"p.ratio\"=\"p-value\"))           \n```\n\n```{r, echo=FALSE}\n# create a Surv response:\nlibrary(survival)\nregicor$tcv \u003c- Surv(regicor$tocv, regicor$cv==\"Yes\")\n\n# perform descriptive table placing the Surv object as the response (left side of ~):\ntab \u003c- descrTable(tcv ~ .-id-cv-tocv, regicor, \n           method=c(triglyc=2, tocv=2, todeath=2),\n           hide.no=\"no\", ref.no=\"no\",\n           show.ratio=TRUE, show.p.overall=FALSE)\n\n# print table on R console\nprint(tab, header.label=c(\"p.ratio\"=\"p-value\"))          \n```\n\n\n\n# Web-based User Interface\n\nFor those not familiar to R syntax, a Web User Interface (**WUI**) has been implemented using [Shiny](https://shiny.rstudio.com/) tools, which can be used remotely just accessing the [**compareGroups project website**](https://isubirana.github.io/compareGroups)\n\n\n\n\n![ ](./man/figures/WUI.png)\n\nTry the WUI compareGroups [here](https://isubirana.github.io/compareGroups/articles/wui.html)\n\n\u003cbr\u003e\n\n\n\n# Citation\n\n\n```{r}\ncitation(\"compareGroups\")\n```\n\n\n# References\n\n\n\u003cp\u003eSubirana, Isaac, Héctor Sanz, and Joan Vila. 2014. “Building Bivariate Tables: The compareGroups Package for R.” \u003cem\u003eJournal of Statistical Software\u003c/em\u003e 57 (12): 1–16. \u003ca href=\"https://www.jstatsoft.org/v57/i12/\" class=\"uri\"\u003ehttps://www.jstatsoft.org/v57/i12/\u003c/a\u003e.\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisubirana%2FcompareGroups","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisubirana%2FcompareGroups","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisubirana%2FcompareGroups/lists"}