head(df)

#Analisis de las variables

data.frame(table(df$AKI_48hs))
# IC para la proporcion de pacientes con AKI a las 48 hs

binom.confint(80, 163, conf.level = 0.95, methods = "exact")
# Sexo
plot(df$Sexo)

# Exploracion grafica
ggplot(df, aes(Sexo))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
sexo<-chisq.test(df$Sexo, df$AKI_48hs, correct = T)
str(sexo)
## List of 9
##  $ statistic: Named num 2.02
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.155
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$Sexo and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 37 46 26 54
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Sexo    : chr [1:2] "Femenino" "Masculino"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 32.1 50.9 30.9 49.1
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Sexo    : chr [1:2] "Femenino" "Masculino"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 0.869 -0.69 -0.885 0.702
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Sexo    : chr [1:2] "Femenino" "Masculino"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 1.58 -1.58 -1.58 1.58
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Sexo    : chr [1:2] "Femenino" "Masculino"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
sexo$expected # Los cumple
##            df$AKI_48hs
## df$Sexo            0        1
##   Femenino  32.07975 30.92025
##   Masculino 50.92025 49.07975
sexo$observed
##            df$AKI_48hs
## df$Sexo      0  1
##   Femenino  37 26
##   Masculino 46 54
sexo$p.value # p-valor = 0.154956
## [1] 0.154956
proportions(table(df$Sexo))
## 
##  Femenino Masculino 
## 0.3865031 0.6134969
proportions(table(df$Sexo[df$AKI_48hs==0]))
## 
##  Femenino Masculino 
## 0.4457831 0.5542169
proportions(table(df$Sexo[df$AKI_48hs==1]))
## 
##  Femenino Masculino 
##     0.325     0.675
# Edad

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_edad<-lm(Edad_Tx ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_edad)
r_estandarizados <- rstandard(modelo_edad)
predichos <- fitted(modelo_edad)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # < 0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.95628, p-value = 5.525e-05
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 90 49
ggplot(data_residuos)+
  geom_point(
    mapping = aes(x=predichos, y=r_estandarizados))

#Evaluo la distribucion por grupo
boxplot(df$Edad_Tx~df$AKI_48hs)

hist(df$Edad_Tx[df$AKI_48hs==0])

hist(df$Edad_Tx[df$AKI_48hs==1])     

# Hay evidencia de incumplimiento de la normalidad
# Hay evidencia de incumplimiento de homocedasticidad
# Por lo tanto test de la Mediana

Median.test(df$Edad_Tx, df$AKI_48hs) # p-valor = 0.5824378
## 
## The Median Test for df$Edad_Tx ~ df$AKI_48hs 
## 
## Chi Square = 0.3023101   DF = 1   P.Value 0.5824378
## Median = 55 
## 
##   Median  r Min Max Q25 Q75
## 0     56 83  21  73  44  62
## 1     55 80  27  70  48  61
## 
## Post Hoc Analysis
## 
## Groups according to probability of treatment differences and alpha level.
## 
## Treatments with the same letter are not significantly different.
## 
##   df$Edad_Tx groups
## 0         56      a
## 1         55      a
mifuncion(df$Edad_Tx)
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       52.92638       12.06237       45.00000       55.00000       62.00000 
##            Min            Max         Rango1         Rango2              N 
##       21.00000       73.00000       21.00000       73.00000      163.00000 
##             na        N_total        Porc_NA 
##        0.00000      163.00000        0.00000
# Causa Cirrosis
plot(df$Causa_cirrosis)

# Exploracion grafica
ggplot(df, aes(Causa_cirrosis))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
causa<-chisq.test(df$Causa_cirrosis, df$AKI_48hs, correct = T)
str(causa)
## List of 9
##  $ statistic: Named num 2.84
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 5
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.725
##  $ method   : chr "Pearson's Chi-squared test"
##  $ data.name: chr "df$Causa_cirrosis and df$AKI_48hs"
##  $ observed : 'table' int [1:6, 1:2] 18 7 17 21 13 7 15 8 12 18 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Causa_cirrosis: chr [1:6] "Alcohol" "CBP" "HAI" "HCV" ...
##   .. ..$ df$AKI_48hs      : chr [1:2] "0" "1"
##  $ expected : num [1:6, 1:2] 16.8 7.64 14.77 19.86 14.26 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Causa_cirrosis: chr [1:6] "Alcohol" "CBP" "HAI" "HCV" ...
##   .. ..$ df$AKI_48hs      : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:6, 1:2] 0.292 -0.231 0.581 0.256 -0.333 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Causa_cirrosis: chr [1:6] "Alcohol" "CBP" "HAI" "HCV" ...
##   .. ..$ df$AKI_48hs      : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:6, 1:2] 0.466 -0.346 0.915 0.419 -0.522 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Causa_cirrosis: chr [1:6] "Alcohol" "CBP" "HAI" "HCV" ...
##   .. ..$ df$AKI_48hs      : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
causa$expected # Los cumple
##                  df$AKI_48hs
## df$Causa_cirrosis         0         1
##           Alcohol 16.803681 16.196319
##           CBP      7.638037  7.361963
##           HAI     14.766871 14.233129
##           HCV     19.858896 19.141104
##           NASH    14.257669 13.742331
##           Otras    9.674847  9.325153
causa$observed
##                  df$AKI_48hs
## df$Causa_cirrosis  0  1
##           Alcohol 18 15
##           CBP      7  8
##           HAI     17 12
##           HCV     21 18
##           NASH    13 15
##           Otras    7 12
causa$p.value # p-valor = 0.7251559
## [1] 0.7251559
fisher.test(df$Causa_cirrosis, df$AKI_48hs) # p-valor = 0.7319
## 
##  Fisher's Exact Test for Count Data
## 
## data:  df$Causa_cirrosis and df$AKI_48hs
## p-value = 0.7319
## alternative hypothesis: two.sided
# Grupo
plot(df$Grupo)

# Exploracion grafica
ggplot(df, aes(Grupo))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
grupo<-chisq.test(df$Grupo, df$AKI_48hs, correct = T)
str(grupo)
## List of 9
##  $ statistic: Named num 0.794
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 3
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.851
##  $ method   : chr "Pearson's Chi-squared test"
##  $ data.name: chr "df$Grupo and df$AKI_48hs"
##  $ observed : 'table' int [1:4, 1:2] 33 35 10 5 35 31 11 3
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grupo   : chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ expected : num [1:4, 1:2] 34.63 33.61 10.69 4.07 33.37 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grupo   : chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:4, 1:2] -0.276 0.24 -0.212 0.459 0.281 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grupo   : chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:4, 1:2] -0.517 0.445 -0.324 0.672 0.517 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grupo   : chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
grupo$expected # No los cumple
##         df$AKI_48hs
## df$Grupo        0        1
##        0 34.62577 33.37423
##        1 33.60736 32.39264
##        2 10.69325 10.30675
##        3  4.07362  3.92638
grupo$observed
##         df$AKI_48hs
## df$Grupo  0  1
##        0 33 35
##        1 35 31
##        2 10 11
##        3  5  3
grupo$p.value # p-valor = 0.8509205
## [1] 0.8509205
fisher.test(df$Grupo, df$AKI_48hs) # p-valor = 0.8632
## 
##  Fisher's Exact Test for Count Data
## 
## data:  df$Grupo and df$AKI_48hs
## p-value = 0.8632
## alternative hypothesis: two.sided
# HCC
plot(df$HCC)

# Exploracion grafica
ggplot(df, aes(HCC))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
hcc<-chisq.test(df$HCC, df$AKI_48hs, correct = T)
str(hcc)
## List of 9
##  $ statistic: Named num 1.68
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.194
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$HCC and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 49 34 56 24
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$HCC     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 53.5 29.5 51.5 28.5
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$HCC     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] -0.611 0.822 0.622 -0.837
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$HCC     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] -1.46 1.46 1.46 -1.46
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$HCC     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
hcc$expected # Los cumple
##       df$AKI_48hs
## df$HCC        0        1
##      0 53.46626 51.53374
##      1 29.53374 28.46626
hcc$observed
##       df$AKI_48hs
## df$HCC  0  1
##      0 49 56
##      1 34 24
hcc$p.value # p-valor = 0.1942925
## [1] 0.1942925
proportions(table(df$HCC))
## 
##         0         1 
## 0.6441718 0.3558282
proportions(table(df$HCC[df$AKI_48hs==0]))
## 
##         0         1 
## 0.5903614 0.4096386
proportions(table(df$HCC[df$AKI_48hs==1]))
## 
##   0   1 
## 0.7 0.3
# BMI

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_bmi<-lm(BMI ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_bmi)
r_estandarizados <- rstandard(modelo_bmi)
predichos <- fitted(modelo_bmi)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # 0.2511
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.98925, p-value = 0.2511
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1]  6 10
ggplot(data_residuos)+
  geom_point(
    mapping = aes(x=predichos, y=r_estandarizados))

#Evaluo homocedasticidad H0: varianzas iguales solo con Levene
leveneTest(BMI ~ df$AKI_48hs, data = df) #No hay evidencia de homocedasticidad - 0.01206
# No hay evidencia de incumplimiento de la normalidad
# Hay evidencia de incumplimiento de homocedasticidad
# Por lo tanto prueba Test-t para varianzas distintas (Welch)

t.test(Edad_Tx~AKI_48hs, var.equal = F, data = df) # p-value = 0.4063
## 
##  Welch Two Sample t-test
## 
## data:  Edad_Tx by AKI_48hs
## t = -0.83266, df = 154.95, p-value = 0.4063
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  -5.289172  2.152425
## sample estimates:
## mean in group 0 mean in group 1 
##        52.15663        53.72500
# DM
plot(df$DM)

# Exploracion grafica
ggplot(df, aes(DM))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
dm<-chisq.test(df$DM, df$AKI_48hs, correct = T)
str(dm)
## List of 9
##  $ statistic: Named num 1.52
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.217
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$DM and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 67 16 57 23
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$DM      : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 63.1 19.9 60.9 19.1
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$DM      : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 0.486 -0.866 -0.495 0.882
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$DM      : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 1.42 -1.42 -1.42 1.42
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$DM      : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
dm$expected # Los cumple
##      df$AKI_48hs
## df$DM       0       1
##     0 63.1411 60.8589
##     1 19.8589 19.1411
dm$observed
##      df$AKI_48hs
## df$DM  0  1
##     0 67 57
##     1 16 23
dm$p.value # p-valor = 0.217377
## [1] 0.217377
# HTA
plot(df$HTA)

# Exploracion grafica
ggplot(df, aes(HTA))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
hta<-chisq.test(df$HTA, df$AKI_48hs, correct = T)
str(hta)
## List of 9
##  $ statistic: Named num 0.00643
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.936
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$HTA and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 75 8 71 9
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$HTA     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 74.34 8.66 71.66 8.34
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$HTA     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 0.0761 -0.2231 -0.0775 0.2273
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$HTA     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 0.337 -0.337 -0.337 0.337
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$HTA     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
hta$expected # Los cumple
##       df$AKI_48hs
## df$HTA         0         1
##      0 74.343558 71.656442
##      1  8.656442  8.343558
hta$observed
##       df$AKI_48hs
## df$HTA  0  1
##      0 75 71
##      1  8  9
hta$p.value # p-valor = 0.9360819
## [1] 0.9360819
# EPS
plot(df$EPS)

# Exploracion grafica
ggplot(df, aes(EPS))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
eps<-chisq.test(df$EPS, df$AKI_48hs, correct = T)
str(eps)
## List of 9
##  $ statistic: Named num 2.21
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.137
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$EPS and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 47 36 35 45
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$EPS     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 41.8 41.2 40.2 39.8
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$EPS     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 0.812 -0.817 -0.827 0.832
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$EPS     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 1.64 -1.64 -1.64 1.64
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$EPS     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
eps$expected # Los cumple
##       df$AKI_48hs
## df$EPS       0       1
##      0 41.7546 40.2454
##      1 41.2454 39.7546
eps$observed
##       df$AKI_48hs
## df$EPS  0  1
##      0 47 35
##      1 36 45
eps$p.value # p-valor = 0.1370061
## [1] 0.1370061
# Ascitis
plot(df$Ascitis)

# Exploracion grafica
ggplot(df, aes(Ascitis))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
ascitis<-chisq.test(df$Ascitis, df$AKI_48hs, correct = T)
str(ascitis)
## List of 9
##  $ statistic: Named num 1.42
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.233
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$Ascitis and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 30 53 21 59
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Ascitis : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 26 57 25 55
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Ascitis : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 0.791 -0.534 -0.806 0.544
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Ascitis : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 1.36 -1.36 -1.36 1.36
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Ascitis : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
ascitis$expected # Los cumple
##           df$AKI_48hs
## df$Ascitis        0        1
##          0 25.96933 25.03067
##          1 57.03067 54.96933
ascitis$observed
##           df$AKI_48hs
## df$Ascitis  0  1
##          0 30 21
##          1 53 59
ascitis$p.value # p-valor = 0.2328473
## [1] 0.2328473
proportions(table(df$Ascitis))
## 
##         0         1 
## 0.3128834 0.6871166
proportions(table(df$Ascitis[df$AKI_48hs==0]))
## 
##         0         1 
## 0.3614458 0.6385542
proportions(table(df$Ascitis[df$AKI_48hs==1]))
## 
##      0      1 
## 0.2625 0.7375
# Grado Ascitis
plot(df$Grado_Ascitis)

# Exploracion grafica
ggplot(df, aes(Grado_Ascitis))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
grado_ascitis<-chisq.test(df$Grado_Ascitis, df$AKI_48hs, correct = T)
str(grado_ascitis)
## List of 9
##  $ statistic: Named num 2.93
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 3
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.403
##  $ method   : chr "Pearson's Chi-squared test"
##  $ data.name: chr "df$Grado_Ascitis and df$AKI_48hs"
##  $ observed : 'table' int [1:4, 1:2] 31 19 21 12 20 22 25 13
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grado_Ascitis: chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  $ expected : num [1:4, 1:2] 26 20.9 23.4 12.7 25 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grado_Ascitis: chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:4, 1:2] 0.987 -0.411 -0.501 -0.205 -1.006 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grado_Ascitis: chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:4, 1:2] 1.7 -0.678 -0.844 -0.317 -1.7 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grado_Ascitis: chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
grado_ascitis$expected # Los cumple
##                 df$AKI_48hs
## df$Grado_Ascitis        0        1
##                0 25.96933 25.03067
##                1 20.87730 20.12270
##                2 23.42331 22.57669
##                3 12.73006 12.26994
grado_ascitis$observed
##                 df$AKI_48hs
## df$Grado_Ascitis  0  1
##                0 31 20
##                1 19 22
##                2 21 25
##                3 12 13
grado_ascitis$p.value # p-valor = 0.403229
## [1] 0.403229
proportions(table(df$Grado_Ascitis))
## 
##         0         1         2         3 
## 0.3128834 0.2515337 0.2822086 0.1533742
proportions(table(df$Grado_Ascitis[df$AKI_48hs==0]))
## 
##         0         1         2         3 
## 0.3734940 0.2289157 0.2530120 0.1445783
proportions(table(df$Grado_Ascitis[df$AKI_48hs==1]))
## 
##      0      1      2      3 
## 0.2500 0.2750 0.3125 0.1625
# AKI previas
plot(df$AKI_previas)

# Exploracion grafica
ggplot(df, aes(AKI_previas))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
aki_previas<-chisq.test(df$AKI_previas, df$AKI_48hs, correct = T)
str(aki_previas)
## List of 9
##  $ statistic: Named num 0.725
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.394
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$AKI_previas and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 64 19 56 24
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$AKI_previas: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs   : chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 61.1 21.9 58.9 21.1
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$AKI_previas: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs   : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 0.37 -0.619 -0.377 0.63
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$AKI_previas: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs   : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 1.03 -1.03 -1.03 1.03
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$AKI_previas: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs   : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
aki_previas$expected # Los cumple
##               df$AKI_48hs
## df$AKI_previas        0        1
##              0 61.10429 58.89571
##              1 21.89571 21.10429
aki_previas$observed
##               df$AKI_48hs
## df$AKI_previas  0  1
##              0 64 56
##              1 19 24
aki_previas$p.value # p-valor = 0.3943596
## [1] 0.3943596
proportions(table(df$AKI_previas))
## 
##         0         1 
## 0.7361963 0.2638037
proportions(table(df$AKI_previas[df$AKI_48hs==0]))
## 
##         0         1 
## 0.7710843 0.2289157
proportions(table(df$AKI_previas[df$AKI_48hs==1]))
## 
##   0   1 
## 0.7 0.3
# Grado AKI previas
plot(df$Grado_AKI_previas)

# Exploracion grafica
ggplot(df, aes(Grado_AKI_previas))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
grado_aki_previas<-chisq.test(df$Grado_AKI_previas, df$AKI_48hs, correct = T)
str(grado_aki_previas)
## List of 9
##  $ statistic: Named num 3.13
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 3
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.372
##  $ method   : chr "Pearson's Chi-squared test"
##  $ data.name: chr "df$Grado_AKI_previas and df$AKI_48hs"
##  $ observed : 'table' int [1:4, 1:2] 64 12 7 0 56 16 6 2
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grado_AKI_previas: chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs         : chr [1:2] "0" "1"
##  $ expected : num [1:4, 1:2] 61.1 14.26 6.62 1.02 58.9 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grado_AKI_previas: chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs         : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:4, 1:2] 0.37 -0.598 0.148 -1.009 -0.377 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grado_AKI_previas: chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs         : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:4, 1:2] 1.03 -0.938 0.22 -1.449 -1.03 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Grado_AKI_previas: chr [1:4] "0" "1" "2" "3"
##   .. ..$ df$AKI_48hs         : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
grado_aki_previas$expected # No los cumple
##                     df$AKI_48hs
## df$Grado_AKI_previas         0          1
##                    0 61.104294 58.8957055
##                    1 14.257669 13.7423313
##                    2  6.619632  6.3803681
##                    3  1.018405  0.9815951
grado_aki_previas$observed
##                     df$AKI_48hs
## df$Grado_AKI_previas  0  1
##                    0 64 56
##                    1 12 16
##                    2  7  6
##                    3  0  2
grado_aki_previas$p.value # p-valor = 0.3723775
## [1] 0.3723775
proportions(table(df$Grado_AKI_previas))
## 
##          0          1          2          3 
## 0.73619632 0.17177914 0.07975460 0.01226994
proportions(table(df$Grado_AKI_previas[df$AKI_48hs==0]))
## 
##          0          1          2          3 
## 0.77108434 0.14457831 0.08433735 0.00000000
proportions(table(df$Grado_AKI_previas[df$AKI_48hs==1]))
## 
##     0     1     2     3 
## 0.700 0.200 0.075 0.025
fisher.test(df$Grado_AKI_previas, df$AKI_48hs) # p-valor = 0.4248
## 
##  Fisher's Exact Test for Count Data
## 
## data:  df$Grado_AKI_previas and df$AKI_48hs
## p-value = 0.4248
## alternative hypothesis: two.sided
# RIN

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_rin<-lm(RIN ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_rin)
r_estandarizados <- rstandard(modelo_rin)
predichos <- fitted(modelo_rin)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # < 0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.70062, p-value < 2.2e-16
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1]  11 100
ggplot(data_residuos)+
  geom_point(
    mapping = aes(x=predichos, y=r_estandarizados))

#Distribucion por grupo
boxplot(df$RIN~df$AKI_48hs)

hist(df$RIN[df$AKI_48hs==0])

hist(df$RIN[df$AKI_48hs==1])  

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones se asemejan
# Por lo tanto Test de Mann Whitney

wilcox.test(df$RIN ~ df$AKI_48hs) # p-value = 0.008143
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  df$RIN by df$AKI_48hs
## W = 2522.5, p-value = 0.008143
## alternative hypothesis: true location shift is not equal to 0
# BT

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_bt<-lm(BT ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_bt)
r_estandarizados <- rstandard(modelo_bt)
predichos <- fitted(modelo_bt)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # < 0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.70557, p-value < 2.2e-16
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 28 58
ggplot(data_residuos)+
  geom_point(
    mapping = aes(x=predichos, y=r_estandarizados))

#Distribucion por grupo
boxplot(df$BT~df$AKI_48hs)

hist(df$BT[df$AKI_48hs==0])

hist(df$BT[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones se asemejan
# Por lo tanto test de la Mann-Whitney

wilcox.test(BT ~ AKI_48hs, data = df, paired = F) # p-valor = 0.0019
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  BT by AKI_48hs
## W = 2384, p-value = 0.0019
## alternative hypothesis: true location shift is not equal to 0
# NA

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_na<-lm(Na ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_na)
r_estandarizados <- rstandard(modelo_na)
predichos <- fitted(modelo_na)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # < 0.01
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.97695, p-value = 0.008003
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 132 158
ggplot(data_residuos)+
  geom_point(
    mapping = aes(x=predichos, y=r_estandarizados))

#Distribucion por grupo
boxplot(df$Na~df$AKI_48hs)

hist(df$Na[df$AKI_48hs==0])

hist(df$Na[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones se asemejan
# Por lo tanto test de la Mann-Whitney

wilcox.test(Na ~ AKI_48hs, data = df, paired = F) # p-valor = 0.07745
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  Na by AKI_48hs
## W = 3851, p-value = 0.07745
## alternative hypothesis: true location shift is not equal to 0
# Albumina

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_Alb<-lm(Alb ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_Alb)
r_estandarizados <- rstandard(modelo_Alb)
predichos <- fitted(modelo_Alb)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # 0.9195
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.99534, p-value = 0.9195
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 51 44
ggplot(data_residuos)+
  geom_point(
    mapping = aes(x=predichos, y=r_estandarizados))

#Evaluo homocedasticidad H0: varianzas iguales solo con Levene
leveneTest(Alb ~ df$AKI_48hs, data = df) # No hay evidencia de heterocedasticidad - 0.7057
# No hay evidencia de incumplimiento de la normalidad
# No hay evidencia de incumplimiento de homocedasticidad
# Por lo tanto Test-t

t.test(Alb~AKI_48hs, data = df) # p-value = 0.01606
## 
##  Welch Two Sample t-test
## 
## data:  Alb by AKI_48hs
## t = 2.4357, df = 146.96, p-value = 0.01606
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  0.0480606 0.4614776
## sample estimates:
## mean in group 0 mean in group 1 
##        2.995325        2.740556
# MELD Na

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_meld<-lm(MELD_Na ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_meld)
r_estandarizados <- rstandard(modelo_meld)
predichos <- fitted(modelo_meld)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # 0.01704
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.9797, p-value = 0.01704
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 67 12
ggplot(data_residuos)+
  geom_point(
    mapping = aes(x=predichos, y=r_estandarizados))

#Distribucion por grupo
boxplot(df$MELD_Na~df$AKI_48hs)

hist(df$MELD_Na[df$AKI_48hs==0])

hist(df$MELD_Na[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones parecen similares
# Por lo tanto Test de Mann Whitney

wilcox.test(MELD_Na ~ AKI_48hs, data = df, paired = F) # p-valor = 0.00663
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  MELD_Na by AKI_48hs
## W = 2502.5, p-value = 0.00663
## alternative hypothesis: true location shift is not equal to 0
# Cistatina

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_cistatina<-lm(Cistatina ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_cistatina)
r_estandarizados <- rstandard(modelo_cistatina)
predichos <- fitted(modelo_cistatina)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # < 0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.94862, p-value = 1.148e-05
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1]  67 145
#Distribucion por grupo
boxplot(df$Cistatina~df$AKI_48hs)

hist(df$Cistatina[df$AKI_48hs==0])

hist(df$Cistatina[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones parecen similares
# Por lo tanto Test de Mann Whitney

wilcox.test(Cistatina ~ AKI_48hs, data = df, paired = F) # p-valor = 0.003483
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  Cistatina by AKI_48hs
## W = 2439.5, p-value = 0.003483
## alternative hypothesis: true location shift is not equal to 0
# Creatinina

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_crea<-lm(Creatinina ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_crea)
r_estandarizados <- rstandard(modelo_crea)
predichos <- fitted(modelo_crea)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # < 0.001 (2.543e-16)
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.71751, p-value = 2.436e-16
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 67 91
#Distribucion por grupo
boxplot(df$Creatinina~df$AKI_48hs)

hist(df$Creatinina[df$AKI_48hs==0])

hist(df$Creatinina[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones parecen similares
# Por lo tanto Test de Mann Whitney

wilcox.test(Creatinina ~ AKI_48hs, data = df, paired = F) # p-valor = 0.5413
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  Creatinina by AKI_48hs
## W = 3135.5, p-value = 0.5413
## alternative hypothesis: true location shift is not equal to 0
mifuncion(df$Creatinina)
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##      0.8563190      0.3995738      0.6350000      0.7800000      1.0000000 
##            Min            Max         Rango1         Rango2              N 
##      0.3200000      4.2000000      0.3200000      4.2000000    163.0000000 
##             na        N_total        Porc_NA 
##      0.0000000    163.0000000      0.0000000
# WIT_min

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_wit<-lm(WIT_min ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_wit)
r_estandarizados <- rstandard(modelo_wit)
predichos <- fitted(modelo_wit)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # 0.05177
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.98364, p-value = 0.05177
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 107 149
#Evaluo homocedasticidad H0: varianzas iguales solo con Levene
leveneTest(WIT_min ~ df$AKI_48hs, data = df) # Hay evidencia de heterocedasticidad - 0.02928
# No hay evidencia de incumplimiento de la normalidad
# Hay evidencia de incumplimiento de homocedasticidad
# Por lo tanto prueba Test-t para varianzas distintas (Welch)

t.test(WIT_min~AKI_48hs, var.equal = F, data = df) # p-value = 0.9148
## 
##  Welch Two Sample t-test
## 
## data:  WIT_min by AKI_48hs
## t = -0.10717, df = 148.36, p-value = 0.9148
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  -3.185056  2.857345
## sample estimates:
## mean in group 0 mean in group 1 
##        45.03614        45.20000
# CIT hs

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_cit<-lm(CIT_hs ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_cit)
r_estandarizados <- rstandard(modelo_cit)
predichos <- fitted(modelo_cit)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # <0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.30886, p-value < 2.2e-16
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 107 157
#Distribucion por grupo
boxplot(df$CIT_hs~df$AKI_48hs)

hist(df$CIT_hs[df$AKI_48hs==0])

hist(df$CIT_hs[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones parecen similares
# Por lo tanto Test de Mann Whitney

wilcox.test(CIT_hs~ AKI_48hs, data = df, paired = F) # p-valor = 0.7014
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  CIT_hs by AKI_48hs
## W = 3436, p-value = 0.7014
## alternative hypothesis: true location shift is not equal to 0
mifuncion(df$CIT_hs)
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       7.354847       4.423671       6.010000       7.020000       8.225000 
##            Min            Max         Rango1         Rango2              N 
##       4.100000      60.000000       4.100000      60.000000     163.000000 
##             na        N_total        Porc_NA 
##       0.000000     163.000000       0.000000
mifuncion(df$CIT_hs[df$AKI_48hs==0])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       7.099639       1.598487       6.085000       7.030000       8.240000 
##            Min            Max         Rango1         Rango2              N 
##       4.100000      10.550000       4.100000      10.550000      83.000000 
##             na        N_total        Porc_NA 
##       0.000000      83.000000       0.000000
mifuncion(df$CIT_hs[df$AKI_48hs==1])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       7.619625       6.110396       6.000000       7.010000       8.182500 
##            Min            Max         Rango1         Rango2              N 
##       4.100000      60.000000       4.100000      60.000000      80.000000 
##             na        N_total        Porc_NA 
##       0.000000      80.000000       0.000000
# Sme reperfusion
plot(df$Sme_reperfusion)

# Exploracion grafica
ggplot(df, aes(Sme_reperfusion))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
reperf<-chisq.test(df$Sme_reperfusion, df$AKI_48hs, correct = T)
str(reperf)
## List of 9
##  $ statistic: Named num 1.03
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.31
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$Sme_reperfusion and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 46 37 37 43
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Sme_reperfusion: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs       : chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 42.3 40.7 40.7 39.3
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Sme_reperfusion: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs       : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 0.575 -0.585 -0.585 0.596
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Sme_reperfusion: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs       : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 1.17 -1.17 -1.17 1.17
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Sme_reperfusion: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs       : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
reperf$expected # No los cumple
##                   df$AKI_48hs
## df$Sme_reperfusion       0       1
##                  0 42.2638 40.7362
##                  1 40.7362 39.2638
reperf$observed
##                   df$AKI_48hs
## df$Sme_reperfusion  0  1
##                  0 46 37
##                  1 37 43
reperf$p.value # p-valor = 0.3104599
## [1] 0.3104599
proportions(table(df$Sme_reperfusion))
## 
##         0         1 
## 0.5092025 0.4907975
proportions(table(df$Sme_reperfusion[df$AKI_48hs==0]))
## 
##         0         1 
## 0.5542169 0.4457831
proportions(table(df$Sme_reperfusion[df$AKI_48hs==1]))
## 
##      0      1 
## 0.4625 0.5375
# Inotropicos
plot(df$Inotropicos_qx)

# Exploracion grafica
ggplot(df, aes(Inotropicos_qx))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
inotropicos<-chisq.test(df$Inotropicos_qx, df$AKI_48hs, correct = T)
str(inotropicos)
## List of 9
##  $ statistic: Named num 0.1
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.751
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$Inotropicos_qx and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 68 15 68 12
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Inotropicos_qx: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs      : chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 69.3 13.7 66.7 13.3
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Inotropicos_qx: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs      : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] -0.15 0.338 0.153 -0.344
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Inotropicos_qx: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs      : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] -0.527 0.527 0.527 -0.527
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Inotropicos_qx: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs      : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
inotropicos$expected # Los cumple
##                  df$AKI_48hs
## df$Inotropicos_qx        0        1
##                 0 69.25153 66.74847
##                 1 13.74847 13.25153
inotropicos$observed
##                  df$AKI_48hs
## df$Inotropicos_qx  0  1
##                 0 68 68
##                 1 15 12
inotropicos$p.value # p-valor = 0.7514455
## [1] 0.7514455
proportions(table(df$Inotropicos_qx))
## 
##         0         1 
## 0.8343558 0.1656442
proportions(table(df$Sme_reperfusion[df$AKI_48hs==0]))
## 
##         0         1 
## 0.5542169 0.4457831
proportions(table(df$Sme_reperfusion[df$AKI_48hs==1]))
## 
##      0      1 
## 0.4625 0.5375
# Globulos rojos

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_gr<-lm(Globulos_Rojos ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_gr)
r_estandarizados <- rstandard(modelo_gr)
predichos <- fitted(modelo_gr)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # <0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.88934, p-value = 1.109e-09
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 149 150
#Distribucion por grupo
boxplot(df$Globulos_Rojos~df$AKI_48hs)

hist(df$Globulos_Rojos[df$AKI_48hs==0])

hist(df$Globulos_Rojos[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones son distintas
# Por lo tanto Test de la Mediana

Median.test(df$Globulos_Rojos, df$AKI_48hs) # p-value = 0.005226603
## 
## The Median Test for df$Globulos_Rojos ~ df$AKI_48hs 
## 
## Chi Square = 7.799316   DF = 1   P.Value 0.005226603
## Median = 2 
## 
##   Median  r Min Max Q25  Q75
## 0      1 83   0   6   0 2.50
## 1      2 80   0  16   0 5.25
## 
## Post Hoc Analysis
## 
## Groups according to probability of treatment differences and alpha level.
## 
## Treatments with the same letter are not significantly different.
## 
##   df$Globulos_Rojos groups
## 1                 2      a
## 0                 1      b
mifuncion(df$Globulos_Rojos)
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       2.325153       2.752963       0.000000       2.000000       3.000000 
##            Min            Max         Rango1         Rango2              N 
##       0.000000      16.000000       0.000000      16.000000     163.000000 
##             na        N_total        Porc_NA 
##       0.000000     163.000000       0.000000
mifuncion(df$Globulos_Rojos[df$AKI_48hs==0])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       1.578313       1.646285       0.000000       1.000000       2.500000 
##            Min            Max         Rango1         Rango2              N 
##       0.000000       6.000000       0.000000       6.000000      83.000000 
##             na        N_total        Porc_NA 
##       0.000000      83.000000       0.000000
mifuncion(df$Globulos_Rojos[df$AKI_48hs==1])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##         3.1000         3.3962         0.0000         2.0000         5.2500 
##            Min            Max         Rango1         Rango2              N 
##         0.0000        16.0000         0.0000        16.0000        80.0000 
##             na        N_total        Porc_NA 
##         0.0000        80.0000         0.0000
# Hemoderivados

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_hem<-lm(Hemoderivados ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_hem)
r_estandarizados <- rstandard(modelo_hem)
predichos <- fitted(modelo_hem)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # <0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.87065, p-value = 1.177e-10
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 129   4
#Distribucion por grupo
boxplot(df$Hemoderivados~df$AKI_48hs)

hist(df$Hemoderivados[df$AKI_48hs==0])

hist(df$Hemoderivados[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones son distintas
# Por lo tanto Test de la Mediana

Median.test(df$Hemoderivados, df$AKI_48hs) # p-value = 0.1012783
## 
## The Median Test for df$Hemoderivados ~ df$AKI_48hs 
## 
## Chi Square = 2.685297   DF = 1   P.Value 0.1012783
## Median = 5 
## 
##   Median  r Min Max Q25   Q75
## 0    3.0 83   0  48   0 13.00
## 1    6.5 80   0  50   0 23.25
## 
## Post Hoc Analysis
## 
## Groups according to probability of treatment differences and alpha level.
## 
## Treatments with the same letter are not significantly different.
## 
##   df$Hemoderivados groups
## 1              6.5      a
## 0              3.0      a
mifuncion(df$Hemoderivados)
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       10.11043       12.43204        0.00000        5.00000       17.00000 
##            Min            Max         Rango1         Rango2              N 
##        0.00000       50.00000        0.00000       50.00000      163.00000 
##             na        N_total        Porc_NA 
##        0.00000      163.00000        0.00000
mifuncion(df$Hemoderivados[df$AKI_48hs==0])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       7.542169       9.944114       0.000000       3.000000      13.000000 
##            Min            Max         Rango1         Rango2              N 
##       0.000000      48.000000       0.000000      48.000000      83.000000 
##             na        N_total        Porc_NA 
##       0.000000      83.000000       0.000000
mifuncion(df$Hemoderivados[df$AKI_48hs==1])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       12.77500       14.14838        0.00000        6.50000       23.25000 
##            Min            Max         Rango1         Rango2              N 
##        0.00000       50.00000        0.00000       50.00000       80.00000 
##             na        N_total        Porc_NA 
##        0.00000       80.00000        0.00000
# AST

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_ast<-lm(AST ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_ast)
r_estandarizados <- rstandard(modelo_ast)
predichos <- fitted(modelo_ast)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # <0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.82072, p-value = 7.238e-13
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 18  4
#Distribucion por grupo
boxplot(df$AST~df$AKI_48hs)

hist(df$AST[df$AKI_48hs==0])

hist(df$AST[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones no parecen semejantes
# Por lo tanto Test de la Mediana

Median.test(df$AST, df$AKI_48hs) # p-value = 0.4816662
## 
## The Median Test for df$AST ~ df$AKI_48hs 
## 
## Chi Square = 0.4950885   DF = 1   P.Value 0.4816662
## Median = 1588 
## 
##   Median  r Min  Max   Q25    Q75
## 0 1519.0 83 221 6800 822.5 2249.0
## 1 1773.5 80 235 8636 785.5 3145.5
## 
## Post Hoc Analysis
## 
## Groups according to probability of treatment differences and alpha level.
## 
## Treatments with the same letter are not significantly different.
## 
##   df$AST groups
## 1 1773.5      a
## 0 1519.0      a
mifuncion(df$AST)
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       1996.699       1674.693        796.000       1588.000       2497.000 
##            Min            Max         Rango1         Rango2              N 
##        221.000       8636.000        221.000       8636.000        163.000 
##             na        N_total        Porc_NA 
##          0.000        163.000          0.000
mifuncion(df$AST[df$AKI_48hs==0])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       1773.663       1346.565        822.500       1519.000       2249.000 
##            Min            Max         Rango1         Rango2              N 
##        221.000       6800.000        221.000       6800.000         83.000 
##             na        N_total        Porc_NA 
##          0.000         83.000          0.000
mifuncion(df$AST[df$AKI_48hs==1])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       2228.100       1939.747        785.500       1773.500       3145.500 
##            Min            Max         Rango1         Rango2              N 
##        235.000       8636.000        235.000       8636.000         80.000 
##             na        N_total        Porc_NA 
##          0.000         80.000          0.000
# ALT

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_alt<-lm(ALT ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_alt)
r_estandarizados <- rstandard(modelo_alt)
predichos <- fitted(modelo_alt)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # < 0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.54343, p-value < 2.2e-16
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1]  37 134
#Distribucion por grupo
boxplot(df$ALT~df$AKI_48hs)

hist(df$ALT[df$AKI_48hs==0])

hist(df$ALT[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones son semejantes
# Por lo tanto Test de la Mann Whitney

wilcox.test(ALT ~ AKI_48hs, data = df, paired = F) # p-valor = 0.1487
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  ALT by AKI_48hs
## W = 2884.5, p-value = 0.1487
## alternative hypothesis: true location shift is not equal to 0
mifuncion(df$ALT)
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       1126.313       1338.581        403.500        836.000       1362.000 
##            Min            Max         Rango1         Rango2              N 
##        109.000      13356.000        109.000      13356.000        163.000 
##             na        N_total        Porc_NA 
##          0.000        163.000          0.000
mifuncion(df$ALT[df$AKI_48hs==0])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       1061.952       1534.951        392.500        734.000       1179.000 
##            Min            Max         Rango1         Rango2              N 
##        128.000      13356.000        128.000      13356.000         83.000 
##             na        N_total        Porc_NA 
##          0.000         83.000          0.000
mifuncion(df$ALT[df$AKI_48hs==1])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       1193.088       1104.494        443.750        950.500       1492.750 
##            Min            Max         Rango1         Rango2              N 
##        109.000       7882.000        109.000       7882.000         80.000 
##             na        N_total        Porc_NA 
##          0.000         80.000          0.000
# Tecnica quirurgica
plot(df$tecnica_quirurgica)

# Exploracion grafica
ggplot(df, aes(tecnica_quirurgica))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
tecnica<-chisq.test(df$tecnica_quirurgica, df$AKI_48hs, correct = T)
str(tecnica)
## List of 9
##  $ statistic: Named num 0.0352
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.851
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$tecnica_quirurgica and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 26 57 23 57
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$tecnica_quirurgica: chr [1:2] "Convencional" "PB"
##   .. ..$ df$AKI_48hs          : chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 25 58 24 56
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$tecnica_quirurgica: chr [1:2] "Convencional" "PB"
##   .. ..$ df$AKI_48hs          : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 0.21 -0.138 -0.214 0.14
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$tecnica_quirurgica: chr [1:2] "Convencional" "PB"
##   .. ..$ df$AKI_48hs          : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 0.358 -0.358 -0.358 0.358
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$tecnica_quirurgica: chr [1:2] "Convencional" "PB"
##   .. ..$ df$AKI_48hs          : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
tecnica$expected # No los cumple
##                      df$AKI_48hs
## df$tecnica_quirurgica        0        1
##          Convencional 24.95092 24.04908
##          PB           58.04908 55.95092
tecnica$observed
##                      df$AKI_48hs
## df$tecnica_quirurgica  0  1
##          Convencional 26 23
##          PB           57 57
tecnica$p.value # p-valor = 0.791692
## [1] 0.8511735
proportions(table(df$tecnica_quirurgica))
## 
## Convencional           PB 
##    0.3006135    0.6993865
proportions(table(df$tecnica_quirurgica[df$AKI_48hs==0]))
## 
## Convencional           PB 
##     0.313253     0.686747
proportions(table(df$tecnica_quirurgica[df$AKI_48hs==1]))
## 
## Convencional           PB 
##       0.2875       0.7125
fisher.test(df$tecnica_quirurgica, df$AKI_48hs) # p-valor = 0.8868
## 
##  Fisher's Exact Test for Count Data
## 
## data:  df$tecnica_quirurgica and df$AKI_48hs
## p-value = 0.7359
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
##  0.5479404 2.3392818
## sample estimates:
## odds ratio 
##   1.129584
# Lactato 

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_lac<-lm(Pico_Lactato ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_lac)
r_estandarizados <- rstandard(modelo_lac)
predichos <- fitted(modelo_lac)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # < 0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.91302, p-value = 2.777e-08
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 38 80
#Distribucion por grupo
boxplot(df$Pico_Lactato~df$AKI_48hs)

hist(df$Pico_Lactato[df$AKI_48hs==0])

hist(df$Pico_Lactato[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones son semejantes
# Por lo tanto Test de la Mann Whitney

wilcox.test(Pico_Lactato ~ AKI_48hs, data = df, paired = F) # p-valor = 0.0004604
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  Pico_Lactato by AKI_48hs
## W = 2264.5, p-value = 0.0004604
## alternative hypothesis: true location shift is not equal to 0
mifuncion(df$Pico_Lactato)
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       4.176319       2.299760       2.450000       3.700000       5.450000 
##            Min            Max         Rango1         Rango2              N 
##       1.000000      14.200000       1.000000      14.200000     163.000000 
##             na        N_total        Porc_NA 
##       0.000000     163.000000       0.000000
mifuncion(df$Pico_Lactato[df$AKI_48hs==0])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       3.611446       2.070876       2.300000       3.200000       4.350000 
##            Min            Max         Rango1         Rango2              N 
##       1.000000      14.200000       1.000000      14.200000      83.000000 
##             na        N_total        Porc_NA 
##       0.000000      83.000000       0.000000
mifuncion(df$Pico_Lactato[df$AKI_48hs==1])
##          Media         Desvio Cuantil.25.25%        Mediana Cuantil.75.75% 
##       4.762375       2.389801       2.700000       4.700000       6.100000 
##            Min            Max         Rango1         Rango2              N 
##       1.000000      13.000000       1.000000      13.000000      80.000000 
##             na        N_total        Porc_NA 
##       0.000000      80.000000       0.000000
# Nefrotoxicos
plot(df$Nefrotoxicos)

# Exploracion grafica
ggplot(df, aes(Nefrotoxicos))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
nefro<-chisq.test(df$Nefrotoxicos, df$AKI_48hs, correct = T)
str(nefro)
## List of 9
##  $ statistic: Named num 3.21
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.0734
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$Nefrotoxicos and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 74 9 62 18
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Nefrotoxicos: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs    : chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 69.3 13.7 66.7 13.3
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Nefrotoxicos: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs    : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 0.571 -1.281 -0.581 1.304
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Nefrotoxicos: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs    : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 2 -2 -2 2
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Nefrotoxicos: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs    : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
nefro$expected # Los cumple
##                df$AKI_48hs
## df$Nefrotoxicos        0        1
##               0 69.25153 66.74847
##               1 13.74847 13.25153
nefro$observed
##                df$AKI_48hs
## df$Nefrotoxicos  0  1
##               0 74 62
##               1  9 18
nefro$p.value # p-valor = 0.073371
## [1] 0.073371
proportions(table(df$Nefrotoxicos))
## 
##         0         1 
## 0.8343558 0.1656442
proportions(table(df$Nefrotoxicos[df$AKI_48hs==0]))
## 
##         0         1 
## 0.8915663 0.1084337
proportions(table(df$Nefrotoxicos[df$AKI_48hs==1]))
## 
##     0     1 
## 0.775 0.225
# Edad donante

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_edaddon<-lm(edad_donante ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_edaddon)
r_estandarizados <- rstandard(modelo_edaddon)
predichos <- fitted(modelo_edaddon)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # 0.08643
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.98544, p-value = 0.08643
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 101  16
#Evaluo homocedasticidad H0: varianzas iguales solo con Levene
leveneTest(edad_donante ~ df$AKI_48hs, data = df) # No hay evidencia de heterocedasticidad - 0.1733
# No hay evidencia de incumplimiento de la normalidad
# No hay evidencia de incumplimiento de homocedasticidad
# Por lo tanto Test T

t.test(df$edad_donante~df$AKI_48hs) # p-value = 0.2467
## 
##  Welch Two Sample t-test
## 
## data:  df$edad_donante by df$AKI_48hs
## t = -1.1628, df = 157.48, p-value = 0.2467
## alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
## 95 percent confidence interval:
##  -7.532051  1.949822
## sample estimates:
## mean in group 0 mean in group 1 
##        42.09639        44.88750
# BMI donante

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_bmidon<-lm(BMI_donante ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_bmidon)
r_estandarizados <- rstandard(modelo_bmidon)
predichos <- fitted(modelo_bmidon)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # < 0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.89969, p-value = 4.276e-09
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 149 139
#Distribucion por grupo
boxplot(df$BMI_donante~df$AKI_48hs)

hist(df$BMI_donante[df$AKI_48hs==0])

hist(df$BMI_donante[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones parecen semejantes
# Por lo tanto Test Mann Whitney

wilcox.test(BMI_donante ~ AKI_48hs, data = df, paired = F) # p-valor = 0.8369
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  BMI_donante by AKI_48hs
## W = 3382.5, p-value = 0.8369
## alternative hypothesis: true location shift is not equal to 0
# Pobre funcion
plot(df$Pobre_funcion)

# Exploracion grafica
ggplot(df, aes(Pobre_funcion))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
pobre<-chisq.test(df$Pobre_funcion, df$AKI_48hs, correct = T)
str(pobre)
## List of 9
##  $ statistic: Named num 5.5
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.019
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$Pobre_funcion and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 64 19 47 33
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Pobre_funcion: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 56.5 26.5 54.5 25.5
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Pobre_funcion: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 0.995 -1.453 -1.013 1.48
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Pobre_funcion: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 2.51 -2.51 -2.51 2.51
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Pobre_funcion: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
pobre$expected # Los cumple
##                 df$AKI_48hs
## df$Pobre_funcion        0        1
##                0 56.52147 54.47853
##                1 26.47853 25.52147
pobre$observed
##                 df$AKI_48hs
## df$Pobre_funcion  0  1
##                0 64 47
##                1 19 33
pobre$p.value # p-valor = 0.01898436
## [1] 0.01898436
# Relaparotomia
plot(df$Relaparotomia)

# Exploracion grafica
ggplot(df, aes(Relaparotomia))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
relap<-chisq.test(df$Relaparotomia, df$AKI_48hs, correct = T)
str(relap)
## List of 9
##  $ statistic: Named num 13.7
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.000219
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$Relaparotomia and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 80 3 60 20
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Relaparotomia: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 71.3 11.7 68.7 11.3
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Relaparotomia: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 1.03 -2.55 -1.05 2.59
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Relaparotomia: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 3.92 -3.92 -3.92 3.92
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Relaparotomia: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs     : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
relap$expected # Los cumple
##                 df$AKI_48hs
## df$Relaparotomia        0        1
##                0 71.28834 68.71166
##                1 11.71166 11.28834
relap$observed
##                 df$AKI_48hs
## df$Relaparotomia  0  1
##                0 80 60
##                1  3 20
relap$p.value # p-valor = 0.0002192561
## [1] 0.0002192561
# TRR
plot(df$TRR)

# Exploracion grafica
ggplot(df, aes(TRR))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
trr<-chisq.test(df$TRR, df$AKI_48hs, correct = T)
str(trr)
## List of 9
##  $ statistic: Named num 18.5
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 1.71e-05
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$TRR and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 82 1 60 20
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$TRR     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 72.3 10.7 69.7 10.3
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$TRR     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 1.14 -2.96 -1.16 3.02
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$TRR     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 4.53 -4.53 -4.53 4.53
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$TRR     : chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs: chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
trr$expected # Los cumple
##       df$AKI_48hs
## df$TRR        0        1
##      0 72.30675 69.69325
##      1 10.69325 10.30675
trr$observed
##       df$AKI_48hs
## df$TRR  0  1
##      0 82 60
##      1  1 20
trr$p.value # p-valor = 1.712241e-05
## [1] 1.712241e-05
# Basiliximab
plot(df$Basiliximab)

# Exploracion grafica
ggplot(df, aes(Basiliximab))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
basi<-chisq.test(df$Basiliximab, df$AKI_48hs, correct = T)
str(basi)
## List of 9
##  $ statistic: Named num 7.98
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.00472
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$Basiliximab and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 70 13 51 29
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Basiliximab: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs   : chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 61.6 21.4 59.4 20.6
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Basiliximab: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs   : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 1.07 -1.81 -1.09 1.85
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Basiliximab: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs   : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 3 -3 -3 3
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Basiliximab: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs   : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
basi$expected # Los cumple
##               df$AKI_48hs
## df$Basiliximab       0       1
##              0 61.6135 59.3865
##              1 21.3865 20.6135
basi$observed
##               df$AKI_48hs
## df$Basiliximab  0  1
##              0 70 51
##              1 13 29
basi$p.value # p-valor = 0.004723642
## [1] 0.004723642
# Tiempo UTI

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_tiempo<-lm(Tiempo_UTI ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_tiempo)
r_estandarizados <- rstandard(modelo_tiempo)
predichos <- fitted(modelo_tiempo)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # < 0.001 
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.56726, p-value < 2.2e-16
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## 115 147 
## 115 146
#Distribucion por grupo
boxplot(df$Tiempo_UTI~df$AKI_48hs)

hist(df$Tiempo_UTI[df$AKI_48hs==0])

hist(df$Tiempo_UTI[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones son semejantes
# Por lo tanto Test de Mann Whitney

#Median.test(df$Tiempo_UTI, df$AKI_48hs) # p-value = 0.2848
wilcox.test(Tiempo_UTI ~ AKI_48hs, data = df, paired = F) # p-valor = 0.01041
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  Tiempo_UTI by AKI_48hs
## W = 2483.5, p-value = 0.01041
## alternative hypothesis: true location shift is not equal to 0
# Tiempo total

#Evaluo si la distribucion de la variable es normal con le evaluacion de residuos

modelo_ttotal<-lm(Tiempo_total ~ df$AKI_48hs, data = df)

#Residuos y predichos
residuos <- resid(modelo_ttotal)
r_estandarizados <- rstandard(modelo_ttotal)
predichos <- fitted(modelo_ttotal)
data_residuos<-tibble(residuos, r_estandarizados,predichos)

#Distribucion de residuos
shapiro.test(residuos) # <0.001
## 
##  Shapiro-Wilk normality test
## 
## data:  residuos
## W = 0.73893, p-value = 1.33e-15
qqnorm(residuos)
qqline(residuos)

qqPlot(residuos) # Datos por fuera de la banda de prediccion indican que la distribucion de los residuos no es normal

## [1] 115   9
#Distribucion por grupo
boxplot(df$Tiempo_total~df$AKI_48hs)

hist(df$Tiempo_total[df$AKI_48hs==0])

hist(df$Tiempo_total[df$AKI_48hs==1])

# Hay evidencia de incumplimiento de la normalidad
# Las distribuciones no son semejantes
# Por lo tanto Test de la Mediana

#Median.test(df$Tiempo_total, df$AKI_48hs) # p-value = ERROR
# Muerte
plot(df$Muerte_mes)

# Exploracion grafica
ggplot(df, aes(Muerte_mes))+
  geom_bar(aes(fill=AKI_48hs))

#Veo si cumple los supuestos del chi-cuadrado
muerte<-chisq.test(df$Muerte_mes, df$AKI_48hs, correct = T)
str(muerte)
## List of 9
##  $ statistic: Named num 3.75
##   ..- attr(*, "names")= chr "X-squared"
##  $ parameter: Named int 1
##   ..- attr(*, "names")= chr "df"
##  $ p.value  : num 0.0528
##  $ method   : chr "Pearson's Chi-squared test with Yates' continuity correction"
##  $ data.name: chr "df$Muerte_mes and df$AKI_48hs"
##  $ observed : 'table' int [1:2, 1:2] 81 2 71 9
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Muerte_mes: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs  : chr [1:2] "0" "1"
##  $ expected : num [1:2, 1:2] 77.4 5.6 74.6 5.4
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Muerte_mes: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs  : chr [1:2] "0" "1"
##  $ residuals: 'table' num [1:2, 1:2] 0.409 -1.522 -0.417 1.55
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Muerte_mes: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs  : chr [1:2] "0" "1"
##  $ stdres   : 'table' num [1:2, 1:2] 2.25 -2.25 -2.25 2.25
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ df$Muerte_mes: chr [1:2] "0" "1"
##   .. ..$ df$AKI_48hs  : chr [1:2] "0" "1"
##  - attr(*, "class")= chr "htest"
muerte$expected # Los cumple
##              df$AKI_48hs
## df$Muerte_mes         0         1
##             0 77.398773 74.601227
##             1  5.601227  5.398773
muerte$observed
##              df$AKI_48hs
## df$Muerte_mes  0  1
##             0 81 71
##             1  2  9
muerte$p.value # p-valor = 0.05275452
## [1] 0.05275452

TABLA 1

labels(df) <- c(Sexo= "Sexo", Edad_Tx="Edad (años)", Causa_cirrosis = "Causa de cirrosis", Grupo= "Grupo sanguíneo", HCC="Hepatocarcinoma", BMI= "Indice de masa corporal (kg/m2)", DM= "Diabetes", HTA= "Hipertension", EPS= "Encefalopatía", Ascitis= "Ascitis", Grado_Ascitis= "Grado de ascitis", AKI_previas= "Antecedente de Falla renal aguda", Grado_AKI_previas= "Grado de Falla renal aguda previa", RIN= "RIN", BT= "Bilirrubina total", Na= "Sodio", Alb="Albiminemia", MELD_Na= "MELD Sodio", Cistatina= "Cistatina en sangre", Creatinina= "Creatininemia")

levels(df$Grupo) <- c("0","A", "B", "AB")
levels(df$HCC) <- c("No", "Si")
levels(df$DM) <- c("No", "Si")
levels(df$HTA) <- c("No", "Si")
levels(df$EPS) <- c("No", "Si")
levels(df$Ascitis) <- c("No", "Si")
levels(df$AKI_previas) <- c("No", "Si")
levels(df$AKI_48hs) <- c("No Falla renal aguda", "Falla renal aguda")

tablauno <- tableby(AKI_48hs~chisq(Sexo)+
                      medtest(Edad_Tx, "median", "range")+
                      chisq(Causa_cirrosis)+
                      fe(Grupo)+
                      HCC+
                      anova(BMI)+
                      DM+
                      HTA+
                      EPS+
                      Ascitis+
                      Grado_Ascitis+
                      AKI_previas+
                      fe(Grado_AKI_previas)+
                      wt(RIN)+
                      wt(BT)+
                      wt(Na)+
                      anova(Alb)+
                      wt(MELD_Na, "median", "range")+
                      wt(Cistatina)+
                      wt(Creatinina, "median", "range"), 
                    data = df, 
                    control=tableby.control(stats.labels = list(meansd= "Media (DS)", median="Mediana", range="Rango"),
                    test.pname = "p-valor", digits=2 ))

summary(tablauno, text=T, pfootnote = T) %>%
  kbl(caption = "Tabla 1: Valores basales por grupo")%>%
  footnote(
    general="MELD Na: Modelo de enfermedad hepatica terminal",
    number=c("Test de Chi Cuadrado", "Test de la Mediana", "Test exacto de Fisher", "Test-T", "Test de Mann Whitney"),
    general_title = "Referencias: CBP: Colangitis biliar primaria; HAI: Hepatitis autoinmune; HCV: Hepatitis C; NASH: Higado graso; DS: Desvío standard")%>%
                      kable_styling()
Tabla 1: Valores basales por grupo
No Falla renal aguda (N=83) Falla renal aguda (N=80) Total (N=163) p-valor
Sexo 0.113 (1)
  • Femenino
37 (44.6%) 26 (32.5%) 63 (38.7%)
  • Masculino
46 (55.4%) 54 (67.5%) 100 (61.3%)
Edad (años) 0.584 (2)
  • Mediana
56.00 55.00 55.00
  • Rango
21.00 - 73.00 27.00 - 70.00 21.00 - 73.00
Causa de cirrosis 0.725 (1)
  • Alcohol
18 (21.7%) 15 (18.8%) 33 (20.2%)
  • CBP
7 (8.4%) 8 (10.0%) 15 (9.2%)
  • HAI
17 (20.5%) 12 (15.0%) 29 (17.8%)
  • HCV
21 (25.3%) 18 (22.5%) 39 (23.9%)
  • NASH
13 (15.7%) 15 (18.8%) 28 (17.2%)
  • Otras
7 (8.4%) 12 (15.0%) 19 (11.7%)
Grupo sanguíneo 0.863 (3)
  • 0
33 (39.8%) 35 (43.8%) 68 (41.7%)
  • A
35 (42.2%) 31 (38.8%) 66 (40.5%)
  • B
10 (12.0%) 11 (13.8%) 21 (12.9%)
  • AB
5 (6.0%) 3 (3.8%) 8 (4.9%)
Hepatocarcinoma 0.144 (1)
  • No
49 (59.0%) 56 (70.0%) 105 (64.4%)
  • Si
34 (41.0%) 24 (30.0%) 58 (35.6%)
Indice de masa corporal (kg/m2) 0.103 (4)
  • Media (DS)
27.33 (4.41) 28.64 (5.70) 27.97 (5.11)
  • Rango
17.90 - 40.70 17.80 - 41.60 17.80 - 41.60
Diabetes 0.156 (1)
  • No
67 (80.7%) 57 (71.2%) 124 (76.1%)
  • Si
16 (19.3%) 23 (28.8%) 39 (23.9%)
Hipertension 0.736 (1)
  • No
75 (90.4%) 71 (88.8%) 146 (89.6%)
  • Si
8 (9.6%) 9 (11.2%) 17 (10.4%)
Encefalopatía 0.100 (1)
  • No
47 (56.6%) 35 (43.8%) 82 (50.3%)
  • Si
36 (43.4%) 45 (56.2%) 81 (49.7%)
Ascitis 0.173 (1)
  • No
30 (36.1%) 21 (26.2%) 51 (31.3%)
  • Si
53 (63.9%) 59 (73.8%) 112 (68.7%)
Grado de ascitis 0.403 (1)
  • 0
31 (37.3%) 20 (25.0%) 51 (31.3%)
  • 1
19 (22.9%) 22 (27.5%) 41 (25.2%)
  • 2
21 (25.3%) 25 (31.2%) 46 (28.2%)
  • 3
12 (14.5%) 13 (16.2%) 25 (15.3%)
Antecedente de Falla renal aguda 0.303 (1)
  • No
64 (77.1%) 56 (70.0%) 120 (73.6%)
  • Si
19 (22.9%) 24 (30.0%) 43 (26.4%)
Grado de Falla renal aguda previa 0.425 (3)
  • 0
64 (77.1%) 56 (70.0%) 120 (73.6%)
  • 1
12 (14.5%) 16 (20.0%) 28 (17.2%)
  • 2
7 (8.4%) 6 (7.5%) 13 (8.0%)
  • 3
0 (0.0%) 2 (2.5%) 2 (1.2%)
RIN 0.008 (5)
  • Media (DS)
1.74 (0.96) 1.88 (0.61) 1.81 (0.81)
  • Rango
0.90 - 7.87 1.10 - 3.47 0.90 - 7.87
Bilirrubina total 0.002 (5)
  • Media (DS)
5.48 (8.21) 7.88 (8.55) 6.66 (8.44)
  • Rango
0.40 - 50.73 0.63 - 35.35 0.40 - 50.73
Sodio 0.077 (5)
  • Media (DS)
135.30 (5.47) 134.04 (4.87) 134.68 (5.21)
  • Rango
121.00 - 148.00 120.00 - 145.00 120.00 - 148.00
Albiminemia 0.016 (4)
  • N-Miss
6 8 14
  • Media (DS)
3.00 (0.67) 2.74 (0.61) 2.87 (0.65)
  • Rango
1.53 - 4.76 1.30 - 4.06 1.30 - 4.76
MELD Sodio 0.007 (5)
  • Mediana
16.00 22.00 19.00
  • Rango
7.00 - 36.00 7.00 - 40.00 7.00 - 40.00
Cistatina en sangre 0.003 (5)
  • Media (DS)
1.38 (0.45) 1.58 (0.50) 1.48 (0.49)
  • Rango
0.49 - 2.87 0.53 - 3.66 0.49 - 3.66
Creatininemia 0.540 (5)
  • Mediana
0.76 0.80 0.78
  • Rango
0.32 - 2.27 0.34 - 4.20 0.32 - 4.20
Referencias: CBP: Colangitis biliar primaria; HAI: Hepatitis autoinmune; HCV: Hepatitis C; NASH: Higado graso; DS: Desvío standard
MELD Na: Modelo de enfermedad hepatica terminal
1 Test de Chi Cuadrado
2 Test de la Mediana
3 Test exacto de Fisher
4 Test-T
5 Test de Mann Whitney
write2word(tablauno, "~/tabla.doc", title="My table in Word")
## 
## 
## processing file: tabla.doc.Rmd
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |......................................................................| 100%
##   ordinary text without R code
## output file: tabla.doc.knit.md
## "C:/Program Files/RStudio/bin/quarto/bin/pandoc" +RTS -K512m -RTS tabla.doc.knit.md --to docx --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc20646374c35.doc --lua-filter "C:\Users\FEDERI~1\AppData\Local\R\WIN-LI~1\4.2\RMARKD~1\RMARKD~1\lua\PAGEBR~1.LUA" --highlight-style tango
## 
## Output created: ~/tabla.doc

Otra opcion de tabla

tab.noby <- tableby(~Sexo + Edad_Tx, data=df)
summary(tab.noby)
## 
## 
## |                            | Overall (N=163) |
## |:---------------------------|:---------------:|
## |**Sexo**                    |                 |
## |&nbsp;&nbsp;&nbsp;Femenino  |   63 (38.7%)    |
## |&nbsp;&nbsp;&nbsp;Masculino |   100 (61.3%)   |
## |**Edad (años)**             |                 |
## |&nbsp;&nbsp;&nbsp;Mean (SD) | 52.926 (12.062) |
## |&nbsp;&nbsp;&nbsp;Range     | 21.000 - 73.000 |
#descriptiva por grupo/by
tab1 <- tableby(AKI_48hs ~ Sexo + Edad_Tx + Causa_cirrosis + Grupo + HCC + BMI + DM + EPS + Ascitis + Grado_Ascitis + AKI_previas + RIN + BT + Alb + MELD_Na + Cistatina + Creatinina, data=df, na.tableby(TRUE)) #paquete arsenal
# si queremos missing, agregar a la sintaxis na.tableby(TRUE)
# si queremos que no haga comparaciones, agregar test=FALSE

#para q se vea bien en la consola
summary(tab1, text=TRUE)
## 
## 
## |                                 | No Falla renal aguda (N=83) | Falla renal aguda (N=80) |  Total (N=163)  | p value|
## |:--------------------------------|:---------------------------:|:------------------------:|:---------------:|-------:|
## |Sexo                             |                             |                          |                 |   0.113|
## |-  Femenino                      |         37 (44.6%)          |        26 (32.5%)        |   63 (38.7%)    |        |
## |-  Masculino                     |         46 (55.4%)          |        54 (67.5%)        |   100 (61.3%)   |        |
## |Edad (años)                      |                             |                          |                 |   0.408|
## |-  Mean (SD)                     |       52.157 (13.381)       |     53.725 (10.547)      | 52.926 (12.062) |        |
## |-  Range                         |       21.000 - 73.000       |     27.000 - 70.000      | 21.000 - 73.000 |        |
## |Causa de cirrosis                |                             |                          |                 |   0.725|
## |-  Alcohol                       |         18 (21.7%)          |        15 (18.8%)        |   33 (20.2%)    |        |
## |-  CBP                           |          7 (8.4%)           |        8 (10.0%)         |    15 (9.2%)    |        |
## |-  HAI                           |         17 (20.5%)          |        12 (15.0%)        |   29 (17.8%)    |        |
## |-  HCV                           |         21 (25.3%)          |        18 (22.5%)        |   39 (23.9%)    |        |
## |-  NASH                          |         13 (15.7%)          |        15 (18.8%)        |   28 (17.2%)    |        |
## |-  Otras                         |          7 (8.4%)           |        12 (15.0%)        |   19 (11.7%)    |        |
## |Grupo sanguíneo                  |                             |                          |                 |   0.851|
## |-  0                             |         33 (39.8%)          |        35 (43.8%)        |   68 (41.7%)    |        |
## |-  A                             |         35 (42.2%)          |        31 (38.8%)        |   66 (40.5%)    |        |
## |-  B                             |         10 (12.0%)          |        11 (13.8%)        |   21 (12.9%)    |        |
## |-  AB                            |          5 (6.0%)           |         3 (3.8%)         |    8 (4.9%)     |        |
## |Hepatocarcinoma                  |                             |                          |                 |   0.144|
## |-  No                            |         49 (59.0%)          |        56 (70.0%)        |   105 (64.4%)   |        |
## |-  Si                            |         34 (41.0%)          |        24 (30.0%)        |   58 (35.6%)    |        |
## |Indice de masa corporal (kg/m2)  |                             |                          |                 |   0.103|
## |-  Mean (SD)                     |       27.333 (4.407)        |      28.637 (5.704)      | 27.973 (5.111)  |        |
## |-  Range                         |       17.900 - 40.700       |     17.800 - 41.600      | 17.800 - 41.600 |        |
## |Diabetes                         |                             |                          |                 |   0.156|
## |-  No                            |         67 (80.7%)          |        57 (71.2%)        |   124 (76.1%)   |        |
## |-  Si                            |         16 (19.3%)          |        23 (28.8%)        |   39 (23.9%)    |        |
## |Encefalopatía                    |                             |                          |                 |   0.100|
## |-  No                            |         47 (56.6%)          |        35 (43.8%)        |   82 (50.3%)    |        |
## |-  Si                            |         36 (43.4%)          |        45 (56.2%)        |   81 (49.7%)    |        |
## |Ascitis                          |                             |                          |                 |   0.173|
## |-  No                            |         30 (36.1%)          |        21 (26.2%)        |   51 (31.3%)    |        |
## |-  Si                            |         53 (63.9%)          |        59 (73.8%)        |   112 (68.7%)   |        |
## |Grado de ascitis                 |                             |                          |                 |   0.403|
## |-  0                             |         31 (37.3%)          |        20 (25.0%)        |   51 (31.3%)    |        |
## |-  1                             |         19 (22.9%)          |        22 (27.5%)        |   41 (25.2%)    |        |
## |-  2                             |         21 (25.3%)          |        25 (31.2%)        |   46 (28.2%)    |        |
## |-  3                             |         12 (14.5%)          |        13 (16.2%)        |   25 (15.3%)    |        |
## |Antecedente de Falla renal aguda |                             |                          |                 |   0.303|
## |-  No                            |         64 (77.1%)          |        56 (70.0%)        |   120 (73.6%)   |        |
## |-  Si                            |         19 (22.9%)          |        24 (30.0%)        |   43 (26.4%)    |        |
## |RIN                              |                             |                          |                 |   0.268|
## |-  Mean (SD)                     |        1.739 (0.958)        |      1.880 (0.609)       |  1.808 (0.807)  |        |
## |-  Range                         |        0.900 - 7.870        |      1.100 - 3.470       |  0.900 - 7.870  |        |
## |Bilirrubina total                |                             |                          |                 |   0.070|
## |-  Mean (SD)                     |        5.481 (8.211)        |      7.880 (8.552)       |  6.659 (8.440)  |        |
## |-  Range                         |       0.400 - 50.730        |      0.630 - 35.350      | 0.400 - 50.730  |        |
## |Albiminemia                      |                             |                          |                 |   0.016|
## |-  N-Miss                        |              6              |            8             |       14        |        |
## |-  Mean (SD)                     |        2.995 (0.665)        |      2.741 (0.612)       |  2.872 (0.650)  |        |
## |-  Range                         |        1.530 - 4.760        |      1.300 - 4.060       |  1.300 - 4.760  |        |
## |MELD Sodio                       |                             |                          |                 |   0.008|
## |-  Mean (SD)                     |       18.012 (7.698)        |      21.212 (7.547)      | 19.583 (7.768)  |        |
## |-  Range                         |       7.000 - 36.000        |      7.000 - 40.000      | 7.000 - 40.000  |        |
## |Cistatina en sangre              |                             |                          |                 |   0.007|
## |-  Mean (SD)                     |        1.380 (0.454)        |      1.584 (0.499)       |  1.480 (0.486)  |        |
## |-  Range                         |        0.490 - 2.870        |      0.530 - 3.660       |  0.490 - 3.660  |        |
## |Creatininemia                    |                             |                          |                 |   0.546|
## |-  Mean (SD)                     |        0.838 (0.327)        |      0.876 (0.465)       |  0.856 (0.400)  |        |
## |-  Range                         |        0.320 - 2.270        |      0.340 - 4.200       |  0.320 - 4.200  |        |
labels(df) <- c(WIT_min= "Tiempo de isquemia caliente (Min)", CIT_hs = "Tiempo de clampeo (hs)",  Sme_reperfusion= "Síndrome de reperfusión", Inotropicos_qx="Requerimiento de inotrópicos postquirúrgicos", Globulos_Rojos = "Cantidad de UGR recibidas en quirófano", Hemoderivados = "Cantidad de hemoderivados recibidos en quirófano", AST = "Nivel de transaminasas GOT al salir de quirófano", ALT = "Nivel de transaminasas GTP al salir de quirófano",  tecnica_quirurgica = "Técnica quirúrgica", Pico_Lactato = "Pico de lactato intraquirófano", Nefrotoxicos= "Uso de nefrotóxicos", Relaparotomia="Relaparotomía")

levels(df$Sme_reperfusion) <- c("No", "Si")
levels(df$Inotropicos_qx) <- c("No", "Si")
levels(df$tecnica_quirurgica) <- c("Convencional", "PB")
levels(df$Nefrotoxicos) <- c("No", "Si")
levels(df$Relaparotomia) <- c("No", "Si")
levels(df$AKI_48hs) <- c("No Falla renal aguda", "Falla renal aguda")

tablados <- tableby(AKI_48hs~WIT_min+
                      wt(CIT_hs, "median", "range")+
                      chisq(Sme_reperfusion)+
                      chisq(Inotropicos_qx)+
                      medtest(Globulos_Rojos, "median", "range")+
                      medtest(Hemoderivados, "median", "range")+
                      medtest(AST, "median", "range")+
                      wt(ALT, "median", "range")+
                      fe(tecnica_quirurgica)+
                      wt(Pico_Lactato, "median", "range")+
                      chisq(Nefrotoxicos)+
                      chisq(Relaparotomia), 
                    data = df, 
                    control=tableby.control(stats.labels = list(meansd= "Media (DS)", median="Mediana", range="Rango"),
                    test.pname = "p-valor", digits=2 ))

summary(tablados, text=T, pfootnote = T) %>%
  kbl(caption = "Tabla 2: Variables quirúrgicas por grupo")%>%
  footnote(
    number=c("Test-T","Test de Mann Whitney", "Test de Chi Cuadrado", "Test de la Mediana", "Test exacto de Fisher"),
    general_title = "Referencias: UGR: Unidad de glóbulos rojos; DS: Desvío standard")%>%
                      kable_styling()
Tabla 2: Variables quirúrgicas por grupo
No Falla renal aguda (N=83) Falla renal aguda (N=80) Total (N=163) p-valor
Tiempo de isquemia caliente (Min) 0.914 (1)
  • Media (DS)
45.04 (8.40) 45.20 (10.91) 45.12 (9.68)
  • Rango
26.00 - 70.00 11.00 - 77.00 11.00 - 77.00
Tiempo de clampeo (hs) 0.700 (2)
  • Mediana
7.03 7.01 7.02
  • Rango
4.10 - 10.55 4.10 - 60.00 4.10 - 60.00
Síndrome de reperfusión 0.242 (3)
  • No
46 (55.4%) 37 (46.2%) 83 (50.9%)
  • Si
37 (44.6%) 43 (53.8%) 80 (49.1%)
Requerimiento de inotrópicos postquirúrgicos 0.598 (3)
  • No
68 (81.9%) 68 (85.0%) 136 (83.4%)
  • Si
15 (18.1%) 12 (15.0%) 27 (16.6%)
Cantidad de UGR recibidas en quirófano 0.005 (4)
  • Mediana
1.00 2.00 2.00
  • Rango
0.00 - 6.00 0.00 - 16.00 0.00 - 16.00
Cantidad de hemoderivados recibidos en quirófano 0.102 (4)
  • Mediana
3.00 6.50 5.00
  • Rango
0.00 - 48.00 0.00 - 50.00 0.00 - 50.00
Nivel de transaminasas GOT al salir de quirófano 0.483 (4)
  • Mediana
1519.00 1773.50 1588.00
  • Rango
221.00 - 6800.00 235.00 - 8636.00 221.00 - 8636.00
Nivel de transaminasas GTP al salir de quirófano 0.148 (2)
  • Mediana
734.00 950.50 836.00
  • Rango
128.00 - 13356.00 109.00 - 7882.00 109.00 - 13356.00
Técnica quirúrgica 0.736 (5)
  • Convencional
26 (31.3%) 23 (28.8%) 49 (30.1%)
  • PB
57 (68.7%) 57 (71.2%) 114 (69.9%)
Pico de lactato intraquirófano < 0.001 (2)
  • Mediana
3.20 4.70 3.70
  • Rango
1.00 - 14.20 1.00 - 13.00 1.00 - 14.20
Uso de nefrotóxicos 0.045 (3)
  • No
74 (89.2%) 62 (77.5%) 136 (83.4%)
  • Si
9 (10.8%) 18 (22.5%) 27 (16.6%)
Relaparotomía < 0.001 (3)
  • No
80 (96.4%) 60 (75.0%) 140 (85.9%)
  • Si
3 (3.6%) 20 (25.0%) 23 (14.1%)
1 Test-T
2 Test de Mann Whitney
3 Test de Chi Cuadrado
4 Test de la Mediana
5 Test exacto de Fisher
write2word(tablados, "~/tabla.doc", title="My table in Word")
## 
## 
## processing file: tabla.doc.Rmd
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |......................................................................| 100%
##   ordinary text without R code
## output file: tabla.doc.knit.md
## "C:/Program Files/RStudio/bin/quarto/bin/pandoc" +RTS -K512m -RTS tabla.doc.knit.md --to docx --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc206442631039.doc --lua-filter "C:\Users\FEDERI~1\AppData\Local\R\WIN-LI~1\4.2\RMARKD~1\RMARKD~1\lua\PAGEBR~1.LUA" --highlight-style tango
## 
## Output created: ~/tabla.doc