Homework - Descriptive tables

Author

Marcio A Diniz

Published

October 4, 2022

Homework 02

Deadline: October, 18th

Format: HTML + Rmd

Submit to: michael.luu@cshs.org

Tutorial

Libraries

library(readxl)
library(tidyverse)
library(glue)

We need to install some additional R-packages.

#install.packages("gt")
library(gt) 

The R-package kableExtra needs to be installed from a different repository because the latest version available on CRAN has a bug which has been fixed but not released on CRAN yet. Therefore, we will install the development version. First, we install the R-package for R-packages under development.

#install.packages("devtools")
library(devtools) 

Then, we can install kableExtra from the repository of the author of the R-package:

#devtools::install_github("haozhu233/kableExtra")
library(kableExtra) 

Reading dataset

We are going to summarize our dataset emergency using descriptive tables.

Qualitative variables

Qualitative variables are summarized by frequencies that are calculated using the function n as showed below:

dt %>% 
  group_by(death) %>% 
  summarize(freq = n())
# A tibble: 2 × 2
  death  freq
  <fct> <int>
1 No      113
2 Yes      36

The function group_by accepts as many arguments as we want,

dt %>% group_by(infection, death, child) %>% 
  summarize(freq = n())
# A tibble: 13 × 4
# Groups:   infection, death [4]
   infection death child  freq
   <fct>     <fct> <fct> <int>
 1 No        No    A         3
 2 No        No    B        29
 3 No        No    C        30
 4 No        No    <NA>      2
 5 No        Yes   A         1
 6 No        Yes   B         4
 7 No        Yes   C         8
 8 Yes       No    A         1
 9 Yes       No    B        28
10 Yes       No    C        15
11 Yes       No    <NA>      5
12 Yes       Yes   B         9
13 Yes       Yes   C        14

Notice that there are some NA values for the variable child. We can identify NA values using the function is.na.

is.na(dt$child)
  [1]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [25] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [61] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [85] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [97] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[109] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
[121] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[133] FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE
[145] FALSE FALSE  TRUE FALSE FALSE

Moreover, we can summarize whether the variable child has any missing value,

any(is.na(dt$child))
[1] TRUE

We can use the function fct_explicit_na from the R-package forcats of the Tidyverse to make the missing values as a level explicitly,

fct_explicit_na(dt$child, na_level = "Missing")
  [1] Missing B       B       B       B       C       A       B       C      
 [10] B       A       C       C       C       B       B       B       C      
 [19] C       B       B       C       B       C       C       B       Missing
 [28] B       B       C       B       C       B       B       C       B      
 [37] B       C       B       C       B       C       C       B       B      
 [46] C       C       B       C       B       C       B       B       A      
 [55] B       B       C       C       C       B       C       B       B      
 [64] B       C       B       C       B       B       B       C       B      
 [73] C       C       C       C       C       B       C       B       B      
 [82] C       B       B       B       C       B       B       B       C      
 [91] B       C       C       B       C       A       C       C       C      
[100] A       C       B       C       B       C       C       C       B      
[109] C       B       B       B       C       C       C       Missing C      
[118] B       C       C       B       B       C       C       C       C      
[127] C       B       B       C       B       C       B       C       B      
[136] C       Missing B       B       Missing Missing B       C       B      
[145] B       C       Missing C       B      
Levels: A B C Missing

Finally, we can use our knowledge so far to present a descriptive table for qualitative variables showing frequency (percentage) for the variable infection by the variable death following the steps:

tab_ql <- dt %>% 
  group_by(., death) %>% 
  mutate(across(where(is.factor), 
                fct_explicit_na,
                na_level = "Missing")) %>%
  select(where(is.factor)) %>%
  pivot_longer(cols =  -death,
               names_to = "variable",
               values_to = "group") %>%
  group_by(death, variable, group) %>%
  summarise (freq = n()) %>%
  mutate(
    perc = ifelse(group != "Missing", 100 * freq / sum(freq), NA),
    perc = ifelse(group != "Missing", round(perc, 2), perc),
    freq.perc = ifelse(group != "Missing", glue("{freq}  ({perc}%)"), freq)
  ) %>%
  select(-perc, -freq) %>%
  pivot_wider(names_from = death,
              names_prefix = "Death: ",
              values_from = freq.perc) %>%
  replace_na(list(`Death: Yes` = "0")) %>%
  rename(Variable = variable, " " = group)

The R-package kableExtra allows us to format a table:

kable(tab_ql) %>% 
  kable_styling(full_width = FALSE)
Variable Death: No Death: Yes
ascites No 31 (27.43%) 5 (13.89%)
ascites Yes 82 (72.57%) 31 (86.11%)
child A 4 (3.54%) 1 (2.78%)
child B 57 (50.44%) 13 (36.11%)
child C 45 (39.82%) 22 (61.11%)
child Missing 7 0
encephalopathy No 44 (38.94%) 17 (47.22%)
encephalopathy Yes 69 (61.06%) 19 (52.78%)
infection No 64 (56.64%) 13 (36.11%)
infection Yes 49 (43.36%) 23 (63.89%)
sex Female 26 (23.01%) 8 (22.22%)
sex Male 87 (76.99%) 28 (77.78%)

Quantitative variables

Quantitative variables can be summarized by mean \(\pm\) sd, median (quantile 25% - quantile 75%), median (min - max). We learned in class to do a descriptive table using mean \(\pm\) sd.

In class, we created the function missing with the extra argument na.rm to ensure that will have a similar behavior of the functions mean and sd:

missing <- function(x, na.rm = TRUE){
  out <- sum(is.na(x))
  return(out)
}

Then,

tab_qt <- dt %>% 
  group_by(., death) %>% 
  select(., -id) %>%
  summarise(across(.cols = where(is.numeric), 
                   .fns = list(mean = mean, sd = sd, missing = missing), 
                   na.rm = TRUE)) %>%
  pivot_longer(., -death, names_to = c("variable", "measure"), 
               values_to = "value", names_sep = "_") %>%
  pivot_wider(., names_from = measure, values_from = value) %>%
  mutate(., mean = round(mean, 2), sd = round(sd, 2)) %>%
  mutate(., mean_sd = glue("{mean} \u00B1 {sd}"),
         missing = as.character(missing)) %>%
  select(-c(mean, sd)) %>%
  pivot_longer(., 
               cols = missing:mean_sd,
               names_to = "measure", 
               values_to = "value") %>%
  mutate(., measure = 
           factor(measure, levels = c("mean_sd", "missing"))) %>%
  group_by(., death, variable) %>%
  arrange(., measure, .by_group = TRUE) %>%
  pivot_wider(.,
              names_from = death, 
              values_from = value,
              names_prefix = "Death: ") %>%
  mutate(.,
         measure = case_when(measure == "mean_sd" ~ "Mean \u00B1 SD",
                             measure == "missing" ~ "Missing")
         ) %>%
  filter(., 
         measure != "Missing" | (measure == "Missing" &  
                                   (`Death: No` != 0 | `Death: Yes` != 0))) %>%
  rename(., 
         Variable = variable,
         " " = measure) %>%
  ungroup()

kbl(tab_qt) %>% 
  kable_styling(full_width = FALSE) 
Variable Death: No Death: Yes
age Mean ± SD 58.26 ± 10.72 57.75 ± 10.46
albumin Mean ± SD 2.87 ± 0.61 2.65 ± 0.66
albumin Missing 7 1
bilirubin Mean ± SD 3.83 ± 5.08 4.9 ± 4.68
bilirubin Missing 1 0
creatinine Mean ± SD 1.46 ± 1.25 2.7 ± 1.66
crp Mean ± SD 50.51 ± 60.29 87.84 ± 104.63
crp Missing 36 7
dbp Mean ± SD 69.61 ± 16.69 63.39 ± 16.21
dbp Missing 17 8
glasgow Mean ± SD 14 ± 1.63 14.22 ± 1.39
glasgow Missing 8 4
hr Mean ± SD 86.06 ± 18.41 87.07 ± 15.58
hr Missing 14 6
inr Mean ± SD 1.56 ± 0.46 2.05 ± 0.92
inr Missing 3 0
leukocytes Mean ± SD 8680.25 ± 5323.42 11031.67 ± 6452.84
los Mean ± SD 6.05 ± 8.26 15.94 ± 17.84
lymphocytes Mean ± SD 1389.38 ± 942.11 1269.44 ± 719.05
meld Mean ± SD 17.54 ± 6.61 26.11 ± 9.12
meld Missing 4 0
neutrophil Mean ± SD 6148.67 ± 4629.18 8719.44 ± 5962.45
sbp Mean ± SD 117.5 ± 25.3 106.32 ± 25.29
sbp Missing 17 8
sodium Mean ± SD 135.72 ± 6.37 133.08 ± 5.65
sodium Missing 1 0

Formatting tables

We can stack both previous tables to obtain only one descriptive table.

tab <- bind_rows(tab_ql, tab_qt)
tab
# A tibble: 38 × 4
# Groups:   Variable [21]
   Variable       ` `     `Death: No`  `Death: Yes`
   <chr>          <chr>   <glue>       <glue>      
 1 ascites        No      31  (27.43%) 5  (13.89%) 
 2 ascites        Yes     82  (72.57%) 31  (86.11%)
 3 child          A       4  (3.54%)   1  (2.78%)  
 4 child          B       57  (50.44%) 13  (36.11%)
 5 child          C       45  (39.82%) 22  (61.11%)
 6 child          Missing 7            0           
 7 encephalopathy No      44  (38.94%) 17  (47.22%)
 8 encephalopathy Yes     69  (61.06%) 19  (52.78%)
 9 infection      No      64  (56.64%) 13  (36.11%)
10 infection      Yes     49  (43.36%) 23  (63.89%)
# … with 28 more rows

We can re-order the rows:

aux <- tab %>%
  mutate(., Variable = 
           factor(Variable, 
                  levels = c("age", "sex", 
                             "ascites", "encephalopathy", "infection", "child",
                             "dbp", "sbp", "glasgow", "hr", "meld", "los",
                             "albumin", "bilirubin", "creatinine", "crp",
                             "inr", "leukocytes", "lymphocytes", "neutrophil",
                             "sodium"),
                  labels = c("Age", "Sex", 
                             "Ascites", "Encephalopathy", "Infection", "CHILD-Pugh Score",
                             "DBP", "SBP", "Glasgow", "HR", "Meld", "Length of Stay",
                             "Albumin", "Bilirubin", "Creatinine", "CRP",
                             "INR", "Leukocytes", "Lymphocytes", "Neutrophil",
                             "Sodium")
                  )
         ) %>%
  arrange(., Variable)  %>%
  mutate(., Variable = as.character(Variable)) %>%
  ungroup()

print(aux, n = nrow(aux))
# A tibble: 38 × 4
   Variable         ` `       `Death: No`       `Death: Yes`      
   <chr>            <chr>     <glue>            <glue>            
 1 Age              Mean ± SD 58.26 ± 10.72     57.75 ± 10.46     
 2 Sex              Female    26  (23.01%)      8  (22.22%)       
 3 Sex              Male      87  (76.99%)      28  (77.78%)      
 4 Ascites          No        31  (27.43%)      5  (13.89%)       
 5 Ascites          Yes       82  (72.57%)      31  (86.11%)      
 6 Encephalopathy   No        44  (38.94%)      17  (47.22%)      
 7 Encephalopathy   Yes       69  (61.06%)      19  (52.78%)      
 8 Infection        No        64  (56.64%)      13  (36.11%)      
 9 Infection        Yes       49  (43.36%)      23  (63.89%)      
10 CHILD-Pugh Score A         4  (3.54%)        1  (2.78%)        
11 CHILD-Pugh Score B         57  (50.44%)      13  (36.11%)      
12 CHILD-Pugh Score C         45  (39.82%)      22  (61.11%)      
13 CHILD-Pugh Score Missing   7                 0                 
14 DBP              Mean ± SD 69.61 ± 16.69     63.39 ± 16.21     
15 DBP              Missing   17                8                 
16 SBP              Mean ± SD 117.5 ± 25.3      106.32 ± 25.29    
17 SBP              Missing   17                8                 
18 Glasgow          Mean ± SD 14 ± 1.63         14.22 ± 1.39      
19 Glasgow          Missing   8                 4                 
20 HR               Mean ± SD 86.06 ± 18.41     87.07 ± 15.58     
21 HR               Missing   14                6                 
22 Meld             Mean ± SD 17.54 ± 6.61      26.11 ± 9.12      
23 Meld             Missing   4                 0                 
24 Length of Stay   Mean ± SD 6.05 ± 8.26       15.94 ± 17.84     
25 Albumin          Mean ± SD 2.87 ± 0.61       2.65 ± 0.66       
26 Albumin          Missing   7                 1                 
27 Bilirubin        Mean ± SD 3.83 ± 5.08       4.9 ± 4.68        
28 Bilirubin        Missing   1                 0                 
29 Creatinine       Mean ± SD 1.46 ± 1.25       2.7 ± 1.66        
30 CRP              Mean ± SD 50.51 ± 60.29     87.84 ± 104.63    
31 CRP              Missing   36                7                 
32 INR              Mean ± SD 1.56 ± 0.46       2.05 ± 0.92       
33 INR              Missing   3                 0                 
34 Leukocytes       Mean ± SD 8680.25 ± 5323.42 11031.67 ± 6452.84
35 Lymphocytes      Mean ± SD 1389.38 ± 942.11  1269.44 ± 719.05  
36 Neutrophil       Mean ± SD 6148.67 ± 4629.18 8719.44 ± 5962.45 
37 Sodium           Mean ± SD 135.72 ± 6.37     133.08 ± 5.65     
38 Sodium           Missing   1                 0                 

Then, the table will be publishable with a few additional steps.

R-package kableExtra

More details about formatting a table using the package kablextra can be found here. Other themes are described here.

tab_final <- aux

kbl(tab_final, caption = "Descriptive table by death: Mean \u00B1 standard deviation and frequency (%)") %>% 
  collapse_rows(columns = 1, valign = "top") %>% 
  kable_styling(full_width = FALSE) %>% 
  kable_classic()
Descriptive table by death: Mean ± standard deviation and frequency (%)
Variable Death: No Death: Yes
Age Mean ± SD 58.26 ± 10.72 57.75 ± 10.46
Sex Female 26 (23.01%) 8 (22.22%)
Male 87 (76.99%) 28 (77.78%)
Ascites No 31 (27.43%) 5 (13.89%)
Yes 82 (72.57%) 31 (86.11%)
Encephalopathy No 44 (38.94%) 17 (47.22%)
Yes 69 (61.06%) 19 (52.78%)
Infection No 64 (56.64%) 13 (36.11%)
Yes 49 (43.36%) 23 (63.89%)
CHILD-Pugh Score A 4 (3.54%) 1 (2.78%)
B 57 (50.44%) 13 (36.11%)
C 45 (39.82%) 22 (61.11%)
Missing 7 0
DBP Mean ± SD 69.61 ± 16.69 63.39 ± 16.21
Missing 17 8
SBP Mean ± SD 117.5 ± 25.3 106.32 ± 25.29
Missing 17 8
Glasgow Mean ± SD 14 ± 1.63 14.22 ± 1.39
Missing 8 4
HR Mean ± SD 86.06 ± 18.41 87.07 ± 15.58
Missing 14 6
Meld Mean ± SD 17.54 ± 6.61 26.11 ± 9.12
Missing 4 0
Length of Stay Mean ± SD 6.05 ± 8.26 15.94 ± 17.84
Albumin Mean ± SD 2.87 ± 0.61 2.65 ± 0.66
Missing 7 1
Bilirubin Mean ± SD 3.83 ± 5.08 4.9 ± 4.68
Missing 1 0
Creatinine Mean ± SD 1.46 ± 1.25 2.7 ± 1.66
CRP Mean ± SD 50.51 ± 60.29 87.84 ± 104.63
Missing 36 7
INR Mean ± SD 1.56 ± 0.46 2.05 ± 0.92
Missing 3 0
Leukocytes Mean ± SD 8680.25 ± 5323.42 11031.67 ± 6452.84
Lymphocytes Mean ± SD 1389.38 ± 942.11 1269.44 ± 719.05
Neutrophil Mean ± SD 6148.67 ± 4629.18 8719.44 ± 5962.45
Sodium Mean ± SD 135.72 ± 6.37 133.08 ± 5.65
Missing 1 0

R-package gt

tab_final <- aux 

gt(tab_final, 
   rowname_col = " ",
   groupname_col = "Variable") %>% 
  tab_header(title = "Descriptive table by death",
             subtitle = "Mean \u00B1 SD and frequency (%)")
Descriptive table by death
Mean ± SD and frequency (%)
Death: No Death: Yes
Age
Mean ± SD 58.26 ± 10.72 57.75 ± 10.46
Sex
Female 26 (23.01%) 8 (22.22%)
Male 87 (76.99%) 28 (77.78%)
Ascites
No 31 (27.43%) 5 (13.89%)
Yes 82 (72.57%) 31 (86.11%)
Encephalopathy
No 44 (38.94%) 17 (47.22%)
Yes 69 (61.06%) 19 (52.78%)
Infection
No 64 (56.64%) 13 (36.11%)
Yes 49 (43.36%) 23 (63.89%)
CHILD-Pugh Score
A 4 (3.54%) 1 (2.78%)
B 57 (50.44%) 13 (36.11%)
C 45 (39.82%) 22 (61.11%)
Missing 7 0
DBP
Mean ± SD 69.61 ± 16.69 63.39 ± 16.21
Missing 17 8
SBP
Mean ± SD 117.5 ± 25.3 106.32 ± 25.29
Missing 17 8
Glasgow
Mean ± SD 14 ± 1.63 14.22 ± 1.39
Missing 8 4
HR
Mean ± SD 86.06 ± 18.41 87.07 ± 15.58
Missing 14 6
Meld
Mean ± SD 17.54 ± 6.61 26.11 ± 9.12
Missing 4 0
Length of Stay
Mean ± SD 6.05 ± 8.26 15.94 ± 17.84
Albumin
Mean ± SD 2.87 ± 0.61 2.65 ± 0.66
Missing 7 1
Bilirubin
Mean ± SD 3.83 ± 5.08 4.9 ± 4.68
Missing 1 0
Creatinine
Mean ± SD 1.46 ± 1.25 2.7 ± 1.66
CRP
Mean ± SD 50.51 ± 60.29 87.84 ± 104.63
Missing 36 7
INR
Mean ± SD 1.56 ± 0.46 2.05 ± 0.92
Missing 3 0
Leukocytes
Mean ± SD 8680.25 ± 5323.42 11031.67 ± 6452.84
Lymphocytes
Mean ± SD 1389.38 ± 942.11 1269.44 ± 719.05
Neutrophil
Mean ± SD 6148.67 ± 4629.18 8719.44 ± 5962.45
Sodium
Mean ± SD 135.72 ± 6.37 133.08 ± 5.65
Missing 1 0

Task 1

Repeat the steps above and comment your code for each step describing what each function is doing at each step.

Task 2

Include the additional descriptive statistics in the descriptive table above:

  1. median (minimum ; maximum);
Hint

The function summarise accepts as many functions as we want to.

  1. median (quantile 25% ; quantile 75%)
Hint

Please remember the conditions to use functions within across.

See the expected tables below:

Median (Minimum - Maximum)

Descriptive table by death with mean ± standard deviation, median (range) and frequency (%)
Variable Death: No Death: Yes
Age Mean ± SD 58.26 ± 10.72 57.75 ± 10.46
Median (Min ; Max) 60 (18 ; 81) 56.5 (32 ; 78)
Sex Female 26 (23.01%) 8 (22.22%)
Male 87 (76.99%) 28 (77.78%)
Ascites No 31 (27.43%) 5 (13.89%)
Yes 82 (72.57%) 31 (86.11%)
Encephalopathy No 44 (38.94%) 17 (47.22%)
Yes 69 (61.06%) 19 (52.78%)
Infection No 64 (56.64%) 13 (36.11%)
Yes 49 (43.36%) 23 (63.89%)
CHILD-Pugh Score A 4 (3.54%) 1 (2.78%)
B 57 (50.44%) 13 (36.11%)
C 45 (39.82%) 22 (61.11%)
Missing 7 0
DBP Mean ± SD 69.61 ± 16.69 63.39 ± 16.21
Median (Min ; Max) 70 (30 ; 112) 60 (38 ; 100)
Missing 17 8
SBP Mean ± SD 117.5 ± 25.3 106.32 ± 25.29
Median (Min ; Max) 118 (60 ; 200) 100 (63 ; 160)
Missing 17 8
Glasgow Mean ± SD 14 ± 1.63 14.22 ± 1.39
Median (Min ; Max) 14 (5 ; 15) 14.5 (8 ; 15)
Missing 8 4
HR Mean ± SD 86.06 ± 18.41 87.07 ± 15.58
Median (Min ; Max) 86 (48 ; 140) 86.5 (56 ; 115)
Missing 14 6
Meld Mean ± SD 17.54 ± 6.61 26.11 ± 9.12
Median (Min ; Max) 17.15 (5.85 ; 35.27) 26.69 (11.8 ; 45.48)
Missing 4 0
Length of Stay Mean ± SD 6.05 ± 8.26 15.94 ± 17.84
Median (Min ; Max) 4 (0 ; 72) 10 (0 ; 92)
Albumin Mean ± SD 2.87 ± 0.61 2.65 ± 0.66
Median (Min ; Max) 2.8 (1.5 ; 4.4) 2.5 (1.8 ; 4.7)
Missing 7 1
Bilirubin Mean ± SD 3.83 ± 5.08 4.9 ± 4.68
Median (Min ; Max) 1.99 (0.3 ; 39.05) 3.51 (0.31 ; 18.3)
Missing 1 0
Creatinine Mean ± SD 1.46 ± 1.25 2.7 ± 1.66
Median (Min ; Max) 1.1 (0.46 ; 11.35) 2.47 (0.41 ; 6.05)
CRP Mean ± SD 50.51 ± 60.29 87.84 ± 104.63
Median (Min ; Max) 28.1 (0.2 ; 230.7) 59.4 (1.9 ; 436)
Missing 36 7
INR Mean ± SD 1.56 ± 0.46 2.05 ± 0.92
Median (Min ; Max) 1.5 (0.95 ; 4.12) 1.68 (0.95 ; 4.8)
Missing 3 0
Leukocytes Mean ± SD 8680.25 ± 5323.42 11031.67 ± 6452.84
Median (Min ; Max) 7610 (1180 ; 35620) 9575 (2890 ; 38920)
Lymphocytes Mean ± SD 1389.38 ± 942.11 1269.44 ± 719.05
Median (Min ; Max) 1200 (100 ; 6400) 1200 (300 ; 3500)
Neutrophil Mean ± SD 6148.67 ± 4629.18 8719.44 ± 5962.45
Median (Min ; Max) 5200 (700 ; 29700) 7950 (1600 ; 34700)
Sodium Mean ± SD 135.72 ± 6.37 133.08 ± 5.65
Median (Min ; Max) 137 (116 ; 148) 133 (119 ; 143)
Missing 1 0

Median (Quantile 25% - Quantile 75%)

Descriptive table by death with mean ± standard deviation, median (quantiles 25%, 75%) and frequency (%)
Variable Death: No Death: Yes
Age Mean ± SD 58.26 ± 10.72 57.75 ± 10.46
Median (Q25% ; Q75%) 60 (52 ; 66) 56.5 (52 ; 65.25)
Sex Female 26 (23.01%) 8 (22.22%)
Male 87 (76.99%) 28 (77.78%)
Ascites No 31 (27.43%) 5 (13.89%)
Yes 82 (72.57%) 31 (86.11%)
Encephalopathy No 44 (38.94%) 17 (47.22%)
Yes 69 (61.06%) 19 (52.78%)
Infection No 64 (56.64%) 13 (36.11%)
Yes 49 (43.36%) 23 (63.89%)
CHILD-Pugh Score A 4 (3.54%) 1 (2.78%)
B 57 (50.44%) 13 (36.11%)
C 45 (39.82%) 22 (61.11%)
Missing 7 0
DBP Mean ± SD 69.61 ± 16.69 63.39 ± 16.21
Median (Q25% ; Q75%) 70 (60 ; 80) 60 (51.5 ; 77)
Missing 17 8
SBP Mean ± SD 117.5 ± 25.3 106.32 ± 25.29
Median (Q25% ; Q75%) 118 (100 ; 130) 100 (89.75 ; 124)
Missing 17 8
Glasgow Mean ± SD 14 ± 1.63 14.22 ± 1.39
Median (Q25% ; Q75%) 14 (14 ; 15) 14.5 (14 ; 15)
Missing 8 4
HR Mean ± SD 86.06 ± 18.41 87.07 ± 15.58
Median (Q25% ; Q75%) 86 (74 ; 99) 86.5 (75.75 ; 98.25)
Missing 14 6
Meld Mean ± SD 17.54 ± 6.61 26.11 ± 9.12
Median (Q25% ; Q75%) 17.15 (12.87 ; 21.66) 26.69 (18.11 ; 32.96)
Missing 4 0
Length of Stay Mean ± SD 6.05 ± 8.26 15.94 ± 17.84
Median (Q25% ; Q75%) 4 (2 ; 8) 10 (5 ; 18.25)
Albumin Mean ± SD 2.87 ± 0.61 2.65 ± 0.66
Median (Q25% ; Q75%) 2.8 (2.42 ; 3.3) 2.5 (2.1 ; 2.9)
Missing 7 1
Bilirubin Mean ± SD 3.83 ± 5.08 4.9 ± 4.68
Median (Q25% ; Q75%) 1.99 (1.17 ; 4.07) 3.51 (1.54 ; 6.53)
Missing 1 0
Creatinine Mean ± SD 1.46 ± 1.25 2.7 ± 1.66
Median (Q25% ; Q75%) 1.1 (0.82 ; 1.69) 2.47 (1.28 ; 3.85)
CRP Mean ± SD 50.51 ± 60.29 87.84 ± 104.63
Median (Q25% ; Q75%) 28.1 (7.93 ; 62) 59.4 (18 ; 122.8)
Missing 36 7
INR Mean ± SD 1.56 ± 0.46 2.05 ± 0.92
Median (Q25% ; Q75%) 1.5 (1.3 ; 1.6) 1.68 (1.49 ; 2.32)
Missing 3 0
Leukocytes Mean ± SD 8680.25 ± 5323.42 11031.67 ± 6452.84
Median (Q25% ; Q75%) 7610 (5380 ; 10240) 9575 (6955 ; 13590)
Lymphocytes Mean ± SD 1389.38 ± 942.11 1269.44 ± 719.05
Median (Q25% ; Q75%) 1200 (800 ; 1800) 1200 (800 ; 1425)
Neutrophil Mean ± SD 6148.67 ± 4629.18 8719.44 ± 5962.45
Median (Q25% ; Q75%) 5200 (3300 ; 7100) 7950 (4375 ; 11025)
Sodium Mean ± SD 135.72 ± 6.37 133.08 ± 5.65
Median (Q25% ; Q75%) 137 (132 ; 140) 133 (130.75 ; 137)
Missing 1 0

Task 3

Install the R-package gtsummary. Create one of the tables from Task 2 using the functions in gtsummary.

Hint

Check out the tutorial for the function tbl_summary.