# Cargar librerias
library(XLConnect)
## Loading required package: XLConnectJars
## XLConnect 0.2-12 by Mirai Solutions GmbH [aut],
## Martin Studer [cre],
## The Apache Software Foundation [ctb, cph] (Apache POI, Apache Commons
## Codec),
## Stephen Colebourne [ctb, cph] (Joda-Time Java library),
## Graph Builder [ctb, cph] (Curvesapi Java library)
## http://www.mirai-solutions.com ,
## http://miraisolutions.wordpress.com
library(survival)
library(prodlim)
require(stringr)
## Loading required package: stringr
source("/Users/mauriciogutierrez/Library/Mobile Documents/com~apple~CloudDocs/estadisticas/general_functions_new.R")
# Preparar los datos
#Pacientes <-read.xlsx("/Users/mauriciogutierrez/Desktop/Pacientes.xlsx",sheetName="Hoja1")
Pacientes <- readexcel("/Users/mauriciogutierrez/Desktop/Pacientes.xlsx","Hoja1")
#View(Pacientes)
data2015=Pacientes[which(Pacientes$anio=="2015"),]
data2016=Pacientes[which(Pacientes$anio=="2016"),]
data2017=Pacientes[which(Pacientes$anio=="2017"),]
#procesar datos
#1) %EIMCP del inicial al minimo------------------------------------------------------
#a) 2015
data2015$EIMCP = ((data2015$IMC_inicial-data2015$IMC_minimo)/(data2015$IMC_inicial -25)*100)
data2015$grupo=ifelse(data2015$EIMCP<50,"<50",ifelse(data2015$EIMCP>65,">65","50-65"))
freq (data2015,data2015$grupo,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## <50 1 4 4 0.1
## >65 20 80 84 59.3
## 50-65 4 16 100 4.54
## Total 25 100.00
## intervalo confianza inferior
## <50 20.35
## >65 93.17
## 50-65 36.08
## Total
#b) 2016
data2016$EIMCP = ((data2016$IMC_inicial-data2016$IMC_minimo)/(data2016$IMC_inicial -25)*100)
data2016$grupo=ifelse(data2016$EIMCP<50,"<50",ifelse(data2016$EIMCP>65,">65","50-65"))
freq (data2016,data2016$grupo,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## <50 1 3.03 3.03 0.08
## >65 29 87.88 90.91 71.8
## 50-65 3 9.09 100 1.92
## Total 33 100.00
## intervalo confianza inferior
## <50 15.76
## >65 96.6
## 50-65 24.33
## Total
#c) 2017
data2017$EIMCP = ((data2017$IMC_inicial-data2017$IMC_minimo)/(data2017$IMC_inicial -25)*100)
data2017$grupo=ifelse(data2017$EIMCP<50,"<50",ifelse(data2017$EIMCP>65,">65","50-65"))
freq (data2017,data2017$grupo,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## >65 8 88.89 88.89 51.75
## 50-65 1 11.11 100 0.28
## Total 9 100.00
## intervalo confianza inferior
## >65 99.72
## 50-65 48.25
## Total
#2) %EIMCP del inicial al actual -----------------------------------------------------
#a) 2015
data2015$EIMCP = ((data2015$IMC_inicial-data2015$IMC_actual)/(data2015$IMC_inicial-25)*100)
data2015$grupo=ifelse(data2015$EIMCP<50,"<50",ifelse(data2015$EIMCP>65,">65","50-65"))
freq (data2015,data2015$grupo,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## <50 4 16 16 4.54
## >65 16 64 80 42.52
## 50-65 5 20 100 6.83
## Total 25 100.00
## intervalo confianza inferior
## <50 36.08
## >65 82.03
## 50-65 40.7
## Total
#b) 2016
data2016$EIMCP = ((data2016$IMC_inicial-data2016$IMC_actual)/(data2016$IMC_inicial-25)*100)
data2016$grupo=ifelse(data2016$EIMCP<50,"<50",ifelse(data2016$EIMCP>65,">65","50-65"))
freq (data2016,data2016$grupo,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## <50 2 6.06 6.06 0.74
## >65 29 87.88 93.94 71.8
## 50-65 2 6.06 100 0.74
## Total 33 100.00
## intervalo confianza inferior
## <50 20.23
## >65 96.6
## 50-65 20.23
## Total
#c) 2017
data2017$EIMCP = ((data2017$IMC_inicial-data2017$IMC_actual)/(data2017$IMC_inicial-25)*100)
data2017$grupo=ifelse(data2017$EIMCP<50,"<50",ifelse(data2017$EIMCP>65,">65","50-65"))
freq (data2017,data2017$grupo,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## >65 8 88.89 88.89 51.75
## 50-65 1 11.11 100 0.28
## Total 9 100.00
## intervalo confianza inferior
## >65 99.72
## 50-65 48.25
## Total
#3) %EIMCP del preoperatorio al minimo---------------------------------------------------
#a) 2015
data2015$EIMCP = ((data2015$IMC_previo_preoperatorio-data2015$IMC_minimo)/(data2015$IMC_previo_preoperatorio-25)*100)
data2015$grupo=ifelse(data2015$EIMCP<50,"<50",ifelse(data2015$EIMCP>65,">65","50-65"))
freq (data2015,data2015$grupo,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## <50 2 8 8 0.98
## >65 18 72 80 50.61
## 50-65 5 20 100 6.83
## Total 25 100.00
## intervalo confianza inferior
## <50 26.03
## >65 87.93
## 50-65 40.7
## Total
#b) 2016
data2016$EIMCP = ((data2016$IMC_previo_preoperatorio-data2016$IMC_minimo)/(data2016$IMC_previo_preoperatorio-25)*100)
data2016$grupo=ifelse(data2016$EIMCP<50,"<50",ifelse(data2016$EIMCP>65,">65","50-65"))
freq (data2016,data2016$grupo,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## <50 2 6.06 6.06 0.74
## >65 27 81.82 87.88 64.54
## 50-65 4 12.12 100 3.4
## Total 33 100.00
## intervalo confianza inferior
## <50 20.23
## >65 93.02
## 50-65 28.2
## Total
#c) 2017
data2017$EIMCP =((data2017$IMC_previo_preoperatorio-data2017$IMC_minimo)/(data2017$IMC_previo_preoperatorio-25)*100)
data2017$grupo=ifelse(data2017$EIMCP<50,"<50",ifelse(data2017$EIMCP>65,">65","50-65"))
freq (data2017,data2017$grupo,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## >65 8 88.89 88.89 51.75
## 50-65 1 11.11 100 0.28
## Total 9 100.00
## intervalo confianza inferior
## >65 99.72
## 50-65 48.25
## Total
#4) Reganancia ----------------------------------------------------------------------------------------------
#a) Todas
Pacientes$reganancia =((Pacientes$Peso_actual-Pacientes$Peso_minimo)/Pacientes$Peso_minimo)*100
Pacientes$reganancia15 = ifelse(Pacientes$reganancia>15,"Mayor a 15%","Menor a 15%")
freq(Pacientes,Pacientes$reganancia15,using_na=T);



##
## absoluta relativa acumulada intervalo confianza inferior
## Mayor a 15% 4 5.97 5.97 1.65
## Menor a 15% 63 94.03 100 85.41
## Total 67 100.00
## intervalo confianza inferior
## Mayor a 15% 14.59
## Menor a 15% 98.35
## Total
Pacientes$reganancia10 = ifelse(Pacientes$reganancia<10,"Menor a 10%","Mayor a 10%")
freq(Pacientes,Pacientes$reganancia10,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Mayor a 10% 11 16.42 16.42 8.49
## Menor a 10% 56 83.58 100 72.52
## Total 67 100.00
## intervalo confianza inferior
## Mayor a 10% 27.48
## Menor a 10% 91.51
## Total
Pacientes$reganancia5 = ifelse(Pacientes$reganancia<5,"Menor a 5%","Mayor a 5%")
freq(Pacientes,Pacientes$reganancia5,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Mayor a 5% 21 31.34 31.34 20.56
## Menor a 5% 46 68.66 100 56.16
## Total 67 100.00
## intervalo confianza inferior
## Mayor a 5% 43.84
## Menor a 5% 79.44
## Total
Pacientes$reganancia0 = ifelse(Pacientes$reganancia<=0,"Mantiene peso","Gano Peso")
freq(Pacientes,Pacientes$reganancia0,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Gano Peso 47 70.15 70.15 57.73
## Mantiene peso 20 29.85 100 19.28
## Total 67 100.00
## intervalo confianza inferior
## Gano Peso 80.72
## Mantiene peso 42.27
## Total
Pacientes$Stages_regain = ifelse (Pacientes$reganancia<2,"a) Menor a 2%",ifelse(Pacientes$reganancia<=5,"b) 2% a 5%", ifelse (Pacientes$reganancia<=10,"c) 5.1% a 10%","d) Mayor>10%")))
freq(Pacientes,Pacientes$Stages_regain,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## a) Menor a 2% 28 41.79 41.79 29.85
## b) 2% a 5% 18 26.87 68.66 16.76
## c) 5.1% a 10% 10 14.93 83.58 7.4
## d) Mayor>10% 11 16.42 100 8.49
## Total 67 100.00
## intervalo confianza inferior
## a) Menor a 2% 54.48
## b) 2% a 5% 39.1
## c) 5.1% a 10% 25.74
## d) Mayor>10% 27.48
## Total
#b) 2015
data2015$reganancia =((data2015$Peso_actual-data2015$Peso_minimo)/data2015$Peso_minimo)*100
data2015$reganancia15 = ifelse(data2015$reganancia>15,"Mayor a 15%","Menor a 15%")
freq(data2015,data2015$reganancia15,using_na=T);



##
## absoluta relativa acumulada intervalo confianza inferior
## Mayor a 15% 3 12 12 2.55
## Menor a 15% 22 88 100 68.78
## Total 25 100.00
## intervalo confianza inferior
## Mayor a 15% 31.22
## Menor a 15% 97.45
## Total
data2015$reganancia10 = ifelse(data2015$reganancia<10,"Menor a 10%","Mayor a 10%")
freq(data2015,data2015$reganancia10,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Mayor a 10% 9 36 36 17.97
## Menor a 10% 16 64 100 42.52
## Total 25 100.00
## intervalo confianza inferior
## Mayor a 10% 57.48
## Menor a 10% 82.03
## Total
data2015$reganancia5 = ifelse(data2015$reganancia<5,"Menor a 5%","Mayor a 5%")
freq(data2015,data2015$reganancia5,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Mayor a 5% 14 56 56 34.93
## Menor a 5% 11 44 100 24.4
## Total 25 100.00
## intervalo confianza inferior
## Mayor a 5% 75.6
## Menor a 5% 65.07
## Total
data2015$reganancia0 = ifelse(data2015$reganancia<=0,"Mantiene peso","Gano Peso")
freq(data2015,data2015$reganancia0,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Gano Peso 21 84 84 63.92
## Mantiene peso 4 16 100 4.54
## Total 25 100.00
## intervalo confianza inferior
## Gano Peso 95.46
## Mantiene peso 36.08
## Total
data2015$Stages_regain = ifelse (data2015$reganancia<2,"a) Menor a 2%",ifelse(data2015$reganancia<=5,"b) 2% a 5%", ifelse (data2015$reganancia<=10,"c) 5.1% a 10%","d) Mayor>10%")))
freq(data2015,data2015$Stages_regain,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## a) Menor a 2% 6 24 24 9.36
## b) 2% a 5% 5 20 44 6.83
## c) 5.1% a 10% 5 20 64 6.83
## d) Mayor>10% 9 36 100 17.97
## Total 25 100.00
## intervalo confianza inferior
## a) Menor a 2% 45.13
## b) 2% a 5% 40.7
## c) 5.1% a 10% 40.7
## d) Mayor>10% 57.48
## Total
#c) 2016
data2016$reganancia =((data2016$Peso_actual-data2016$Peso_minimo)/data2016$Peso_minimo)*100
data2016$reganancia15 = ifelse(data2016$reganancia>15,"Mayor a 15%","Menor a 15%")
freq(data2016,data2016$reganancia15,using_na=T);



##
## absoluta relativa acumulada intervalo confianza inferior
## Mayor a 15% 1 3.03 3.03 0.08
## Menor a 15% 32 96.97 100 84.24
## Total 33 100.00
## intervalo confianza inferior
## Mayor a 15% 15.76
## Menor a 15% 99.92
## Total
data2016$reganancia10 = ifelse(data2016$reganancia<10,"Menor a 10%","Mayor a 10%")
freq(data2016,data2016$reganancia10,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Mayor a 10% 2 6.06 6.06 0.74
## Menor a 10% 31 93.94 100 79.77
## Total 33 100.00
## intervalo confianza inferior
## Mayor a 10% 20.23
## Menor a 10% 99.26
## Total
data2016$reganancia5 = ifelse(data2016$reganancia<5,"Menor a 5%","Mayor a 5%")
freq(data2016,data2016$reganancia5,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Mayor a 5% 7 21.21 21.21 8.98
## Menor a 5% 26 78.79 100 61.09
## Total 33 100.00
## intervalo confianza inferior
## Mayor a 5% 38.91
## Menor a 5% 91.02
## Total
data2016$reganancia0 = ifelse(data2016$reganancia<=0,"Mantiene peso","Gano Peso")
freq(data2016,data2016$reganancia0,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Gano Peso 21 63.64 63.64 45.12
## Mantiene peso 12 36.36 100 20.4
## Total 33 100.00
## intervalo confianza inferior
## Gano Peso 79.6
## Mantiene peso 54.88
## Total
data2016$Stages_regain = ifelse (data2016$reganancia<2,"a) Menor a 2%",ifelse(data2016$reganancia<=5,"b) 2% a 5%", ifelse (data2016$reganancia<=10,"c) 5.1% a 10%","d) Mayor>10%")))
freq(data2016,data2016$Stages_regain,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## a) Menor a 2% 15 45.45 45.45 28.11
## b) 2% a 5% 11 33.33 78.79 17.96
## c) 5.1% a 10% 5 15.15 93.94 5.11
## d) Mayor>10% 2 6.06 100 0.74
## Total 33 100.00
## intervalo confianza inferior
## a) Menor a 2% 63.65
## b) 2% a 5% 51.83
## c) 5.1% a 10% 31.9
## d) Mayor>10% 20.23
## Total
#d) 2017
data2017$reganancia =((data2017$Peso_actual-data2017$Peso_minimo)/data2017$Peso_minimo)*100
data2017$reganancia15 = ifelse(data2017$reganancia>15,"Mayor a 15%","Menor a 15%")
freq(data2017,data2017$reganancia15,using_na=T);



##
## absoluta relativa acumulada intervalo confianza inferior
## Menor a 15% 9 100 100 66.37
## Total 9 100.00
## intervalo confianza inferior
## Menor a 15% 100
## Total
data2017$reganancia10 = ifelse(data2017$reganancia<10,"Menor a 10%","Mayor a 10%")
freq(data2017,data2017$reganancia10,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Menor a 10% 9 100 100 66.37
## Total 9 100.00
## intervalo confianza inferior
## Menor a 10% 100
## Total
data2017$reganancia5 = ifelse(data2017$reganancia<5,"Menor a 5%","Mayor a 5%")
freq(data2017,data2017$reganancia5,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Menor a 5% 9 100 100 66.37
## Total 9 100.00
## intervalo confianza inferior
## Menor a 5% 100
## Total
data2017$reganancia0 = ifelse(data2017$reganancia<=0,"Mantiene peso","Gano Peso")
freq(data2017,data2017$reganancia0,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Gano Peso 5 55.56 55.56 21.2
## Mantiene peso 4 44.44 100 13.7
## Total 9 100.00
## intervalo confianza inferior
## Gano Peso 86.3
## Mantiene peso 78.8
## Total
data2017$Stages_regain = ifelse (data2017$reganancia<2,"a) Menor a 2%",ifelse(data2017$reganancia<=5,"b) 2% a 5%", ifelse (data2017$reganancia<=10,"c) 5.1% a 10%","d) Mayor>10%")))
freq(data2017,data2017$Stages_regain,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## a) Menor a 2% 7 77.78 77.78 39.99
## b) 2% a 5% 2 22.22 100 2.81
## Total 9 100.00
## intervalo confianza inferior
## a) Menor a 2% 97.19
## b) 2% a 5% 60.01
## Total
# 5) Que porcentaje bajo cirugia al minimo
Pacientes$bajo=ifelse(Pacientes$semanas_minimo_CB<52,"<1 año",ifelse(Pacientes$semanas_minimo_CB>104,">2 años",ifelse(Pacientes$semanas_minimo_CB>=52,">=1 año","")))
freq (Pacientes,Pacientes$bajo,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## <1 año 32 47.76 47.76 35.4
## >=1 año 29 43.28 91.04 31.22
## >2 años 6 8.96 100 3.36
## Total 67 100.00
## intervalo confianza inferior
## <1 año 60.33
## >=1 año 55.96
## >2 años 18.48
## Total
# 6) Evaluar cambio en estado nutricional
# todos
means(Pacientes,Pacientes$IMC_inicial)
##
## IMC_inicial
## n 67
## Media 46.86
## Mediana 45.29
## DS 7.94
## Min 34.77
## Max 76.4
## Rango 41.64
## Q1 41.47
## Q3 50.82
## RIQ 9.35
## Normal 0.003
## ICI 44.92
## ICS 48.8
## Resumen Mediana[Q1-Q3] -->45.29(41.47-50.82)


means(Pacientes,Pacientes$IMC_minimo)
##
## IMC_minimo
## n 67
## Media 28.29
## Mediana 27.43
## DS 5.44
## Min 17.13
## Max 46.85
## Rango 29.72
## Q1 24.77
## Q3 30.77
## RIQ 5.99
## Normal 0.004
## ICI 26.96
## ICS 29.61
## Resumen Mediana[Q1-Q3] -->27.43(24.77-30.77)


means(Pacientes,Pacientes$IMC_actual)
##
## IMC_actual
## n 67
## Media 29.49
## Mediana 28.57
## DS 5.35
## Min 18.87
## Max 47.07
## Rango 28.2
## Q1 26.13
## Q3 32.18
## RIQ 6.04
## Normal 0.007
## ICI 28.18
## ICS 30.79
## Resumen Mediana[Q1-Q3] -->28.57(26.13-32.18)


IMC=c(45.29,27.43,28.57)
EN=c("IMC inicial","IMC minimo","IMC actual")
barplot(IMC,names.arg=EN,col=c("Red","Yellow","Green"),ylab="IMC",ylim = c(0,50))

# 2015
means(data2015,data2015$IMC_inicial)
##
## IMC_inicial
## n 25
## Media 46.75
## Mediana 47.39
## DS 7.38
## Min 35.2
## Max 61.72
## Rango 26.52
## Q1 40.46
## Q3 48.84
## RIQ 8.38
## Normal 0.196
## ICI 43.7
## ICS 49.79
## Resumen Media[ICI-ICS] --> 46.75(43.7-49.79)


means(data2015,data2015$IMC_minimo)
##
## IMC_minimo
## n 25
## Media 28.39
## Mediana 27.89
## DS 6.11
## Min 17.13
## Max 46.85
## Rango 29.72
## Q1 24.86
## Q3 31.6
## RIQ 6.74
## Normal 0.217
## ICI 25.86
## ICS 30.91
## Resumen Media[ICI-ICS] --> 28.39(25.86-30.91)


means(data2015,data2015$IMC_actual)
##
## IMC_actual
## n 25
## Media 30.42
## Mediana 31.22
## DS 5.98
## Min 18.87
## Max 47.07
## Rango 28.2
## Q1 27.75
## Q3 33.46
## RIQ 5.71
## Normal 0.503
## ICI 27.96
## ICS 32.89
## Resumen Media[ICI-ICS] --> 30.42(27.96-32.89)


IMC=c(46.75,28.39,30.41)
EN=c("IMC inicial","IMC minimo","IMC actual")
barplot(IMC,names.arg=EN,col=c("Red","Yellow","Green"),ylab="IMC",ylim = c(0,50))

# 2016
means(data2016,data2016$IMC_inicial)
##
## IMC_inicial
## n 33
## Media 45.38
## Mediana 43.2
## DS 6.63
## Min 34.77
## Max 60.51
## Rango 25.74
## Q1 41.25
## Q3 50.73
## RIQ 9.48
## Normal 0.246
## ICI 43.03
## ICS 47.73
## Resumen Media[ICI-ICS] --> 45.38(43.03-47.73)


means(data2016,data2016$IMC_minimo)
##
## IMC_minimo
## n 33
## Media 27.72
## Mediana 26.96
## DS 4.87
## Min 20.47
## Max 41.48
## Rango 21.01
## Q1 24.05
## Q3 28.76
## RIQ 4.71
## Normal 0.013
## ICI 25.99
## ICS 29.45
## Resumen Mediana[Q1-Q3] -->26.96(24.05-28.76)


means(data2016,data2016$IMC_actual)
##
## IMC_actual
## n 33
## Media 28.51
## Mediana 27.04
## DS 4.78
## Min 20.47
## Max 43.28
## Rango 22.81
## Q1 25.81
## Q3 29.72
## RIQ 3.91
## Normal 0.004
## ICI 26.82
## ICS 30.21
## Resumen Mediana[Q1-Q3] -->27.04(25.81-29.72)


IMC=c(45.38,27.72,28.51)
EN=c("IMC inicial","IMC minimo","IMC actual")
barplot(IMC,names.arg=EN,col=c("Red","Yellow","Green"),ylab="IMC",ylim = c(0,50))

# 2017
means(data2017,data2017$IMC_inicial)
##
## IMC_inicial
## n 9
## Media 52.6
## Mediana 48.94
## DS 11.61
## Min 39.09
## Max 76.4
## Rango 37.31
## Q1 44.01
## Q3 58.28
## RIQ 14.27
## Normal 0.254
## ICI 43.68
## ICS 61.52
## Resumen Media[ICI-ICS] --> 52.6(43.68-61.52)


means(data2017,data2017$IMC_minimo)
##
## IMC_minimo
## n 9
## Media 30.1
## Mediana 28.69
## DS 5.66
## Min 23.92
## Max 43.47
## Rango 19.55
## Q1 28.09
## Q3 30.7
## RIQ 2.61
## Normal 0.039
## ICI 25.75
## ICS 34.45
## Resumen Mediana[Q1-Q3] -->28.69(28.09-30.7)


means(data2017,data2017$IMC_actual)
##
## IMC_actual
## n 9
## Media 30.46
## Mediana 29.4
## DS 5.49
## Min 24.3
## Max 43.47
## Rango 19.17
## Q1 28.53
## Q3 30.7
## RIQ 2.17
## Normal 0.036
## ICI 26.24
## ICS 34.67
## Resumen Mediana[Q1-Q3] -->29.4(28.53-30.7)


IMC=c(52.6,30.1,30.46)
EN=c("IMC inicial","IMC minimo","IMC actual")
barplot(IMC,names.arg=EN,col=c("Red","Yellow","Green"),ylab="IMC",ylim = c(0,50))

# 7) Reganancia total Vs Numero de Controles
lineal(Pacientes$reganancia,Pacientes$CONTROLES,"Reganancia","Controles")
##
## Call:
## lm(formula = y ~ x)
##
## Coefficients:
## (Intercept) x
## 2.0387 0.1944
##
## [1] "r2=0.062"
## [1] "p=0.042"

# 8) Descenso de peso preoperatorio (EPC)
Pacientes$EPC = ((Pacientes$IMC_inicial-Pacientes$IMC_previo_preoperatorio)/Pacientes$IMC_inicial)*100
Pacientes$Descenso_preoperatorio=ifelse(Pacientes$EPC>10,"Mayor al 10%",ifelse(Pacientes$EPC>0,"Menor al 10%","Aumento de peso"))
freq(Pacientes,Pacientes$Descenso_preoperatorio,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## Aumento de peso 2 2.99 2.99 0.36
## Mayor al 10% 27 40.3 43.28 28.49
## Menor al 10% 38 56.72 100 44.04
## Total 67 100.00
## intervalo confianza inferior
## Aumento de peso 10.37
## Mayor al 10% 53
## Menor al 10% 68.78
## Total
# 9) Descenso de peso preoperatorio Vs Reganancia
lineal(Pacientes$EPC,Pacientes$reganancia,"Descenso Preoperatorio","Reganancia")
##
## Call:
## lm(formula = y ~ x)
##
## Coefficients:
## (Intercept) x
## 9.8361 -0.1441
##
## [1] "r2=0.022"
## [1] "p=0.235"

# 10) Descenso de peso preoperatorio Vs Numero de Controles
lineal(Pacientes$EPC,Pacientes$CONTROLES,"Descenso Preoperatorio","Controles")
##
## Call:
## lm(formula = y ~ x)
##
## Coefficients:
## (Intercept) x
## 8.27447 0.06962
##
## [1] "r2=0.008"
## [1] "p=0.464"

# Solicitados 8/5
means(Pacientes, Pacientes$Edad)
##
## Edad
## n 67
## Media 42.06
## Mediana 41
## DS 10.81
## Min 21
## Max 67
## Rango 46
## Q1 35
## Q3 50
## RIQ 15
## Normal 0.658
## ICI 39.42
## ICS 44.7
## Resumen Media[ICI-ICS] --> 42.06(39.42-44.7)


freq (Pacientes, Pacientes$Sexo, using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## F 56 83.58 83.58 72.52
## M 11 16.42 100 8.49
## Total 67 100.00
## intervalo confianza inferior
## F 91.51
## M 27.48
## Total
freq (Pacientes, Pacientes$anio,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## 2015 25 37.31 37.31 25.8
## 2016 33 49.25 86.57 36.82
## 2017 9 13.43 100 6.33
## Total 67 100.00
## intervalo confianza inferior
## 2015 49.99
## 2016 61.76
## 2017 23.97
## Total
# semanas al minimo es entre la CB y la fecha del peso minimo
means(Pacientes, Pacientes$semanas_al_minimo)
##
## semanas_al_minimo
## n 67
## Media 60.57
## Mediana 53
## DS 27.41
## Min 21.71
## Max 137
## Rango 115.29
## Q1 43.43
## Q3 77
## RIQ 33.57
## Normal 0.001
## ICI 53.88
## ICS 67.25
## Resumen Mediana[Q1-Q3] -->53(43.43-77)


# solicitado 17 de Mayo------------------------------------------------------------------
# 5) Que porcentaje cirugia al minimo
Pacientes$bajo=ifelse(Pacientes$semanas_minimo_CB<52,"<1 año",ifelse(Pacientes$semanas_minimo_CB>104,">2 años",ifelse(Pacientes$semanas_minimo_CB>=52,">=1 año","")))
freq (Pacientes,Pacientes$bajo,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## <1 año 32 47.76 47.76 35.4
## >=1 año 29 43.28 91.04 31.22
## >2 años 6 8.96 100 3.36
## Total 67 100.00
## intervalo confianza inferior
## <1 año 60.33
## >=1 año 55.96
## >2 años 18.48
## Total
# 6) Evaluar cambio en estado nutricional.
# Uno por uno los pacientes careceria de logica, es mejor hacer los boxplot que viste en el congreso, tiene en cuenta la variabilidad
y=c(median(Pacientes$IMC_inicial),median(Pacientes$IMC_minimo),median(Pacientes$IMC_actual))
x=c("Inicial","Minimo","Actual");
p1=round(t.test(Pacientes$IMC_inicial,Pacientes$IMC_minimo)$p.value,3)
p2=round(t.test(Pacientes$IMC_minimo,Pacientes$IMC_actual)$p.value,3)
p1=ifelse(p1==0,"p<0.001",paste("p=",p1,sep=""))
p2=ifelse(p1==0,"p<0.001",paste("p=",p2,sep=""))
a=c(rep(1,67),rep(2,67),rep(3,67))
b=c(Pacientes$IMC_inicial,Pacientes$IMC_minimo,Pacientes$IMC_actual)
boxplot(Pacientes$IMC_inicial,Pacientes$IMC_minimo,Pacientes$IMC_actual,names=x,frame.plot=F)
abline (h=35,col="red")
text(x=1,y=y[1]+2,labels=paste("x=",round(y[1],2),sep=""))
text(x=2,y=y[2]+2,labels=paste("x=",round(y[2],2),sep=""))
text(x=3,y=y[2]+3,labels=paste("x=",round(y[3],2),sep=""))
text(x=3.3,y=37,labels="IMC<35",col="red")
text(x=1.3,y=28,p1)
text(x=2.6 ,y=22,p2)

boxplot(Pacientes$IMC_inicial,Pacientes$IMC_minimo,Pacientes$IMC_actual,names=x,frame.plot=F)
stripchart(b~a,vertical=T,add=T,method="jitter",jitter=0.1)

# 8) % de pacientes que decendio o no, el 10% del Exceso de peso (Da 1 paciente de diferencia con la planilla)
Pacientes$peso_ideal=Pacientes$TALLA^2*25
Pacientes$EPC=Pacientes$peso_inicial-Pacientes$peso_ideal
Pacientes$EPC10=Pacientes$EPC*0.10
Pacientes$logro10=ifelse(Pacientes$peso_inicial-Pacientes$peso_previo_preoperatorio>Pacientes$EPC10,"Si","No")
freq(Pacientes,Pacientes$logro10,using_na=T)



##
## absoluta relativa acumulada intervalo confianza inferior
## No 9 13.43 13.43 6.33
## Si 58 86.57 100 76.03
## Total 67 100.00
## intervalo confianza inferior
## No 23.97
## Si 93.67
## Total
# 9) Descenso de peso preoperatorio Vs Reganancia
means(Pacientes,Pacientes$EPC10)
##
## EPC10
## n 67
## Media 5.98
## Mediana 5.63
## DS 2.26
## Min 2.39
## Max 13.66
## Rango 11.27
## Q1 4.25
## Q3 7.18
## RIQ 2.93
## Normal 0.01
## ICI 5.43
## ICS 6.53
## Resumen Mediana[Q1-Q3] -->5.63(4.25-7.18)


means(Pacientes,Pacientes$reganancia,Pacientes$logro10)
##
## reganancia by logro10 = No reganancia by logro10 = Si
## n 9 58
## Media 4.2 4.62
## Mediana 3.49 2.57
## DS 4.79 5.8
## Min 0 0
## Max 12.99 27.08
## Rango 12.99 27.08
## Q1 0 0
## Q3 5.88 6.15
## RIQ 5.88 6.15
## Normal 0.085 0
## ICI 0.52 3.09
## ICS 7.88 6.14
## Resumen2 3.49 (0-5.88) 2.57 (0-6.15)
## Resumen1 Mediana[Q1-Q3]
## grupos Homocedastica
## Normalidad No
## Diferencias No
## p-value >0.999
## Metodo Wilcoxon

lineal(Pacientes$reganancia,Pacientes$EPC10,"Reganancia","EPC10")
##
## Call:
## lm(formula = y ~ x)
##
## Coefficients:
## (Intercept) x
## 8.93 -0.73
##
## [1] "r2=0.085"
## [1] "p=0.017"

# 10) Descenso de peso postoperatorio Vs Numero de Controles
Pacientes$Descenso = ((Pacientes$IMC_previo_preoperatorio-Pacientes$IMC_minimo)/Pacientes$IMC_previo_preoperatorio)*100
lineal(Pacientes$Descenso,Pacientes$CONTROLES,"Descenso Postoperatorio","Controles")
##
## Call:
## lm(formula = y ~ x)
##
## Coefficients:
## (Intercept) x
## 28.9100 0.3263
##
## [1] "r2=0.087"
## [1] "p=0.015"
