path="/Users/mauriciogutierrez/Library/Mobile Documents/com~apple~CloudDocs/estadisticas";
pathfunctions=paste(path,"/general_functions_new.R",sep="")
pathtodosbase=paste(path,"/mariana_elhordoy/datos_bariatica_tsh_alterada.xls",sep="")
source(pathfunctions)
## Loading required package: XLConnectJars
## XLConnect 0.2-11 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)
## http://www.mirai-solutions.com ,
## http://miraisolutions.wordpress.com
## Loading required package: reshape2
## Loading required package: stringr
todos=readexcel(pathtodosbase,"Hoja3")
todos$imc_inicial=as.numeric(todos$imc_inicial)
todos$tsh_previo=as.numeric(todos$tsh_previo)
todos$t4_previo=as.numeric(todos$t4_previo)
todos$imc_12meses=as.numeric(todos$imc_12meses)
todos$tsh_12meses=as.numeric(todos$tsh_12meses)

means(todos,todos$edad)
## 
##                                          edad
## n                                          15
## Mean                                     43.2
## Median                                     42
## Sd                                      13.09
## Min                                        21
## Max                                        67
## Range                                      46
## Q1                                       34.5
## Q3                                         52
## Iqr                                      17.5
## Normality                               0.921
## ICI                                     42.98
## SCI                                     43.42
## Summary   Mean[ICI-ICS] --> 43.2(42.98-43.42)

freq(todos,todos$sexo,c("F","M"),using_na=T)

## 
##       absolute relative cumulative   ici   ics
## F           13    86.67      86.67 59.54 98.34
## M            2    13.33        100  1.66 40.46
## Total       15   100.00
means(todos,todos$edad,todos$sexo,c("F","M"))
## 
##                   sexo = F           sexo = M
## n                       13                  2
## Mean                 42.54               47.5
## Median                  42               47.5
## Sd                   11.53              27.58
## Min                     21                 28
## Max                     60                 67
## Range                   39                 39
## Q1                      35              37.75
## Q3                      51              57.25
## Iqr                     16               19.5
## Normal               0.821                 -1
## IIC                  42.33                 -1
## ICS                  42.74                 -1
## Summary2        42 (35-51) 47.5 (37.75-57.25)
## Summary      Median[Q1-Q3]                   
## Groups       Homocedastics                   
## Normality               No                   
## Differences             No                   
## p-value              0.865                   
## Method      Kruskal-Wallis

means(todos,todos$imc_inicial)
## 
##                                   imc_inicial
## n                                          15
## Mean                                    50.63
## Median                                  49.27
## Sd                                       9.96
## Min                                     36.32
## Max                                     72.07
## Range                                   35.75
## Q1                                      43.08
## Q3                                      55.64
## Iqr                                     12.56
## Normality                               0.384
## ICI                                     50.47
## SCI                                      50.8
## Summary   Mean[ICI-ICS] --> 50.63(50.47-50.8)

means(todos,todos$imc_inicial,todos$sexo,c("F","M"))
## 
##                        sexo = F           sexo = M
## n                            13                  2
## Mean                      51.22               46.8
## Median                    49.27               46.8
## Sd                        10.52               5.23
## Min                       36.32               43.1
## Max                       72.07               50.5
## Range                     35.75                7.4
## Q1                        43.06              44.95
## Q3                        59.48              48.65
## Iqr                       16.42                3.7
## Normal                    0.637                 -1
## IIC                       51.04                 -1
## ICS                       51.41                 -1
## Summary2    49.27 (43.06-59.48) 46.8 (44.95-48.65)
## Summary           Median[Q1-Q3]                   
## Groups            Homocedastics                   
## Normality                    No                   
## Differences                  No                   
## p-value                   0.933                   
## Method                 Wilcoxon

means(todos,todos$tsh_previo)
## 
##                                 tsh_previo
## n                                       15
## Mean                                  6.32
## Median                                6.49
## Sd                                    1.28
## Min                                   4.46
## Max                                   9.07
## Range                                 4.61
## Q1                                    5.31
## Q3                                    7.12
## Iqr                                    1.8
## Normality                            0.779
## ICI                                    6.3
## SCI                                   6.34
## Summary   Mean[ICI-ICS] --> 6.32(6.3-6.34)

means(todos,todos$t4_previo)
## 
##                                   t4_previo
## n                                        15
## Mean                                   1.16
## Median                                 1.11
## Sd                                     0.22
## Min                                    0.89
## Max                                    1.83
## Range                                  0.94
## Q1                                     1.08
## Q3                                     1.21
## Iqr                                    0.13
## Normality                             0.003
## ICI                                    1.16
## SCI                                    1.17
## Summary   Median[Q1-Q3]  -->1.11(1.08-1.21)

means(todos,todos$tsh_previo,todos$sexo,c("F","M"))
## 
##                     sexo = F         sexo = M
## n                         13                2
## Mean                    6.49             5.25
## Median                  6.53             5.25
## Sd                      1.26             1.12
## Min                     4.51             4.46
## Max                     9.07             6.04
## Range                   4.56             1.58
## Q1                      5.36             4.85
## Q3                      7.16             5.65
## Iqr                      1.8             0.79
## Normal                 0.839               -1
## IIC                     6.46               -1
## ICS                     6.51               -1
## Summary2    6.53 (5.36-7.16) 5.25 (4.85-5.65)
## Summary        Median[Q1-Q3]                 
## Groups         Homocedastics                 
## Normality                 No                 
## Differences               No                 
## p-value                0.229                 
## Method              Wilcoxon

lineal(todos$tsh_previo,todos$imc_inicial,labely="tsh previo",labelx="imc inicial")
## 
## Call:
## lm(formula = y ~ x)
## 
## Coefficients:
## (Intercept)            x  
##     3.73267      0.05111  
## 
## [1] "r2=0.158"
## [1] "p=0.143"

#excluir outlier (paciente 48) de t4
sin_outlier=todos[which(todos$paciente!=48),]
lineal(sin_outlier$tsh_previo,sin_outlier$t4_previo,labely="tsh previo",labelx="t4l previo")
## 
## Call:
## lm(formula = y ~ x)
## 
## Coefficients:
## (Intercept)            x  
##      14.492       -7.381  
## 
## [1] "r2=0.431"
## [1] "p=0.011"

means(todos,todos$imc_12meses)
## 
##                                    imc_12meses
## n                                           15
## Mean                                     32.44
## Median                                   35.36
## Sd                                        5.67
## Min                                      23.43
## Max                                       41.2
## Range                                    17.77
## Q1                                        26.4
## Q3                                       36.79
## Iqr                                      10.39
## Normality                                0.084
## ICI                                      32.34
## SCI                                      32.53
## Summary   Mean[ICI-ICS] --> 32.44(32.34-32.53)

means(todos,todos$tsh_12meses)
## 
##                                 tsh_12meses
## n                                        15
## Mean                                   1.88
## Median                                 1.51
## Sd                                      1.1
## Min                                    0.45
## Max                                    4.08
## Range                                  3.63
## Q1                                     1.16
## Q3                                     2.46
## Iqr                                     1.3
## Normality                             0.326
## ICI                                    1.86
## SCI                                    1.89
## Summary   Mean[ICI-ICS] --> 1.88(1.86-1.89)

matched_means(todos,todos$imc_inicial,todos$imc_12meses)
## 
##                                      imc_inicial imc_12meses
## n                                             15          15
## Mean                                       50.63       32.44
## Median                                     49.27       35.36
## Sd                                          9.96        5.67
## Min                                        36.32       23.43
## Max                                        72.07        41.2
## Range                                      35.75       17.77
## Q1                                         43.08        26.4
## Q3                                         55.64       36.79
## Iqr                                        12.56       10.39
## Normal                                     0.384       0.084
## IIC                                        50.47       32.34
## ICS                                         50.8       32.53
## Summary     Median[Q1-Q3] 35.36 ( 26.4 - 36.79 )            
## Groups                           Heteroscedastic            
## Normality                                    Yes            
## Differences                                  Yes            
## p-value                                   <0.001            
## Method                   t-Student(Satterhwaite)

matched_means(todos,todos$tsh_previo,todos$tsh_12meses)
## 
##                                     tsh_previo tsh_12meses
## n                                           15          15
## Mean                                      6.32        1.88
## Median                                    6.49        1.51
## Sd                                        1.28         1.1
## Min                                       4.46        0.45
## Max                                       9.07        4.08
## Range                                     4.61        3.63
## Q1                                        5.31        1.16
## Q3                                        7.12        2.46
## Iqr                                        1.8         1.3
## Normal                                   0.779       0.326
## IIC                                        6.3        1.86
## ICS                                       6.34        1.89
## Summary     Mean[ICI-ICS] 1.88 ( 1.86 - 1.89 )            
## Groups                           Homocedastics            
## Normality                                  Yes            
## Differences                                Yes            
## p-value                                 <0.001            
## Method                       t-Student(Pooled)

lineal(todos$tsh_12meses,todos$imc_12meses,labely="tsh 12 meses",labelx="imc 12 meses")
## 
## Call:
## lm(formula = y ~ x)
## 
## Coefficients:
## (Intercept)            x  
##     1.19287      0.02106  
## 
## [1] "r2=0.012"
## [1] "p=0.7"