README.md

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 http://www.jstatsoft.org/v57/i12/.].

News

Version 4.1

Version 4.0

Package installation

Install the compareGroups package from CRAN and then load it by typing:

install.packages("compareGroups")

or from github to get the latest version

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

Costumizing the table

In the following table, some variables from the REGICOR (“Registre Gironí del Cor”) project (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.

Following, to describe all the variables of the data set just type:

library(compareGroups) # load compareGroups package
data(regicor) # load example data
descrTable(regicor)


--------Summary descriptives table ---------

_____________________________________________________________________________ 
                                                          [ALL]           N   
                                                         N=2294               
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 
Individual id                                    1215817624 (1339538686) 2294 
Recruitment year:                                                        2294 
    1995                                               431 (18.8%)            
    2000                                               786 (34.3%)            
    2005                                              1077 (46.9%)            
Age                                                    54.7 (11.0)       2294 
Sex:                                                                     2294 
    Male                                              1101 (48.0%)            
    Female                                            1193 (52.0%)            
Smoking status:                                                          2233 
    Never smoker                                      1201 (53.8%)            
    Current or former < 1y                             593 (26.6%)            
    Former >= 1y                                       439 (19.7%)            
Systolic blood pressure                                131 (20.3)        2280 
Diastolic blood pressure                               79.7 (10.5)       2280 
History of hypertension:                                                 2286 
    Yes                                                723 (31.6%)            
    No                                                1563 (68.4%)            
Hypertension treatment:                                                  2251 
    No                                                1823 (81.0%)            
    Yes                                                428 (19.0%)            
Total cholesterol                                      219 (45.2)        2193 
HDL cholesterol                                        52.7 (14.7)       2225 
Triglycerides                                          116 (73.9)        2231 
LDL cholesterol                                        143 (39.7)        2126 
History of hyperchol.:                                                   2273 
    Yes                                                709 (31.2%)            
    No                                                1564 (68.8%)            
Cholesterol treatment:                                                   2239 
    No                                                2011 (89.8%)            
    Yes                                                228 (10.2%)            
Height (cm)                                            163 (9.22)        2259 
Weight (Kg)                                            73.4 (13.7)       2259 
Body mass index                                        27.6 (4.56)       2259 
Physical activity (Kcal/week)                           399 (388)        2206 
Physical component                                     49.6 (9.01)       2054 
Mental component                                       48.0 (11.0)       2054 
Cardiovascular event:                                                    2163 
    No                                                2071 (95.7%)            
    Yes                                                92 (4.25%)             
Days to cardiovascular event or end of follow-up       1755 (1081)       2163 
Overall death:                                                           2148 
    No                                                1975 (91.9%)            
    Yes                                                173 (8.05%)            
Days to overall death or end of follow-up              1721 (1051)       2148 
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Example

In the following table, variables are described by year of recruitment. Some 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. Also, individuals older than 55 years old are selected. Appropiate tests to compare means, medians or proportions are performed. For 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. Finally, patient id (id) has been removed using - from the formula environment.

Note 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.

tab <- descrTable(year ~ . - id, regicor, hide.no="no", method=c(triglyc=2, tocv=2, todeath=2), 
                  subset=age>55)
tab


--------Summary descriptives table by 'year'---------

__________________________________________________________________________________________________________ 
                                                      1995            2000            2005       p.overall 
                                                      N=203           N=365           N=540                
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 
Age                                                65.0 (5.41)     64.7 (5.48)     64.3 (5.57)     0.235   
Sex:                                                                                               0.613   
    Male                                           94 (46.3%)      181 (49.6%)     251 (46.5%)             
    Female                                         109 (53.7%)     184 (50.4%)     289 (53.5%)             
Smoking status:                                                                                   <0.001   
    Never smoker                                   127 (64.1%)     220 (63.2%)     326 (61.6%)             
    Current or former < 1y                         29 (14.6%)      84 (24.1%)      71 (13.4%)              
    Former >= 1y                                   42 (21.2%)      44 (12.6%)      132 (25.0%)             
Systolic blood pressure                            142 (18.3)      144 (20.0)      137 (20.0)     <0.001   
Diastolic blood pressure                           79.5 (9.88)     83.5 (9.93)     81.2 (10.6)    <0.001   
History of hypertension                            80 (39.4%)      151 (41.4%)     274 (51.0%)     0.002   
Hypertension treatment                             57 (28.1%)      101 (27.7%)     198 (38.1%)     0.002   
Total cholesterol                                  229 (41.8)      228 (44.4)      217 (44.3)     <0.001   
HDL cholesterol                                    52.4 (14.5)     52.2 (15.3)     53.5 (14.2)     0.403   
Triglycerides                                    99.0 [77.0;137] 107 [82.0;136]  104 [77.0;142]    0.491   
LDL cholesterol                                    154 (37.5)      153 (38.3)      139 (39.6)     <0.001   
History of hyperchol.                              52 (25.6%)      150 (42.3%)     219 (40.7%)    <0.001   
Cholesterol treatment                              22 (10.8%)      55 (15.4%)      111 (21.3%)     0.002   
Height (cm)                                        162 (8.72)      160 (8.98)      161 (8.54)      0.002   
Weight (Kg)                                        73.1 (11.8)     75.2 (12.9)     74.1 (12.4)     0.157   
Body mass index                                    28.0 (4.40)     29.5 (4.21)     28.4 (4.39)    <0.001   
Physical activity (Kcal/week)                       491 (380)       429 (317)       373 (370)     <0.001   
Physical component                                 46.9 (8.95)     45.7 (10.8)     47.6 (9.70)     0.031   
Mental component                                   49.2 (11.6)     49.8 (11.0)     47.6 (10.9)     0.016   
Cardiovascular event                                6 (3.23%)      21 (6.10%)      28 (5.44%)      0.356   
Days to cardiovascular event or end of follow-up 1710 [804;2769] 1577 [640;2564] 1752 [824;2739]   0.137   
Overall death                                      13 (7.03%)      61 (17.9%)      46 (8.91%)     <0.001   
Days to overall death or end of follow-up        1620 [808;2631] 1483 [732;2323] 1751 [782;2640]   0.106   
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Also, number of decimals and much more options can be changed to costumize the table as desired (see the package manual)

Visual exploration

With compareGroups it is also possible to visualize the distribution of analysed variables. This can be done by the plot function applied on the table:

plot(tab["sex"]) # barplot
plot(tab["age"]) # histogram and normality plot

Exporting the table

Once 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.

export2pdf(tab, file = "example.pdf")
export2xls(tab, file = "example.xlsx")
export2word(tab, file = "example.docx")
export2latex(tab, file = "example.tex")

This is how the table looks like in PDF:

Also, 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.

export2md(tab, strip = TRUE, first = TRUE, 
          header.background = "blue", header.color = "white", 
          caption = "Description of variables by recruitment year",
          size=10)
Description of variables by recruitment year 1995 2000 2005 p.overall N=203 N=365 N=540 Age 65.0 (5.41) 64.7 (5.48) 64.3 (5.57) 0.235 Sex: 0.613 Male 94 (46.3%) 181 (49.6%) 251 (46.5%) Female 109 (53.7%) 184 (50.4%) 289 (53.5%) Smoking status: <0.001 Never smoker 127 (64.1%) 220 (63.2%) 326 (61.6%) Current or former < 1y 29 (14.6%) 84 (24.1%) 71 (13.4%) Former >= 1y 42 (21.2%) 44 (12.6%) 132 (25.0%) Systolic blood pressure 142 (18.3) 144 (20.0) 137 (20.0) <0.001 Diastolic blood pressure 79.5 (9.88) 83.5 (9.93) 81.2 (10.6) <0.001 History of hypertension 80 (39.4%) 151 (41.4%) 274 (51.0%) 0.002 Hypertension treatment 57 (28.1%) 101 (27.7%) 198 (38.1%) 0.002 Total cholesterol 229 (41.8) 228 (44.4) 217 (44.3) <0.001 HDL cholesterol 52.4 (14.5) 52.2 (15.3) 53.5 (14.2) 0.403 Triglycerides 99.0 \[77.0;137\] 107 \[82.0;136\] 104 \[77.0;142\] 0.491 LDL cholesterol 154 (37.5) 153 (38.3) 139 (39.6) <0.001 History of hyperchol. 52 (25.6%) 150 (42.3%) 219 (40.7%) <0.001 Cholesterol treatment 22 (10.8%) 55 (15.4%) 111 (21.3%) 0.002 Height (cm) 162 (8.72) 160 (8.98) 161 (8.54) 0.002 Weight (Kg) 73.1 (11.8) 75.2 (12.9) 74.1 (12.4) 0.157 Body mass index 28.0 (4.40) 29.5 (4.21) 28.4 (4.39) <0.001 Physical activity (Kcal/week) 491 (380) 429 (317) 373 (370) <0.001 Physical component 46.9 (8.95) 45.7 (10.8) 47.6 (9.70) 0.031 Mental component 49.2 (11.6) 49.8 (11.0) 47.6 (10.9) 0.016 Cardiovascular event 6 (3.23%) 21 (6.10%) 28 (5.44%) 0.356 Days to cardiovascular event or end of follow-up 1710 \[804;2769\] 1577 \[640;2564\] 1752 \[824;2739\] 0.137 Overall death 13 (7.03%) 61 (17.9%) 46 (8.91%) <0.001 Days to overall death or end of follow-up 1620 \[808;2631\] 1483 \[732;2323\] 1751 \[782;2640\] 0.106

Stratified tables

After 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:

# stratify by sex
tabestr <- strataTable(tab, strata="sex")

# remove sex variable from the table
tabestr[-2]


--------Summary descriptives table ---------

______________________________________________________________________________________________________________________________________________________________________
                                                                            Male                                                      Female                          
                                                 __________________________________________________________  _________________________________________________________
                                                       1995            2000            2005       p.overall       1995            2000            2005       p.overall 
                                                       N=94            N=181           N=251                      N=109           N=184           N=289                
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Age                                                65.4 (5.36)      64.7 (5.39)     64.6 (5.62)     0.453      64.7 (5.47)     64.6 (5.58)     64.1 (5.53)     0.403   
Smoking status:                                                                                    <0.001                                                      0.007   
    Never smoker                                    23 (25.6%)      50 (28.9%)      70 (28.6%)                 104 (96.3%)     170 (97.1%)     256 (90.1%)             
    Current or former < 1y                          25 (27.8%)      80 (46.2%)      57 (23.3%)                  4 (3.70%)       4 (2.29%)      14 (4.93%)              
    Former >= 1y                                    42 (46.7%)      43 (24.9%)      118 (48.2%)                 0 (0.00%)       1 (0.57%)      14 (4.93%)              
Systolic blood pressure                             141 (18.0)      145 (18.8)      139 (19.3)      0.003      143 (18.6)      143 (21.1)      136 (20.4)     <0.001   
Diastolic blood pressure                           79.8 (8.79)      84.8 (9.50)     82.5 (10.8)    <0.001      79.3 (10.8)     82.2 (10.2)     80.0 (10.2)     0.028   
History of hypertension                             34 (36.2%)      67 (37.0%)      126 (50.6%)     0.006      46 (42.2%)      84 (45.7%)      148 (51.4%)     0.202   
Hypertension treatment                              25 (26.6%)      39 (21.5%)      96 (39.8%)     <0.001      32 (29.4%)      62 (33.7%)      102 (36.6%)     0.398   
Total cholesterol                                   221 (42.3)      222 (44.3)      207 (37.9)     <0.001      236 (40.3)      234 (43.8)      225 (47.8)      0.035   
HDL cholesterol                                    47.6 (14.3)      46.9 (11.9)     49.1 (12.7)     0.225      56.8 (13.4)     57.6 (16.5)     57.4 (14.4)     0.913   
Triglycerides                                     110 [79.5;139]  112 [87.0;137]  109 [77.0;142]    0.670    95.5 [75.0;127] 104 [77.0;134]  102 [77.0;142]    0.577   
LDL cholesterol                                     151 (38.8)      152 (39.8)      134 (34.2)     <0.001      157 (36.4)      154 (36.9)      144 (43.2)      0.006   
History of hyperchol.                               24 (25.5%)      72 (40.4%)      90 (36.0%)      0.050      28 (25.7%)      78 (44.1%)      129 (44.8%)     0.002   
Cholesterol treatment                               12 (12.8%)      30 (16.9%)      44 (18.1%)      0.498      10 (9.17%)      25 (14.0%)      67 (24.2%)      0.001   
Height (cm)                                         168 (6.78)      166 (6.36)      167 (6.92)      0.040      156 (6.27)      153 (6.27)      156 (6.36)     <0.001   
Weight (Kg)                                        76.6 (12.6)      81.1 (11.8)     78.8 (10.2)     0.005      70.1 (10.4)     69.2 (11.1)     69.9 (12.6)     0.773   
Body mass index                                    27.1 (3.97)      29.4 (3.59)     28.2 (3.25)    <0.001      28.8 (4.62)     29.6 (4.76)     28.6 (5.19)     0.141   
Physical activity (Kcal/week)                       499 (462)        399 (342)       492 (449)      0.054       483 (299)       458 (289)       269 (240)     <0.001   
Physical component                                 48.3 (7.03)      48.0 (10.2)     49.0 (9.03)     0.558      45.6 (10.3)     43.5 (11.0)     46.4 (10.1)     0.024   
Mental component                                   52.6 (10.3)      52.5 (9.49)     50.1 (9.94)     0.033      46.1 (11.9)     47.2 (11.8)     45.3 (11.2)     0.263   
Cardiovascular event                                3 (3.33%)       14 (8.19%)      13 (5.44%)      0.257       3 (3.12%)       7 (4.05%)      15 (5.43%)      0.706   
Days to cardiovascular event or end of follow-up 1606 [793;2735]  1608 [537;2492] 1882 [920;2827]   0.105    1739 [834;2768] 1573 [686;2655] 1723 [701;2673]   0.512   
Overall death                                       9 (10.3%)       34 (20.0%)      16 (6.72%)     <0.001       4 (4.08%)      27 (15.8%)      30 (10.8%)      0.013   
Days to overall death or end of follow-up        1625 [1015;2655] 1442 [769;2247] 1684 [715;2518]   0.290    1501 [725;2515] 1507 [679;2408] 1811 [890;2721]   0.174   
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

or when is complied in HTML

export2md(tabestr, strip = TRUE, first = TRUE, 
          header.background = "blue", header.color = "white", size=8)
Summary descriptive tables Male Female 1995 2000 2005 p.overall 1995 2000 2005 p.overall N=94 N=181 N=251 N=109 N=184 N=289 Age 65.4 (5.36) 64.7 (5.39) 64.6 (5.62) 0.453 64.7 (5.47) 64.6 (5.58) 64.1 (5.53) 0.403 Sex: . . Male 94 (100%) 181 (100%) 251 (100%) 0 (0.00%) 0 (0.00%) 0 (0.00%) Female 0 (0.00%) 0 (0.00%) 0 (0.00%) 109 (100%) 184 (100%) 289 (100%) Smoking status: <0.001 0.007 Never smoker 23 (25.6%) 50 (28.9%) 70 (28.6%) 104 (96.3%) 170 (97.1%) 256 (90.1%) Current or former < 1y 25 (27.8%) 80 (46.2%) 57 (23.3%) 4 (3.70%) 4 (2.29%) 14 (4.93%) Former >= 1y 42 (46.7%) 43 (24.9%) 118 (48.2%) 0 (0.00%) 1 (0.57%) 14 (4.93%) Systolic blood pressure 141 (18.0) 145 (18.8) 139 (19.3) 0.003 143 (18.6) 143 (21.1) 136 (20.4) <0.001 Diastolic blood pressure 79.8 (8.79) 84.8 (9.50) 82.5 (10.8) <0.001 79.3 (10.8) 82.2 (10.2) 80.0 (10.2) 0.028 History of hypertension 34 (36.2%) 67 (37.0%) 126 (50.6%) 0.006 46 (42.2%) 84 (45.7%) 148 (51.4%) 0.202 Hypertension treatment 25 (26.6%) 39 (21.5%) 96 (39.8%) <0.001 32 (29.4%) 62 (33.7%) 102 (36.6%) 0.398 Total cholesterol 221 (42.3) 222 (44.3) 207 (37.9) <0.001 236 (40.3) 234 (43.8) 225 (47.8) 0.035 HDL cholesterol 47.6 (14.3) 46.9 (11.9) 49.1 (12.7) 0.225 56.8 (13.4) 57.6 (16.5) 57.4 (14.4) 0.913 Triglycerides 110 \[79.5;139\] 112 \[87.0;137\] 109 \[77.0;142\] 0.670 95.5 \[75.0;127\] 104 \[77.0;134\] 102 \[77.0;142\] 0.577 LDL cholesterol 151 (38.8) 152 (39.8) 134 (34.2) <0.001 157 (36.4) 154 (36.9) 144 (43.2) 0.006 History of hyperchol. 24 (25.5%) 72 (40.4%) 90 (36.0%) 0.050 28 (25.7%) 78 (44.1%) 129 (44.8%) 0.002 Cholesterol treatment 12 (12.8%) 30 (16.9%) 44 (18.1%) 0.498 10 (9.17%) 25 (14.0%) 67 (24.2%) 0.001 Height (cm) 168 (6.78) 166 (6.36) 167 (6.92) 0.040 156 (6.27) 153 (6.27) 156 (6.36) <0.001 Weight (Kg) 76.6 (12.6) 81.1 (11.8) 78.8 (10.2) 0.005 70.1 (10.4) 69.2 (11.1) 69.9 (12.6) 0.773 Body mass index 27.1 (3.97) 29.4 (3.59) 28.2 (3.25) <0.001 28.8 (4.62) 29.6 (4.76) 28.6 (5.19) 0.141 Physical activity (Kcal/week) 499 (462) 399 (342) 492 (449) 0.054 483 (299) 458 (289) 269 (240) <0.001 Physical component 48.3 (7.03) 48.0 (10.2) 49.0 (9.03) 0.558 45.6 (10.3) 43.5 (11.0) 46.4 (10.1) 0.024 Mental component 52.6 (10.3) 52.5 (9.49) 50.1 (9.94) 0.033 46.1 (11.9) 47.2 (11.8) 45.3 (11.2) 0.263 Cardiovascular event 3 (3.33%) 14 (8.19%) 13 (5.44%) 0.257 3 (3.12%) 7 (4.05%) 15 (5.43%) 0.706 Days to cardiovascular event or end of follow-up 1606 \[793;2735\] 1608 \[537;2492\] 1882 \[920;2827\] 0.105 1739 \[834;2768\] 1573 \[686;2655\] 1723 \[701;2673\] 0.512 Overall death 9 (10.3%) 34 (20.0%) 16 (6.72%) <0.001 4 (4.08%) 27 (15.8%) 30 (10.8%) 0.013 Days to overall death or end of follow-up 1625 \[1015;2655\] 1442 \[769;2247\] 1684 \[715;2518\] 0.290 1501 \[725;2515\] 1507 \[679;2408\] 1811 \[890;2721\] 0.174

Odds Ratios and Hazard Ratios

Using compareGroups package you can compute Odds Ratios for transversal or case-control studies, or Hazard Ratios for cohort studies

data(SNPs)
descrTable(casco ~ .-id, SNPs, show.ratio=TRUE, show.p.overall=FALSE)[1:4]


--------Summary descriptives table by 'casco'---------

_______________________________________________________________ 
                 0             1              OR        p.ratio 
               N=47          N=110                              
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 
sex:                                                            
    Male    21 (44.7%)    54 (49.1%)         Ref.        Ref.   
    Female  26 (55.3%)    56 (50.9%)   0.84 [0.42;1.67]  0.619  
blood.pre   13.1 (0.88)   12.9 (1.03)  0.78 [0.55;1.11]  0.174  
protein    39938 (19770) 44371 (24897) 1.00 [1.00;1.00]  0.280  
snp10001:                                                       
    CC       2 (4.26%)    10 (9.09%)         Ref.        Ref.   
    CT      21 (44.7%)    32 (29.1%)   0.33 [0.04;1.43]  0.147  
    TT      24 (51.1%)    68 (61.8%)   0.60 [0.08;2.55]  0.521  
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# create a Surv response:
library(survival)
regicor$tcv <- Surv(regicor$tocv, regicor$cv=="Yes")

# perform descriptive table placing the Surv object as the response (left side of ~):
tab <- 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)

# print table on R console
print(tab, header.label=c("p.ratio"="p-value"))


--------Summary descriptives table by 'tcv'---------

__________________________________________________________________________________________________ 
                                             No event          Event             HR        p-value 
                                              N=2071           N=92                                
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 
Recruitment year:                                                                                  
    1995                                    388 (18.7%)     10 (10.9%)          Ref.        Ref.   
    2000                                    706 (34.1%)     35 (38.0%)    1.95 [0.96;3.93]  0.063  
    2005                                    977 (47.2%)     47 (51.1%)    1.82 [0.92;3.59]  0.087  
Age                                         54.6 (11.1)     57.5 (11.0)   1.02 [1.00;1.04]  0.021  
Sex:                                                                                               
    Male                                    996 (48.1%)     46 (50.0%)          Ref.        Ref.   
    Female                                 1075 (51.9%)     46 (50.0%)    0.92 [0.61;1.39]  0.696  
Smoking status:                                                                                    
    Never smoker                           1099 (54.3%)     37 (40.2%)          Ref.        Ref.   
    Current or former < 1y                  506 (25.0%)     47 (51.1%)    2.67 [1.74;4.11] <0.001  
    Former >= 1y                            419 (20.7%)      8 (8.70%)    0.55 [0.26;1.18]  0.123  
Systolic blood pressure                     131 (20.3)      138 (21.5)    1.02 [1.01;1.02]  0.001  
Diastolic blood pressure                    79.5 (10.4)     82.9 (12.3)   1.03 [1.01;1.05]  0.002  
History of hypertension                     647 (31.3%)     38 (41.3%)    1.52 [1.01;2.31]  0.047  
Hypertension treatment                      382 (18.7%)     22 (23.9%)    1.37 [0.85;2.22]  0.195  
Total cholesterol                           218 (44.5)      224 (50.4)    1.00 [1.00;1.01]  0.207  
HDL cholesterol                             52.8 (14.8)     50.4 (13.3)   0.99 [0.97;1.00]  0.114  
Triglycerides                             96.0 [71.0;135] 110 [87.5;161]  1.00 [1.00;1.00]  0.190  
LDL cholesterol                             143 (39.6)      149 (45.6)    1.00 [1.00;1.01]  0.148  
History of hyperchol.                       639 (31.1%)     25 (27.2%)    0.82 [0.52;1.30]  0.406  
Cholesterol treatment                       213 (10.5%)      6 (6.52%)    0.61 [0.27;1.39]  0.239  
Height (cm)                                 163 (9.21)      163 (9.34)    1.00 [0.98;1.03]  0.692  
Weight (Kg)                                 73.4 (13.7)     74.9 (12.8)   1.01 [0.99;1.02]  0.294  
Body mass index                             27.6 (4.56)     28.1 (4.48)   1.02 [0.98;1.07]  0.299  
Physical activity (Kcal/week)                405 (397)       338 (238)    1.00 [1.00;1.00]  0.089  
Physical component                          49.7 (8.95)     47.4 (9.03)   0.98 [0.96;1.00]  0.023  
Mental component                            48.1 (10.9)     46.3 (12.2)   0.99 [0.97;1.00]  0.122  
Overall death                               156 (7.98%)     15 (16.9%)    2.35 [1.35;4.09]  0.003  
Days to overall death or end of follow-up 1684 [789;2663] 1468 [510;2453] 1.00 [1.00;1.00]  0.298  
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

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 remotely just accessing the compareGroups project website

Try the WUI compareGroups here

Citation

citation("compareGroups")

To cite compareGroups in publications use:

  Isaac Subirana, Hector Sanz, Joan Vila (2014). Building Bivariate
  Tables: The compareGroups Package for R. Journal of Statistical
  Software, 57(12), 1-16. URL https://www.jstatsoft.org/v57/i12/.

A BibTeX entry for LaTeX users is

  @Article{,
    title = {Building Bivariate Tables: The {compareGroups} Package for {R}},
    author = {Isaac Subirana and H\'ector Sanz and Joan Vila},
    journal = {Journal of Statistical Software},
    year = {2014},
    volume = {57},
    number = {12},
    pages = {1--16},
    url = {https://www.jstatsoft.org/v57/i12/},
  }

References

Subirana, Isaac, Héctor Sanz, and Joan Vila. 2014. “Building Bivariate Tables: The compareGroups Package for R.” Journal of Statistical Software 57 (12): 1–16. https://www.jstatsoft.org/v57/i12/.



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