library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(cluster)
library(FactoMineR)
library(gridExtra)
##
## Attaching package: 'gridExtra'
##
## The following object is masked from 'package:dplyr':
##
## combine
library(dplyr)
library (MASS)
##
## Attaching package: 'MASS'
##
## The following object is masked from 'package:dplyr':
##
## select
library(corrplot)
## corrplot 0.92 loaded
library(ggplot2)
library(ggsignif)
library(psych)
##
## Attaching package: 'psych'
##
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(purrr)
library(flextable)
##
## Attaching package: 'flextable'
##
## The following object is masked from 'package:purrr':
##
## compose
library(tables)
library(kableExtra)
##
## Attaching package: 'kableExtra'
##
## The following objects are masked from 'package:flextable':
##
## as_image, footnote
##
## The following object is masked from 'package:dplyr':
##
## group_rows
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
##
## The following object is masked from 'package:psych':
##
## logit
##
## The following object is masked from 'package:dplyr':
##
## recode
##
## The following object is masked from 'package:purrr':
##
## some
library(ROSE)
## Loaded ROSE 0.0-4
library(caret)
## Loading required package: lattice
##
## Attaching package: 'caret'
##
## The following object is masked from 'package:purrr':
##
## lift
library(pROC)
## Type 'citation("pROC")' for a citation.
##
## Attaching package: 'pROC'
##
## The following objects are masked from 'package:stats':
##
## cov, smooth, var
library(ggrepel)
require(ggpubr)
## Loading required package: ggpubr
##
## Attaching package: 'ggpubr'
##
## The following objects are masked from 'package:flextable':
##
## border, font, rotate
library(kableExtra)
require(table1)
## Loading required package: table1
##
## Attaching package: 'table1'
##
## The following objects are masked from 'package:base':
##
## units, units<-
library(graphics)
library(inspectdf)
library(vcd)
## Loading required package: grid
require(CGPfunctions)
## Loading required package: CGPfunctions
library(readxl)
Vinuba <- read_excel("C:/Users/diana/OneDrive/Escritorio/ASESORIAS_R/Vinuba.xlsx",
col_types = c("text", "numeric", "text",
"text", "text", "date", "numeric",
"text", "text", "date", "date", "numeric",
"text", "text", "text", "text", "text",
"text", "text", "numeric", "text",
"text", "text", "text", "text", "text",
"date", "text", "text", "text", "date",
"text", "text", "text", "numeric",
"numeric", "text", "text", "text",
"text", "text", "text", "text", "text",
"text", "text", "text", "text", "text",
"text", "text", "text", "text", "text",
"numeric", "numeric", "numeric"))
View(Vinuba)
summary(Vinuba)
## ISO3_code ID_Caso Nombre_Paciente Apellidos_Paciente
## Length:6970 Min. : 1 Length:6970 Length:6970
## Class :character 1st Qu.: 334 Class :character Class :character
## Mode :character Median : 667 Mode :character Mode :character
## Mean : 667
## 3rd Qu.:1000
## Max. :1333
## NA's :5637
## Sexo Fecha_Nacimiento Edad_Meses
## Length:6970 Min. :2011-03-02 00:00:00.0 Min. : 0.00
## Class :character 1st Qu.:2015-06-20 00:00:00.0 1st Qu.: 8.00
## Mode :character Median :2017-02-17 00:00:00.0 Median :19.00
## Mean :2017-03-21 01:27:11.0 Mean :21.89
## 3rd Qu.:2018-12-29 00:00:00.0 3rd Qu.:34.00
## Max. :2022-11-06 00:00:00.0 Max. :59.00
##
## Departamento Distrito Fecha_Admisión
## Length:6970 Length:6970 Min. :2016-01-01 00:51:35.00
## Class :character Class :character 1st Qu.:2017-04-29 06:00:00.00
## Mode :character Mode :character Median :2018-11-08 00:00:00.00
## Mean :2019-01-28 16:23:09.98
## 3rd Qu.:2020-06-25 18:00:00.00
## Max. :2022-12-31 00:00:00.00
##
## Fecha_inicio_sÃntomas dif_fecha_ini_sint_hemo Dx_Admision\r\n
## Min. :2015-12-15 00:00:00.00 Min. :-0.481 Length:6970
## 1st Qu.:2017-04-22 06:00:00.00 1st Qu.: 3.000 Class :character
## Median :2018-11-01 00:00:00.00 Median : 5.564 Mode :character
## Mean :2019-01-22 17:40:12.83 Mean : 7.274
## 3rd Qu.:2020-06-20 18:00:00.00 3rd Qu.: 9.000
## Max. :2022-12-30 00:00:00.00 Max. :69.000
## NA's :3853
## Antiobiotico_previo Dificultad_respiratoria Tiraje_toracico
## Length:6970 Length:6970 Length:6970
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## Tos Cianosis Estridor_reposo
## Length:6970 Length:6970 Length:6970
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## FR(repiraciones/minuto) Vomito Fiebre(≥38.5C)
## Min. : 10.0 Length:6970 Length:6970
## 1st Qu.: 28.0 Class :character Class :character
## Median : 34.0 Mode :character Mode :character
## Mean : 36.3
## 3rd Qu.: 42.0
## Max. :100.0
##
## Hipotermia(<36°C) Desnutricion_grave Vacuna_Hib Num_dosis_Hib
## Length:6970 Length:6970 Length:6970 Length:6970
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## Fecha_ultima_dosis_Hib Vacuna_neumococica
## Min. :2011-09-02 00:00:00.00 Length:6970
## 1st Qu.:2015-11-24 18:00:00.00 Class :character
## Median :2017-06-10 00:00:00.00 Mode :character
## Mean :2017-07-27 17:21:56.84
## 3rd Qu.:2019-03-29 00:00:00.00
## Max. :2022-12-16 00:00:00.00
## NA's :726
## Num_dosis_vacuna_neumococica Tipo de vacuna neumócocica PCV10-PCV13
## Length:6970 Length:6970
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## Fecha_ultima_dosis_neumococica toma_RX Resultado_RX_torax
## Min. :2012-02-28 00:00:00.00 Length:6970 Length:6970
## 1st Qu.:2016-03-07 00:00:00.00 Class :character Class :character
## Median :2017-10-03 00:00:00.00 Mode :character Mode :character
## Mean :2017-11-16 11:32:41.06
## 3rd Qu.:2019-06-27 12:00:00.00
## Max. :2022-12-16 00:00:00.00
## NA's :723
## MX_sangre ID_mx_sangre Fecha_mx_sangre toma_hemocultivo
## Length:6970 Min. :6.970e+02 Min. :42371 Length:6970
## Class :character 1st Qu.:1.020e+09 1st Qu.:42836 Class :character
## Mode :character Median :1.028e+09 Median :43356 Mode :character
## Mean :8.558e+09 Mean :43486
## 3rd Qu.:1.075e+09 3rd Qu.:44039
## Max. :2.211e+13 Max. :44928
## NA's :1033 NA's :3853
## Resultados_hemocultivo otros_organismos_id_hemocultivo
## Length:6970 Length:6970
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## Tincion_Gram_hemocultivo Resultados_Gram_hemocultivo Organismos_id_Gram
## Length:6970 Length:6970 Length:6970
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## PCR_hemocultivo Resultados_PCR_hemocultivo cultivo_lÃquido_Pleural
## Length:6970 Length:6970 Length:6970
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## Resultados_cultivo_liquido_pleural Otros_organismos_id_cultivo_liq_pleural
## Length:6970 Length:6970
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## Resultado_serotipos_Spn Resultado_serotipos_Hi Resultado_serogrupos_Nm
## Length:6970 Length:6970 Length:6970
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## Evolucion_paciente Diagnostico_medico_alta_hospitalaria
## Length:6970 Length:6970
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## Clasificacion_final_caso probables observaciones adicionales
## Length:6970 Length:6970 Min. : NA
## Class :character Class :character 1st Qu.: NA
## Mode :character Mode :character Median : NA
## Mean :NaN
## 3rd Qu.: NA
## Max. : NA
## NA's :6970
## dif_fecha_adm_toma_hem dif_fecha_sint_adm
## Min. :-0.498 Min. : -0.4036
## 1st Qu.: 0.000 1st Qu.: 2.4494
## Median : 1.000 Median : 4.0000
## Mean : 1.459 Mean : 5.9655
## 3rd Qu.: 1.907 3rd Qu.: 7.0000
## Max. :43.000 Max. :1102.0000
## NA's :3853
#install.packages("DataExplorer")
# Importing the library
#library(DataExplorer)
#create_report(Vinuba)
#data()
#install.packages("SmartEDA")
# Import library
#library(SmartEDA)
#ExpReport(Vinuba,op_file='smartEDA.html')
## # A tibble: 3,048 × 57
## ISO3_code ID_Caso Nombre_Paciente Apellidos_Paciente Sexo
## <chr> <dbl> <chr> <chr> <chr>
## 1 COL 1 SAMUEL DARIO REINA MENDOZA M
## 2 COL 2 MICHEL NATALIA CRUZ GUERRERO F
## 3 COL 3 DYLAN STIVEN CARDENAS BARRETO M
## 4 COL 7 SAMUEL MATIAS ARZUZA BAYON M
## 5 COL 8 ERICK DAMIAN RAMIREZ BOLIVAR M
## 6 COL 9 ANA LUCIA CRUZ ACUÑA F
## 7 COL 11 DOMINICK MATIAS ALDANA LOZADA M
## 8 COL 12 SARA GABRIELA LEGUIZAMON ROJAS F
## 9 COL 13 DAVID SANTIAGO GULLOSO URREA M
## 10 COL 17 DILAN SAMUEL ESPINOSA BALLESTEROS M
## # ℹ 3,038 more rows
## # ℹ 52 more variables: Fecha_Nacimiento <dttm>, Edad_Meses <dbl>,
## # Departamento <chr>, Distrito <chr>, Fecha_Admisión <dttm>,
## # Fecha_inicio_sÃntomas <dttm>, dif_fecha_ini_sint_hemo <dbl>,
## # `Dx_Admision\r\n` <chr>, Antiobiotico_previo <chr>,
## # Dificultad_respiratoria <chr>, Tiraje_toracico <chr>, Tos <chr>,
## # Cianosis <chr>, Estridor_reposo <chr>, `FR(repiraciones/minuto)` <dbl>, …
summary(probables)
## ISO3_code ID_Caso Nombre_Paciente Apellidos_Paciente
## Length:3048 Min. : 1.0 Length:3048 Length:3048
## Class :character 1st Qu.: 363.0 Class :character Class :character
## Mode :character Median : 717.0 Mode :character Mode :character
## Mean : 682.7
## 3rd Qu.:1009.0
## Max. :1332.0
## NA's :2399
## Sexo Fecha_Nacimiento Edad_Meses
## Length:3048 Min. :2011-03-24 00:00:00.0 Min. : 0.0
## Class :character 1st Qu.:2015-04-21 00:00:00.0 1st Qu.: 9.0
## Mode :character Median :2016-09-25 12:00:00.0 Median :19.0
## Mean :2016-11-09 12:07:05.2 Mean :22.4
## 3rd Qu.:2018-05-29 00:00:00.0 3rd Qu.:34.0
## Max. :2022-08-11 00:00:00.0 Max. :59.0
##
## Departamento Distrito Fecha_Admisión
## Length:3048 Length:3048 Min. :2016-01-01 00:51:35.00
## Class :character Class :character 1st Qu.:2017-03-21 00:00:00.00
## Mode :character Mode :character Median :2018-05-19 12:00:00.00
## Mean :2018-10-04 15:39:56.67
## 3rd Qu.:2019-10-16 00:00:00.00
## Max. :2022-12-31 00:00:00.00
##
## Fecha_inicio_sÃntomas dif_fecha_ini_sint_hemo Dx_Admision\r\n
## Min. :2015-12-27 00:00:00.00 Min. :-0.4806 Length:3048
## 1st Qu.:2017-03-13 18:00:00.00 1st Qu.: 3.0000 Class :character
## Median :2018-05-13 00:00:00.00 Median : 6.0000 Mode :character
## Mean :2018-09-28 15:54:43.14 Mean : 7.1829
## 3rd Qu.:2019-10-08 06:00:00.00 3rd Qu.: 8.0000
## Max. :2022-12-30 00:00:00.00 Max. :69.0000
## NA's :271
## Antiobiotico_previo Dificultad_respiratoria Tiraje_toracico
## Length:3048 Length:3048 Length:3048
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## Tos Cianosis Estridor_reposo
## Length:3048 Length:3048 Length:3048
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## FR(repiraciones/minuto) Vomito Fiebre(≥38.5C)
## Min. : 14.00 Length:3048 Length:3048
## 1st Qu.: 28.00 Class :character Class :character
## Median : 34.00 Mode :character Mode :character
## Mean : 36.75
## 3rd Qu.: 42.00
## Max. :100.00
##
## Hipotermia(<36°C) Desnutricion_grave Vacuna_Hib Num_dosis_Hib
## Length:3048 Length:3048 Length:3048 Length:3048
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## Fecha_ultima_dosis_Hib Vacuna_neumococica
## Min. :2011-11-23 00:00:00.00 Length:3048
## 1st Qu.:2015-10-19 00:00:00.00 Class :character
## Median :2017-03-03 00:00:00.00 Mode :character
## Mean :2017-04-20 17:36:16.58
## 3rd Qu.:2018-10-22 00:00:00.00
## Max. :2022-12-16 00:00:00.00
## NA's :271
## Num_dosis_vacuna_neumococica Tipo de vacuna neumócocica PCV10-PCV13
## Length:3048 Length:3048
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## Fecha_ultima_dosis_neumococica toma_RX Resultado_RX_torax
## Min. :2012-02-28 00:00:00.00 Length:3048 Length:3048
## 1st Qu.:2016-01-25 00:00:00.00 Class :character Class :character
## Median :2017-06-04 00:00:00.00 Mode :character Mode :character
## Mean :2017-08-07 07:27:32.36
## 3rd Qu.:2019-01-08 06:00:00.00
## Max. :2022-12-16 00:00:00.00
## NA's :268
## MX_sangre ID_mx_sangre Fecha_mx_sangre toma_hemocultivo
## Length:3048 Min. :1.004e+03 Min. :42371 Length:3048
## Class :character 1st Qu.:1.020e+09 1st Qu.:42808 Class :character
## Mode :character Median :1.028e+09 Median :43235 Mode :character
## Mean :1.065e+09 Mean :43371
## 3rd Qu.:1.075e+09 3rd Qu.:43735
## Max. :1.562e+10 Max. :44928
## NA's :138 NA's :271
## Resultados_hemocultivo otros_organismos_id_hemocultivo
## Length:3048 Length:3048
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## Tincion_Gram_hemocultivo Resultados_Gram_hemocultivo Organismos_id_Gram
## Length:3048 Length:3048 Length:3048
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## PCR_hemocultivo Resultados_PCR_hemocultivo cultivo_lÃquido_Pleural
## Length:3048 Length:3048 Length:3048
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## Resultados_cultivo_liquido_pleural Otros_organismos_id_cultivo_liq_pleural
## Length:3048 Length:3048
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## Resultado_serotipos_Spn Resultado_serotipos_Hi Resultado_serogrupos_Nm
## Length:3048 Length:3048 Length:3048
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## Evolucion_paciente Diagnostico_medico_alta_hospitalaria
## Length:3048 Length:3048
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## Clasificacion_final_caso probables observaciones adicionales
## Length:3048 Length:3048 Min. : NA
## Class :character Class :character 1st Qu.: NA
## Mode :character Mode :character Median : NA
## Mean :NaN
## 3rd Qu.: NA
## Max. : NA
## NA's :3048
## dif_fecha_adm_toma_hem dif_fecha_sint_adm
## Min. :-0.4977 Min. :-0.4036
## 1st Qu.: 0.0000 1st Qu.: 2.7741
## Median : 0.6176 Median : 4.0000
## Mean : 1.3254 Mean : 6.0319
## 3rd Qu.: 1.2049 3rd Qu.: 7.0000
## Max. :24.4790 Max. :69.0000
## NA's :271
tabla de resultados de hemocultivos:
tabla1=table(probables$Resultados_hemocultivo)
tabla1
##
## Contaminado Hi Negativo Nm No tomado
## 234 32 2326 1 292
## Otros agentes Spn
## 76 87
prop.table(tabla1)*100
##
## Contaminado Hi Negativo Nm No tomado
## 7.6771654 1.0498688 76.3123360 0.0328084 9.5800525
## Otros agentes Spn
## 2.4934383 2.8543307
probables$Resultados_hemocultivo<- str_replace(probables$Resultados_hemocultivo, "Hi","Positivo")
probables$Resultados_hemocultivo<- str_replace(probables$Resultados_hemocultivo, "Nm","Positivo")
probables$Resultados_hemocultivo<- str_replace(probables$Resultados_hemocultivo, "Otros agentes","Positivo")
probables$Resultados_hemocultivo<- str_replace(probables$Resultados_hemocultivo, "Spn","Positivo")
Antibio <- subset(probables, select = c(ID_Caso, dif_fecha_ini_sint_hemo, Antiobiotico_previo, Resultados_hemocultivo))
Antibio
## # A tibble: 3,048 × 4
## ID_Caso dif_fecha_ini_sint_hemo Antiobiotico_previo Resultados_hemocultivo
## <dbl> <dbl> <chr> <chr>
## 1 1 3 No Negativo
## 2 2 5 No Positivo
## 3 3 8 No Contaminado
## 4 7 10 No Negativo
## 5 8 5 No Positivo
## 6 9 5.56 No Negativo
## 7 11 6 Si Negativo
## 8 12 5 No Negativo
## 9 13 6 No Negativo
## 10 17 2 No Negativo
## # ℹ 3,038 more rows
PlotXTabs2(data=Antibio,x=Antiobiotico_previo,y=Resultados_hemocultivo)
v2 = table(Antibio$Antiobiotico_previo, Antibio$Resultados_hemocultivo)
rownames(v2) <- c ("No", "Si")
colnames(v2) <- c("Contaminado", "Positivo", "Negativo", "No tomado")
addmargins(v2)
##
## Contaminado Positivo Negativo No tomado Sum
## No 210 1901 199 168 2478
## Si 24 425 93 28 570
## Sum 234 2326 292 196 3048
chisq.test(v2)
##
## Pearson's Chi-squared test
##
## data: v2
## X-squared = 46.974, df = 3, p-value = 3.521e-10
#fisher.test(v1)
assocstats(v2)
## X^2 df P(> X^2)
## Likelihood Ratio 44.466 3 1.2014e-09
## Pearson 46.974 3 3.5207e-10
##
## Phi-Coefficient : NA
## Contingency Coeff.: 0.123
## Cramer's V : 0.124
En este caso, el valor de p de Chi cuadrado es significante (p-value 3.521e-10) por lo tanto se rechaza hipotesis nula y se acepta hipotesis alterna, donde se evidencia que la administración previa de antibiotico influye en el resultado del hemocultivo. El Ãndice de Cramer (0.124) determina que hay una asociación pequeña entre las variables.
ggplot(Antibio, aes(x = dif_fecha_ini_sint_hemo, fill = Resultados_hemocultivo)) +
geom_histogram (bins=30) + labs (title = "Distribucion de diferencia en dias entre sintomas y toma hemocultivo y resultado de hemocultivo")
## Warning: Removed 271 rows containing non-finite outside the scale range
## (`stat_bin()`).
g10=ggplot(data = Antibio, aes(x = dif_fecha_ini_sint_hemo)) +
geom_density(alpha = 0.35, color = "black")+
scale_fill_manual(values = c( "#0570B0","#D0D1E6",
"#74A9CF"))
ggarrange(g10, labels = c("A"),ncol = 1, nrow = 1)
## Warning: Removed 271 rows containing non-finite outside the scale range
## (`stat_density()`).
g1=ggplot(data = Antibio, aes(x = Resultados_hemocultivo, y = dif_fecha_ini_sint_hemo)) +
geom_boxplot(fill = "#D0D1E6", colour = "black")+geom_jitter(width = 0.3,size = 0.8)
ggarrange(g1, labels = c("A"),ncol = 2, nrow = 1)
## Warning: Removed 271 rows containing non-finite outside the scale range
## (`stat_boxplot()`).
## Warning: Removed 271 rows containing missing values or values outside the scale range
## (`geom_point()`).