#paquetes

library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'ggplot2' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## Warning: package 'forcats' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.1     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(gtsummary)
## Warning: package 'gtsummary' was built under R version 4.2.3
library(gt)
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 4.2.3
library(readxl)
## Warning: package 'readxl' was built under R version 4.2.3
FIDEL_OSUNA_RAG_HIPOALBUMINEMIA_PREECLAMPSIA <- read_excel("C:/Users/fidel/OneDrive - UNIVERSIDAD AUTONOMA DE SINALOA/COLABS/DrMurillo HMujer/Precalmpsia/FIDEL OSUNA RAG HIPOALBUMINEMIA PREECLAMPSIA.xls")

dbhm<-FIDEL_OSUNA_RAG_HIPOALBUMINEMIA_PREECLAMPSIA

names(dbhm)
##  [1] "nombre"        "fecha22"       "edad"          "cesarea"      
##  [5] "sdg"           "gestas"        "compfet"       "sana"         
##  [9] "htg"           "pens"          "pese"          "imc"          
## [13] "leucos"        "neutro"        "linfos"        "plaq"         
## [17] "pcr"           "dhl"           "creat"         "urea"         
## [21] "un"            "prot24"        "acu"           "ca"           
## [25] "mg"            "album"         "glog"          "rag"          
## [29] "observaciones" "HIPOALBUM"     "HIPOGLOB"      "hipalbglob"   
## [33] "RAG127"        "patologia"     "agr1"          "agr2"         
## [37] "agr3"          "Ptardia"       "raghtg"        "ragPtar"      
## [41] "ragPns"        "var45"         "var44"         "PEtmp"        
## [45] "compMat"       "PCO"
str(dbhm)
## tibble [223 × 46] (S3: tbl_df/tbl/data.frame)
##  $ nombre       : chr [1:223] "VALENUELA LOPEZ  CLAUDIA YADIRA" "ANGULO MARTINEZ ROSINA NOHEMI" "CORONEL GUEVARA YAHAIRA GUADALUPE" "MEZA AMBROCIO LURDES" ...
##  $ fecha22      : num [1:223] 1601 611 2310 901 701 ...
##  $ edad         : num [1:223] 31 22 32 31 33 29 36 28 18 20 ...
##  $ cesarea      : num [1:223] 1 1 1 0 NA 1 NA 1 1 0 ...
##  $ sdg          : num [1:223] 38.1 37.3 39.6 34 24.6 39.1 23.5 38.3 38.5 37.1 ...
##  $ gestas       : num [1:223] 2 2 3 4 2 3 3 3 1 1 ...
##  $ compfet      : num [1:223] 0 0 0 0 1 0 0 0 0 0 ...
##  $ sana         : num [1:223] 0 0 0 0 0 0 0 0 0 0 ...
##  $ htg          : num [1:223] 0 0 1 1 0 1 0 1 0 0 ...
##  $ pens         : num [1:223] 1 0 0 0 0 0 0 0 0 1 ...
##  $ pese         : num [1:223] 0 0 0 0 0 0 0 0 0 0 ...
##  $ imc          : num [1:223] 23.1 27.6 39.7 33 23.2 ...
##  $ leucos       : num [1:223] 7350 13330 13070 9980 11620 ...
##  $ neutro       : num [1:223] 67.2 70.6 65.9 59.9 74.4 77 82.6 75.5 66.1 78.4 ...
##  $ linfos       : num [1:223] 27.1 16.1 24.6 29.9 19.6 15.8 9.1 15.6 24.3 17 ...
##  $ plaq         : num [1:223] 143 356 278 298 295 242 303 205 175 297 ...
##  $ pcr          : num [1:223] NA 13 NA NA NA ...
##  $ dhl          : num [1:223] 194 121 215 184 165 241 167 170 182 198 ...
##  $ creat        : num [1:223] 0.62 0.51 0.62 0.52 0.69 0.86 0.42 0.54 0.52 0.55 ...
##  $ urea         : num [1:223] 19.2 11.8 17.9 16.6 13.4 20.4 11.5 19.7 14.5 12.6 ...
##  $ un           : num [1:223] 9 NA 8.4 7.8 6.3 7.5 5.4 9.2 6.8 5.9 ...
##  $ prot24       : num [1:223] 329 NA NA 204 NA ...
##  $ acu          : num [1:223] 5.5 3.3 7.3 4.2 3.7 5.6 3.5 3.5 3.6 4.1 ...
##  $ ca           : num [1:223] 8.52 9.22 9.61 9.86 9.74 ...
##  $ mg           : num [1:223] 1.93 1.74 1.95 1.88 1.99 NA 1.87 1.73 1.51 1.78 ...
##  $ album        : num [1:223] 3.5 3.25 3.86 3.66 4.28 2.92 4.08 3.21 3.6 4.1 ...
##  $ glog         : num [1:223] 3.04 2.78 2.87 2.88 2.83 2.38 3.02 2.85 3 2.81 ...
##  $ rag          : num [1:223] 1.15 1.17 1.14 1.27 1.51 1.23 1.35 1.13 1.2 1.46 ...
##  $ observaciones: chr [1:223] "IVU" "OLIGODR" "HTG" NA ...
##  $ HIPOALBUM    : num [1:223] 0 1 0 0 0 1 0 1 0 0 ...
##  $ HIPOGLOB     : num [1:223] 1 1 1 1 1 1 1 1 1 1 ...
##  $ hipalbglob   : num [1:223] 0 1 0 0 0 1 0 1 0 0 ...
##  $ RAG127       : num [1:223] 1 1 1 1 0 1 0 1 1 0 ...
##  $ patologia    : chr [1:223] "PENS" "Sin resultado" "HTG" "HTG" ...
##  $ agr1         : num [1:223] 0 0 0 0 0 0 0 0 0 0 ...
##  $ agr2         : num [1:223] 1 1 1 1 0 1 0 1 1 0 ...
##  $ agr3         : num [1:223] 0 0 0 0 1 0 1 0 0 1 ...
##  $ Ptardia      : num [1:223] 1 0 0 0 0 0 0 0 0 1 ...
##  $ raghtg       : num [1:223] NA NA 1.14 1.27 NA NA NA 1.13 NA NA ...
##  $ ragPtar      : num [1:223] 1.15 1.17 1.14 1.27 NA 1.23 NA 1.13 1.2 1.46 ...
##  $ ragPns       : num [1:223] 1.15 NA NA NA NA NA NA NA NA 1.46 ...
##  $ var45        : num [1:223] NA NA NA NA 183 NA 43 NA NA NA ...
##  $ var44        : num [1:223] NA NA NA NA NA NA NA NA NA NA ...
##  $ PEtmp        : num [1:223] 0 0 0 0 0 0 0 0 0 0 ...
##  $ compMat      : num [1:223] 1 1 1 0 1 0 0 1 1 1 ...
##  $ PCO          : num [1:223] 23.6 22 25.5 22.7 27.8 ...
#dbhm <- dbhm %>% filter(patologia != "Sin resultado")


dbhm %>% select(sana, pens, pese) %>% tbl_summary()
Characteristic N = 2231
sana 35 (16%)
pens 42 (19%)
pese 43 (19%)
1 n (%)

#hacer una tabla por patologia

pensgtsumm<-dbhm %>% select(edad,cesarea,sdg,gestas,compfet,imc,leucos,neutro,linfos,plaq,pcr,dhl,creat,    urea,   un, prot24, acu,ca,mg,album,    glog,   rag,PCO,HIPOALBUM,HIPOGLOB, hipalbglob, RAG127,pens) %>% tbl_summary(by=pens) %>% add_p() %>% add_overall() 
## Warning for variable 'pcr':
## simpleWarning in wilcox.test.default(x = DATA[[1L]], y = DATA[[2L]], ...): cannot compute exact p-value with ties
pensgtsumm
Characteristic Overall, N = 2231 0, N = 1811 1, N = 421 p-value2
edad 25 (20, 30) 25 (21, 31) 24 (18, 29) 0.2
cesarea 119 (63%) 100 (64%) 19 (58%) 0.5
    Unknown 34 25 9
sdg 37.9 (35.0, 39.0) 38.0 (34.9, 39.0) 37.5 (35.1, 39.0) 0.9
    Unknown 1 1 0
gestas >0.9
    1 72 (32%) 55 (30%) 17 (40%)
    2 66 (30%) 53 (29%) 13 (31%)
    3 40 (18%) 34 (19%) 6 (14%)
    4 29 (13%) 24 (13%) 5 (12%)
    5 5 (2.2%) 5 (2.8%) 0 (0%)
    6 6 (2.7%) 5 (2.8%) 1 (2.4%)
    7 3 (1.3%) 3 (1.7%) 0 (0%)
    8 2 (0.9%) 2 (1.1%) 0 (0%)
compfet 8 (3.7%) 7 (3.9%) 1 (2.5%) >0.9
    Unknown 5 3 2
imc 29.8 (25.6, 34.5) 29.2 (25.5, 34.4) 33.0 (28.2, 35.5) 0.14
    Unknown 23 18 5
leucos 10,365 (8,600, 12,958) 10,210 (8,490, 12,975) 11,015 (9,372, 12,832) 0.3
    Unknown 1 1 0
neutro 74 (67, 79) 74 (67, 79) 73 (68, 78) >0.9
    Unknown 3 1 2
linfos 18 (14, 24) 18 (13, 23) 18 (15, 24) 0.9
    Unknown 3 1 2
plaq 219 (146, 278) 210 (142, 279) 240 (208, 275) 0.060
    Unknown 1 1 0
pcr 41 (20, 86) 40 (19, 86) 79 (50, 80) 0.4
    Unknown 171 134 37
dhl 186 (162, 226) 188 (166, 228) 182 (149, 208) 0.083
    Unknown 7 7 0
creat 0.55 (0.49, 0.62) 0.55 (0.49, 0.63) 0.54 (0.49, 0.58) 0.2
urea 16 (13, 20) 16 (13, 20) 14 (11, 16) 0.009
un 7.40 (5.90, 9.20) 7.50 (6.10, 9.35) 6.30 (5.25, 7.70) 0.013
    Unknown 17 14 3
prot24 348 (257, 557) 282 (208, 502) 384 (343, 560) 0.003
    Unknown 119 116 3
acu 4.60 (3.70, 5.60) 4.60 (3.70, 5.70) 4.40 (3.53, 5.50) 0.3
    Unknown 7 7 0
ca 9.21 (8.89, 9.48) 9.18 (8.80, 9.44) 9.40 (9.13, 9.65) 0.005
    Unknown 14 12 2
mg 1.85 (1.74, 1.95) 1.86 (1.74, 1.97) 1.83 (1.76, 1.93) 0.3
    Unknown 17 16 1
album 3.66 (3.36, 3.91) 3.66 (3.30, 3.88) 3.72 (3.46, 3.94) 0.2
    Unknown 4 4 0
glog 2.71 (2.49, 2.95) 2.71 (2.44, 2.97) 2.75 (2.59, 2.94) 0.6
    Unknown 5 5 0
rag 1.34 (1.21, 1.47) 1.34 (1.20, 1.47) 1.37 (1.28, 1.44) 0.6
    Unknown 5 5 0
PCO 23.40 (21.76, 25.10) 23.40 (21.74, 25.10) 23.52 (22.11, 25.67) 0.5
    Unknown 152 122 30
HIPOALBUM 80 (37%) 68 (39%) 12 (29%) 0.2
    Unknown 5 5 0
HIPOGLOB 197 (90%) 159 (90%) 38 (90%) >0.9
    Unknown 5 5 0
hipalbglob 77 (35%) 65 (37%) 12 (29%) 0.3
    Unknown 6 6 0
RAG127 78 (36%) 67 (38%) 11 (26%) 0.15
    Unknown 5 5 0
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Pearson's Chi-squared test; Fisher's exact test
pesegtsumm<-dbhm %>% select(edad,cesarea,sdg,gestas,compfet,imc,leucos,neutro,linfos,plaq,pcr,dhl,creat,    urea,   un, prot24, acu,ca,mg,album,    glog,   rag,PCO,HIPOALBUM,HIPOGLOB, hipalbglob, RAG127,pese) %>% tbl_summary(by=pese) %>% add_p()
## Warning for variable 'pcr':
## simpleWarning in wilcox.test.default(x = DATA[[1L]], y = DATA[[2L]], ...): cannot compute exact p-value with ties
## Warning for variable 'PCO':
## simpleWarning in wilcox.test.default(x = DATA[[1L]], y = DATA[[2L]], ...): cannot compute exact p-value with ties
pesegtsumm
Characteristic 0, N = 1801 1, N = 431 p-value2
edad 25 (21, 30) 25 (19, 31) 0.8
cesarea 88 (59%) 31 (78%) 0.032
    Unknown 31 3
sdg 38.0 (34.9, 39.1) 37.4 (35.6, 38.3) 0.4
    Unknown 0 1
gestas 0.018
    1 59 (33%) 13 (30%)
    2 51 (28%) 15 (35%)
    3 37 (21%) 3 (7.0%)
    4 24 (13%) 5 (12%)
    5 4 (2.2%) 1 (2.3%)
    6 4 (2.2%) 2 (4.7%)
    7 1 (0.6%) 2 (4.7%)
    8 0 (0%) 2 (4.7%)
compfet 6 (3.4%) 2 (4.7%) 0.7
    Unknown 5 0
imc 29.8 (25.7, 34.2) 29.7 (24.5, 36.4) 0.7
    Unknown 20 3
leucos 10,430 (8,570, 13,045) 9,910 (8,660, 12,030) 0.3
    Unknown 1 0
neutro 74 (68, 79) 73 (64, 78) 0.2
    Unknown 3 0
linfos 18 (14, 23) 20 (16, 27) 0.042
    Unknown 3 0
plaq 220 (149, 276) 191 (120, 304) 0.3
    Unknown 1 0
pcr 50 (24, 91) 28 (15, 32) 0.042
    Unknown 141 30
dhl 183 (159, 218) 224 (178, 270) <0.001
    Unknown 7 0
creat 0.54 (0.49, 0.59) 0.61 (0.50, 0.69) 0.014
urea 15 (12, 19) 18 (14, 22) 0.006
un 7.20 (5.77, 8.75) 8.65 (6.82, 10.55) 0.005
    Unknown 16 1
prot24 332 (242, 412) 441 (286, 1,289) 0.024
    Unknown 116 3
acu 4.40 (3.60, 5.30) 5.70 (4.30, 6.95) <0.001
    Unknown 7 0
ca 9.25 (8.96, 9.53) 8.90 (8.66, 9.35) <0.001
    Unknown 13 1
mg 1.84 (1.74, 1.94) 1.92 (1.75, 2.02) 0.052
    Unknown 16 1
album 3.70 (3.41, 3.97) 3.42 (3.14, 3.75) <0.001
    Unknown 4 0
glog 2.72 (2.50, 2.95) 2.68 (2.42, 2.97) 0.6
    Unknown 4 1
rag 1.35 (1.23, 1.47) 1.27 (1.14, 1.45) 0.040
    Unknown 4 1
PCO 24.87 (21.97, 26.15) 23.28 (21.65, 24.86) 0.054
    Unknown 151 1
HIPOALBUM 54 (31%) 26 (60%) <0.001
    Unknown 5 0
HIPOGLOB 159 (90%) 38 (90%) >0.9
    Unknown 4 1
hipalbglob 53 (30%) 24 (57%) 0.001
    Unknown 5 1
RAG127 56 (32%) 22 (52%) 0.012
    Unknown 4 1
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Pearson's Chi-squared test; Fisher's exact test
tbl_merge(
  tbls = list(pensgtsumm,pesegtsumm),                          # combine
  tab_spanner = c("**PENS**", "**PESE**"))
Characteristic PENS PESE
Overall, N = 2231 0, N = 1811 1, N = 421 p-value2 0, N = 1801 1, N = 431 p-value2
edad 25 (20, 30) 25 (21, 31) 24 (18, 29) 0.2 25 (21, 30) 25 (19, 31) 0.8
cesarea 119 (63%) 100 (64%) 19 (58%) 0.5 88 (59%) 31 (78%) 0.032
    Unknown 34 25 9 31 3
sdg 37.9 (35.0, 39.0) 38.0 (34.9, 39.0) 37.5 (35.1, 39.0) 0.9 38.0 (34.9, 39.1) 37.4 (35.6, 38.3) 0.4
    Unknown 1 1 0 0 1
gestas >0.9 0.018
    1 72 (32%) 55 (30%) 17 (40%) 59 (33%) 13 (30%)
    2 66 (30%) 53 (29%) 13 (31%) 51 (28%) 15 (35%)
    3 40 (18%) 34 (19%) 6 (14%) 37 (21%) 3 (7.0%)
    4 29 (13%) 24 (13%) 5 (12%) 24 (13%) 5 (12%)
    5 5 (2.2%) 5 (2.8%) 0 (0%) 4 (2.2%) 1 (2.3%)
    6 6 (2.7%) 5 (2.8%) 1 (2.4%) 4 (2.2%) 2 (4.7%)
    7 3 (1.3%) 3 (1.7%) 0 (0%) 1 (0.6%) 2 (4.7%)
    8 2 (0.9%) 2 (1.1%) 0 (0%) 0 (0%) 2 (4.7%)
compfet 8 (3.7%) 7 (3.9%) 1 (2.5%) >0.9 6 (3.4%) 2 (4.7%) 0.7
    Unknown 5 3 2 5 0
imc 29.8 (25.6, 34.5) 29.2 (25.5, 34.4) 33.0 (28.2, 35.5) 0.14 29.8 (25.7, 34.2) 29.7 (24.5, 36.4) 0.7
    Unknown 23 18 5 20 3
leucos 10,365 (8,600, 12,958) 10,210 (8,490, 12,975) 11,015 (9,372, 12,832) 0.3 10,430 (8,570, 13,045) 9,910 (8,660, 12,030) 0.3
    Unknown 1 1 0 1 0
neutro 74 (67, 79) 74 (67, 79) 73 (68, 78) >0.9 74 (68, 79) 73 (64, 78) 0.2
    Unknown 3 1 2 3 0
linfos 18 (14, 24) 18 (13, 23) 18 (15, 24) 0.9 18 (14, 23) 20 (16, 27) 0.042
    Unknown 3 1 2 3 0
plaq 219 (146, 278) 210 (142, 279) 240 (208, 275) 0.060 220 (149, 276) 191 (120, 304) 0.3
    Unknown 1 1 0 1 0
pcr 41 (20, 86) 40 (19, 86) 79 (50, 80) 0.4 50 (24, 91) 28 (15, 32) 0.042
    Unknown 171 134 37 141 30
dhl 186 (162, 226) 188 (166, 228) 182 (149, 208) 0.083 183 (159, 218) 224 (178, 270) <0.001
    Unknown 7 7 0 7 0
creat 0.55 (0.49, 0.62) 0.55 (0.49, 0.63) 0.54 (0.49, 0.58) 0.2 0.54 (0.49, 0.59) 0.61 (0.50, 0.69) 0.014
urea 16 (13, 20) 16 (13, 20) 14 (11, 16) 0.009 15 (12, 19) 18 (14, 22) 0.006
un 7.40 (5.90, 9.20) 7.50 (6.10, 9.35) 6.30 (5.25, 7.70) 0.013 7.20 (5.77, 8.75) 8.65 (6.82, 10.55) 0.005
    Unknown 17 14 3 16 1
prot24 348 (257, 557) 282 (208, 502) 384 (343, 560) 0.003 332 (242, 412) 441 (286, 1,289) 0.024
    Unknown 119 116 3 116 3
acu 4.60 (3.70, 5.60) 4.60 (3.70, 5.70) 4.40 (3.53, 5.50) 0.3 4.40 (3.60, 5.30) 5.70 (4.30, 6.95) <0.001
    Unknown 7 7 0 7 0
ca 9.21 (8.89, 9.48) 9.18 (8.80, 9.44) 9.40 (9.13, 9.65) 0.005 9.25 (8.96, 9.53) 8.90 (8.66, 9.35) <0.001
    Unknown 14 12 2 13 1
mg 1.85 (1.74, 1.95) 1.86 (1.74, 1.97) 1.83 (1.76, 1.93) 0.3 1.84 (1.74, 1.94) 1.92 (1.75, 2.02) 0.052
    Unknown 17 16 1 16 1
album 3.66 (3.36, 3.91) 3.66 (3.30, 3.88) 3.72 (3.46, 3.94) 0.2 3.70 (3.41, 3.97) 3.42 (3.14, 3.75) <0.001
    Unknown 4 4 0 4 0
glog 2.71 (2.49, 2.95) 2.71 (2.44, 2.97) 2.75 (2.59, 2.94) 0.6 2.72 (2.50, 2.95) 2.68 (2.42, 2.97) 0.6
    Unknown 5 5 0 4 1
rag 1.34 (1.21, 1.47) 1.34 (1.20, 1.47) 1.37 (1.28, 1.44) 0.6 1.35 (1.23, 1.47) 1.27 (1.14, 1.45) 0.040
    Unknown 5 5 0 4 1
PCO 23.40 (21.76, 25.10) 23.40 (21.74, 25.10) 23.52 (22.11, 25.67) 0.5 24.87 (21.97, 26.15) 23.28 (21.65, 24.86) 0.054
    Unknown 152 122 30 151 1
HIPOALBUM 80 (37%) 68 (39%) 12 (29%) 0.2 54 (31%) 26 (60%) <0.001
    Unknown 5 5 0 5 0
HIPOGLOB 197 (90%) 159 (90%) 38 (90%) >0.9 159 (90%) 38 (90%) >0.9
    Unknown 5 5 0 4 1
hipalbglob 77 (35%) 65 (37%) 12 (29%) 0.3 53 (30%) 24 (57%) 0.001
    Unknown 6 6 0 5 1
RAG127 78 (36%) 67 (38%) 11 (26%) 0.15 56 (32%) 22 (52%) 0.012
    Unknown 5 5 0 4 1
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Pearson's Chi-squared test; Fisher's exact test
#Asumiendo que las columnas "Ptardia" y "PEtmp" ya existen en tu dataframe "dbhm"
dbhm <- dbhm %>%
  mutate(preclamp = case_when(
    Ptardia == 1 & PEtmp == 1 ~ 1, # Cuando ambos Ptardia y PEtmp son igual a 1
    TRUE ~ 0 # En cualquier otro caso
  ))
# Reorder the levels of 'patologia'
dbhm$patologia <- factor(dbhm$patologia, levels = c("Sana", "HTG", "PENS", "PESE"))


# Filter only for rows with desired categories in the 'patologia' column
dbhm <- dbhm[dbhm$patologia %in% c("Sana", "HTG", "PENS", "PESE"), ]

my_comparisons <- list(c("Sana", "HTG"), c("Sana", "PENS"), c("Sana", "PESE"))

# Create boxplots and add the p-value comparisons
albplt<-ggboxplot(dbhm, x = "patologia", y = "album", 
          color = "patologia", palette = c("#00AFBB", "#E7B800", "#FC4E07", "#0073C2")) +
  labs(title = "", 
       x = "Pathology", 
       y = "Albumin (??)", 
       color = "") +
  theme(legend.position='none')+
  stat_compare_means(comparisons = my_comparisons, method = NULL,
                     aes(label = paste0("p = ", after_stat(p.signif)))) + # Add pairwise comparisons p-value
  stat_compare_means(label.x = 2.5, label.y = 0.5, method = "kruskal.test") # Add overall p-value at lower left corner
albplt
## Warning: Removed 4 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 4 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 4 rows containing non-finite values (`stat_compare_means()`).

# Reorder the levels of 'patologia'
dbhm$patologia <- factor(dbhm$patologia, levels = c("Sana", "HTG", "PENS", "PESE"))


# Filter only for rows with desired categories in the 'patologia' column
dbhm <- dbhm[dbhm$patologia %in% c("Sana", "HTG", "PENS", "PESE"), ]

my_comparisons <- list(c("Sana", "HTG"), c("Sana", "PENS"), c("Sana", "PESE"))

# Create boxplots and add the p-value comparisons
ragplt<-ggboxplot(dbhm, x = "patologia", y = "rag", 
          color = "patologia", palette = c("#00AFBB", "#E7B800", "#FC4E07", "#0073C2")) +
  labs(title = "", 
       x = "Pathology", 
       y = "RAG (??)", 
       color = "") +
  theme(legend.position='none')+
  stat_compare_means(comparisons = my_comparisons, method = NULL,
                     aes(label = paste0("p = ", after_stat(p.signif)))) + # Add pairwise comparisons p-value
  stat_compare_means(label.x = 2.5, label.y = 0.5, method = "kruskal.test") # Add overall p-value at lower left corner
ragplt
## Warning: Removed 5 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 5 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 5 rows containing non-finite values (`stat_compare_means()`).

ggarrange(albplt,ragplt ,
          labels = c("A", "B"),align = "hv",
          ncol = 2, nrow = 1,font.label = list(size = 16, 
        color = "black", face = "bold", family = NULL))
## Warning: Removed 4 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 4 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 4 rows containing non-finite values (`stat_compare_means()`).
## Warning: Removed 5 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 5 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 5 rows containing non-finite values (`stat_compare_means()`).

# Reorder the levels of 'patologia'
dbhm$patologia <- factor(dbhm$patologia, levels = c("Sana", "HTG", "PENS", "PESE"))


# Filter only for rows with desired categories in the 'patologia' column
dbhm <- dbhm[dbhm$patologia %in% c("Sana", "HTG", "PENS", "PESE"), ]

my_comparisons <- list(c("Sana", "HTG"), c("Sana", "PENS"), c("Sana", "PESE"))

# Create boxplots and add the p-value comparisons
ggboxplot(dbhm, x = "patologia", y = "glog", 
          color = "patologia", palette = c("#00AFBB", "#E7B800", "#FC4E07", "#0073C2")) +
  labs(title = "", 
       x = "Pathology", 
       y = "Globulin (??) ", 
       color = "") +
  theme(legend.position='none')+
  stat_compare_means(comparisons = my_comparisons, method = NULL,
                     aes(label = paste0("p = ", after_stat(p.signif)))) + # Add pairwise comparisons p-value
  stat_compare_means(label.x = 3, label.y = 1.8, method = "kruskal.test") # Add overall p-value at lower left corner
## Warning: Removed 5 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 5 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 5 rows containing non-finite values (`stat_compare_means()`).

# Reorder the levels of 'patologia'
dbhm$patologia <- factor(dbhm$patologia, levels = c("Sana", "HTG", "PENS", "PESE"))


# Filter only for rows with desired categories in the 'patologia' column
dbhm <- dbhm[dbhm$patologia %in% c("Sana", "HTG", "PENS", "PESE"), ]

my_comparisons <- list(c("Sana", "HTG"), c("Sana", "PENS"), c("Sana", "PESE"))

# Create boxplots and add the p-value comparisons
ggboxplot(dbhm, x = "patologia", y = "plaq", 
          color = "patologia", palette = c("#00AFBB", "#E7B800", "#FC4E07", "#0073C2")) +
  labs(title = "", 
       x = "Pathology", 
       y = "platelets (??)", 
       color = "") +
  theme(legend.position='none')+
  stat_compare_means(comparisons = my_comparisons, method = NULL,
                     aes(label = paste0("p = ", after_stat(p.signif)))) + # Add pairwise comparisons p-value
  stat_compare_means(label.x = 3, label.y = 1.8, method = "kruskal.test") # Add overall p-value at lower left corner
## Warning: Removed 1 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 1 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 1 rows containing non-finite values (`stat_compare_means()`).

# Reorder the levels of 'patologia'
dbhm$patologia <- factor(dbhm$patologia, levels = c("Sana", "HTG", "PENS", "PESE"))


# Filter only for rows with desired categories in the 'patologia' column
dbhm <- dbhm[dbhm$patologia %in% c("Sana", "HTG", "PENS", "PESE"), ]

my_comparisons <- list(c("Sana", "HTG"), c("Sana", "PENS"), c("Sana", "PESE"))

# Create boxplots and add the p-value comparisons
ggboxplot(dbhm, x = "patologia", y = "dhl", 
          color = "patologia", palette = c("#00AFBB", "#E7B800", "#FC4E07", "#0073C2")) +
  labs(title = "", 
       x = "Pathology", 
       y = "LDH (??)", 
       color = "") +
  theme(legend.position='none')+
  stat_compare_means(comparisons = my_comparisons, method = NULL,
                     aes(label = paste0("p = ", after_stat(p.signif)))) + # Add pairwise comparisons p-value
  stat_compare_means(label.x = 3, label.y = 1.8, method = "kruskal.test") # Add overall p-value at lower left corner
## Warning: Removed 4 rows containing non-finite values (`stat_boxplot()`).
## Warning: Removed 4 rows containing non-finite values (`stat_signif()`).
## Warning: Removed 4 rows containing non-finite values (`stat_compare_means()`).

###A

#library(pROC)
library(dplyr)
library(ggplot2)
library(cutpointr)
library(pROC)
## Type 'citation("pROC")' for a citation.
## 
## Attaching package: 'pROC'
## The following objects are masked from 'package:cutpointr':
## 
##     auc, roc
## The following objects are masked from 'package:stats':
## 
##     cov, smooth, var
#curva roc para pens
pens_roc <- roc(pens ~ album +glog + rag, data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
# Genera la curva ROC pese
pese_roc <- roc(pese ~ album +glog + rag, data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases

###curva pens

pensroc<-ggroc(pens_roc,linetype = 1, size = 1) + theme_bw()+
  theme(legend.title = element_blank(),text = element_text(size = 18)) +
  theme(legend.text = element_text(size = 18, color = "black", face = "bold"))+ theme_bw()+geom_abline(slope = 1, intercept = 1, lty = 2, colour = 'black',size=.5)+ theme(
    title =element_text(size=20, face='bold'),
    axis.title.x = element_text(size =18, face = 'bold'), 
    axis.title.y = element_text(size =18, face = 'bold'),
    panel.border = element_rect(size = 1, fill = NA), 
    axis.text.x = element_text(size = 18, face ='bold'),
    axis.text.y = element_text(size = 18, face ='bold'))+ theme(legend.title = element_blank())+
  theme(legend.text = element_text(size=18,face ='bold'))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `size` argument of `element_rect()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
pensroc

###curva pese

peseroc<-ggroc(pese_roc,linetype = 1, size = 1) + theme_bw()+
  theme(legend.title = element_blank(),text = element_text(size = 18)) +
  theme(legend.text = element_text(size = 18, color = "black", face = "bold"))+ theme_bw()+geom_abline(slope = 1, intercept = 1, lty = 2, colour = 'black',size=.5)+ theme(
    title =element_text(size=20, face='bold'),
    axis.title.x = element_text(size =18, face = 'bold'), 
    axis.title.y = element_text(size =18, face = 'bold'),
    panel.border = element_rect(size = 1, fill = NA), 
    axis.text.x = element_text(size = 18, face ='bold'),
    axis.text.y = element_text(size = 18, face ='bold'))+ theme(legend.title = element_blank())+
  theme(legend.text = element_text(size=18,face ='bold'))
peseroc

ggarrange(pensroc, peseroc, ncol = 2, labels = c("A", "B"), 
                           font.label = list(size = 22))

library(gtsummary)
# Genera los modelos ROC
pens_roc_album <- roc(pens ~ album, data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
pens_roc_glog <- roc(pens ~ glog, data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
pens_roc_rag <- roc(pens ~ rag, data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
pese_roc_album <- roc(pese ~ album, data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
pese_roc_glog <- roc(pens ~ glog, data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
pese_roc_rag <- roc(pese ~ rag, data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
# Calcula los AUC
pens_auc_album <- auc(pens_roc_album)
pens_auc_glog<- auc(pens_roc_glog)
pens_auc_rag <- auc(pens_roc_rag)
pese_auc_album <- auc(pese_roc_album)
pese_auc_glog<- auc(pese_roc_glog)
pese_auc_rag <- auc(pese_roc_rag)

# Calcula los puntos de corte óptimos y las estadísticas asociadas
pens_opt_album <- coords(pens_roc_album, "best")
pens_opt_glog<-coords(pens_roc_glog, "best")
pens_opt_rag <- coords(pens_roc_rag, "best")
pese_opt_album <- coords(pese_roc_album, "best")
pese_opt_glog<-coords(pese_roc_glog, "best")
pese_opt_rag <- coords(pese_roc_rag, "best")

# Crea una tabla con los resultados
results <- data.frame(
  Model = c("pens_album", "pens_glog", "pens_rag", "pese_album", "pese_glog", "pese_rag"),
  AUC = c(pens_auc_album,pens_auc_glog, pens_auc_rag, pese_auc_album, pese_auc_glog, pese_auc_rag),
  Optimal_Cutoff = c(pens_opt_album$threshold,pens_opt_glog$threshold, pens_opt_rag$threshold, pese_opt_album$threshold, pese_opt_glog$threshold, pese_opt_rag$threshold),
  Sensitivity = c(pens_opt_album$sensitivity,pens_opt_glog$sensitivity, pens_opt_rag$sensitivity, pese_opt_album$sensitivity, pese_opt_glog$sensitivity, pese_opt_rag$sensitivity),
  Specificity = c(pens_opt_album$specificity, pens_opt_glog$specificity, pens_opt_rag$specificity, pese_opt_album$specificity,pese_opt_glog$specificity, pese_opt_rag$specificity)
)

# Utiliza gtsummary para crear una tabla para publicación
aucmodels<-results %>% gt()
aucmodels
Model AUC Optimal_Cutoff Sensitivity Specificity
pens_album 0.5754698 3.395 0.8292683 0.3196721
pens_glog 0.5587583 2.555 0.8048780 0.3719008
pens_rag 0.5089700 1.095 1.0000000 0.1322314
pese_album 0.6861434 3.495 0.6046512 0.6916667
pese_glog 0.5587583 2.555 0.8048780 0.3719008
pese_rag 0.6229167 1.225 0.4523810 0.8083333

#Explorar otras variables no solo casarnos con RAG y PENS

#curva roc para pens
pensotras_roc <- roc(pens ~ album + rag + plaq + dhl + creat + urea + un + prot24 + acu + ca , data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
ggroc(pensotras_roc,linetype = 1, size = 1) + theme_bw()+
  theme(legend.title = element_blank(),text = element_text(size = 18)) +
  theme(legend.text = element_text(size = 18, color = "black", face = "bold"))+ theme_bw()+geom_abline(slope = 1, intercept = 1, lty = 2, colour = 'black',size=.5)+ theme(
    title =element_text(size=20, face='bold'),
    axis.title.x = element_text(size =18, face = 'bold'), 
    axis.title.y = element_text(size =18, face = 'bold'),
    panel.border = element_rect(size = 1, fill = NA), 
    axis.text.x = element_text(size = 18, face ='bold'),
    axis.text.y = element_text(size = 18, face ='bold'))+ theme(legend.title = element_blank())+
  theme(legend.text = element_text(size=18,face ='bold'))

pensotras_roc
## $album
## 
## Call:
## roc.formula(formula = pens ~ album, data = dbhm)
## 
## Data: album in 122 controls (pens 0) < 41 cases (pens 1).
## Area under the curve: 0.5755
## 
## $rag
## 
## Call:
## roc.formula(formula = pens ~ rag, data = dbhm)
## 
## Data: rag in 121 controls (pens 0) < 41 cases (pens 1).
## Area under the curve: 0.509
## 
## $plaq
## 
## Call:
## roc.formula(formula = pens ~ plaq, data = dbhm)
## 
## Data: plaq in 125 controls (pens 0) < 41 cases (pens 1).
## Area under the curve: 0.5956
## 
## $dhl
## 
## Call:
## roc.formula(formula = pens ~ dhl, data = dbhm)
## 
## Data: dhl in 122 controls (pens 0) > 41 cases (pens 1).
## Area under the curve: 0.6374
## 
## $creat
## 
## Call:
## roc.formula(formula = pens ~ creat, data = dbhm)
## 
## Data: creat in 126 controls (pens 0) > 41 cases (pens 1).
## Area under the curve: 0.598
## 
## $urea
## 
## Call:
## roc.formula(formula = pens ~ urea, data = dbhm)
## 
## Data: urea in 126 controls (pens 0) > 41 cases (pens 1).
## Area under the curve: 0.6561
## 
## $un
## 
## Call:
## roc.formula(formula = pens ~ un, data = dbhm)
## 
## Data: un in 119 controls (pens 0) > 38 cases (pens 1).
## Area under the curve: 0.6504
## 
## $prot24
## 
## Call:
## roc.formula(formula = pens ~ prot24, data = dbhm)
## 
## Data: prot24 in 65 controls (pens 0) < 38 cases (pens 1).
## Area under the curve: 0.6727
## 
## $acu
## 
## Call:
## roc.formula(formula = pens ~ acu, data = dbhm)
## 
## Data: acu in 122 controls (pens 0) > 41 cases (pens 1).
## Area under the curve: 0.6003
## 
## $ca
## 
## Call:
## roc.formula(formula = pens ~ ca, data = dbhm)
## 
## Data: ca in 114 controls (pens 0) < 39 cases (pens 1).
## Area under the curve: 0.6614
pensaltaauc_roc <- roc(pens ~ album + rag  + urea + un + prot24 + acu + ca, data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
ggroc(pensaltaauc_roc,linetype = 1, size = 1) + theme_bw()+
  theme(legend.title = element_blank(),text = element_text(size = 18)) +
  theme(legend.text = element_text(size = 18, color = "black", face = "bold"))+ theme_bw()+geom_abline(slope = 1, intercept = 1, lty = 2, colour = 'black',size=.5)+ theme(
    title =element_text(size=20, face='bold'),
    axis.title.x = element_text(size =18, face = 'bold'), 
    axis.title.y = element_text(size =18, face = 'bold'),
    panel.border = element_rect(size = 1, fill = NA), 
    axis.text.x = element_text(size = 18, face ='bold'),
    axis.text.y = element_text(size = 18, face ='bold'))+ theme(legend.title = element_blank())+
  theme(legend.text = element_text(size=18,face ='bold'))

#AHORA PARA PESE

#curva roc para pens
peseotras_roc <- roc(pese ~ album + rag + plaq + dhl + creat + urea + un + prot24 + acu + ca , data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
ggroc(peseotras_roc,linetype = 1, size = 1) + theme_bw()+
  theme(legend.title = element_blank(),text = element_text(size = 18)) +
  theme(legend.text = element_text(size = 18, color = "black", face = "bold"))+ theme_bw()+geom_abline(slope = 1, intercept = 1, lty = 2, colour = 'black',size=.5)+ theme(
    title =element_text(size=20, face='bold'),
    axis.title.x = element_text(size =18, face = 'bold'), 
    axis.title.y = element_text(size =18, face = 'bold'),
    panel.border = element_rect(size = 1, fill = NA), 
    axis.text.x = element_text(size = 18, face ='bold'),
    axis.text.y = element_text(size = 18, face ='bold'))+ theme(legend.title = element_blank())+
  theme(legend.text = element_text(size=18,face ='bold'))

peseotras_roc
## $album
## 
## Call:
## roc.formula(formula = pese ~ album, data = dbhm)
## 
## Data: album in 120 controls (pese 0) > 43 cases (pese 1).
## Area under the curve: 0.6861
## 
## $rag
## 
## Call:
## roc.formula(formula = pese ~ rag, data = dbhm)
## 
## Data: rag in 120 controls (pese 0) > 42 cases (pese 1).
## Area under the curve: 0.6229
## 
## $plaq
## 
## Call:
## roc.formula(formula = pese ~ plaq, data = dbhm)
## 
## Data: plaq in 123 controls (pese 0) > 43 cases (pese 1).
## Area under the curve: 0.567
## 
## $dhl
## 
## Call:
## roc.formula(formula = pese ~ dhl, data = dbhm)
## 
## Data: dhl in 120 controls (pese 0) < 43 cases (pese 1).
## Area under the curve: 0.6617
## 
## $creat
## 
## Call:
## roc.formula(formula = pese ~ creat, data = dbhm)
## 
## Data: creat in 124 controls (pese 0) < 43 cases (pese 1).
## Area under the curve: 0.6127
## 
## $urea
## 
## Call:
## roc.formula(formula = pese ~ urea, data = dbhm)
## 
## Data: urea in 124 controls (pese 0) < 43 cases (pese 1).
## Area under the curve: 0.6213
## 
## $un
## 
## Call:
## roc.formula(formula = pese ~ un, data = dbhm)
## 
## Data: un in 115 controls (pese 0) < 42 cases (pese 1).
## Area under the curve: 0.6297
## 
## $prot24
## 
## Call:
## roc.formula(formula = pese ~ prot24, data = dbhm)
## 
## Data: prot24 in 63 controls (pese 0) < 40 cases (pese 1).
## Area under the curve: 0.6383
## 
## $acu
## 
## Call:
## roc.formula(formula = pese ~ acu, data = dbhm)
## 
## Data: acu in 120 controls (pese 0) < 43 cases (pese 1).
## Area under the curve: 0.6762
## 
## $ca
## 
## Call:
## roc.formula(formula = pese ~ ca, data = dbhm)
## 
## Data: ca in 111 controls (pese 0) > 42 cases (pese 1).
## Area under the curve: 0.6961
pesealtaauc_roc <- roc(pese ~ album + rag  + urea + un + prot24 + acu + ca, data = dbhm)
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls < cases
## Setting levels: control = 0, case = 1
## Setting direction: controls > cases
ggroc(pesealtaauc_roc,linetype = 1, size = 1) + theme_bw()+
  theme(legend.title = element_blank(),text = element_text(size = 18)) +
  theme(legend.text = element_text(size = 18, color = "black", face = "bold"))+ theme_bw()+geom_abline(slope = 1, intercept = 1, lty = 2, colour = 'black',size=.5)+ theme(
    title =element_text(size=20, face='bold'),
    axis.title.x = element_text(size =18, face = 'bold'), 
    axis.title.y = element_text(size =18, face = 'bold'),
    panel.border = element_rect(size = 1, fill = NA), 
    axis.text.x = element_text(size = 18, face ='bold'),
    axis.text.y = element_text(size = 18, face ='bold'))+ theme(legend.title = element_blank())+
  theme(legend.text = element_text(size=18,face ='bold'))