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.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,"planilla actual")
todos$imc_inicial=as.numeric(todos$imc_inicial)
todos$tsh_previo=as.numeric(todos$tsh_previo)
todos$imc_12meses=as.numeric(todos$imc_12meses)
todos$tsh_12meses=as.numeric(todos$tsh_12meses)

means(todos,todos$edad)
## 
##                                           edad
## n                                           97
## Mean                                     46.28
## Median                                      47
## Sd                                       11.31
## Min                                         21
## Max                                         70
## Range                                       49
## Q1                                          39
## Q3                                          54
## Iqr                                         15
## Normality                                0.457
## ICI                                      46.21
## SCI                                      46.35
## Summary   Mean[ICI-ICS] --> 46.28(46.21-46.35)

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

## 
##       absolute relative cumulative   ici   ics
## F           74    75.51      75.51 65.79 83.64
## M           24    24.49        100 16.36 34.21
## Total       98   100.00
means(todos,todos$edad,todos$sexo,c("F","M"))
## 
##                        sexo = F            sexo = M
## n                            74                  23
## Mean                      45.24               49.61
## Median                     45.5                  48
## Sd                        11.34               10.78
## Min                          21                  28
## Max                          67                  70
## Range                        46                  42
## Q1                        37.25                42.5
## Q3                           53                57.5
## Iqr                       15.75                  15
## Normal                     0.39               0.957
## IIC                       45.16               49.47
## ICS                       45.33               49.75
## Summary2    45.24 (45.16-45.33) 49.61 (49.47-49.75)
## Summary           Mean[ICI-ICS]                    
## Groups            Homocedastics                    
## Normality                   Yes                    
## Differences                  No                    
## p-value                   0.106                    
## Method        t-Student(Pooled)

means(todos,todos$imc_inicial)
## 
##                                  imc_inicial
## n                                         85
## Mean                                    51.2
## Median                                 49.87
## Sd                                      8.34
## Min                                    36.32
## Max                                    74.21
## Range                                  37.89
## Q1                                      44.5
## Q3                                      56.5
## Iqr                                       12
## Normality                              0.008
## ICI                                    51.15
## SCI                                    51.26
## Summary   Median[Q1-Q3]  -->49.87(44.5-56.5)

means(todos,todos$imc_inicial,todos$sexo,c("F","M"))
## 
##                        sexo = F            sexo = M
## n                            62                  23
## Mean                       51.4               50.67
## Median                    49.87               49.87
## Sd                         8.61                7.73
## Min                       36.32                36.8
## Max                       74.21               64.88
## Range                     37.89               28.08
## Q1                        45.22               44.48
## Q3                        56.48               57.54
## Iqr                       11.27               13.06
## Normal                    0.013               0.368
## IIC                       51.33               50.57
## ICS                       51.47               50.77
## Summary2    49.87 (45.22-56.48) 49.87 (44.48-57.54)
## Summary           Median[Q1-Q3]                    
## Groups            Homocedastics                    
## Normality                    No                    
## Differences                  No                    
## p-value                   0.917                    
## Method                 Wilcoxon

means(todos,todos$tsh_previo)
## 
##                                  tsh_previo
## n                                        85
## Mean                                   3.93
## Median                                 2.85
## Sd                                     3.58
## Min                                    0.75
## Max                                   24.55
## Range                                  23.8
## Q1                                     2.11
## Q3                                     4.54
## Iqr                                    2.43
## Normality                                 0
## ICI                                     3.9
## SCI                                    3.95
## Summary   Median[Q1-Q3]  -->2.85(2.11-4.54)

means(todos,todos$tsh_previo,todos$sexo,c("F","M"))
## 
##                    sexo = F         sexo = M
## n                        62               23
## Mean                   4.01              3.7
## Median                 3.09             2.66
## Sd                     3.39             4.11
## Min                    0.75             1.19
## Max                   24.55             21.8
## Range                  23.8            20.61
## Q1                      2.2             2.04
## Q3                     5.22             3.45
## Iqr                    3.02             1.41
## Normal                    0                0
## IIC                    3.98             3.65
## ICS                    4.04             3.76
## Summary2    3.09 (2.2-5.22) 2.66 (2.04-3.45)
## Summary       Median[Q1-Q3]                 
## Groups        Homocedastics                 
## Normality                No                 
## Differences              No                 
## p-value               0.288                 
## Method             Wilcoxon

pre_completo=todos[which(todos$imc_inicial>0&todos$tsh_previo<10),]
lineal(pre_completo$tsh_previo,pre_completo$imc_inicial,labely="tsh previo",labelx="imc inicial")
## 
## Call:
## lm(formula = y ~ x)
## 
## Coefficients:
## (Intercept)            x  
##     2.60540      0.01674  
## 
## [1] "r2=0.005"
## [1] "p=0.515"

pre_post=todos[which(todos$imc_inicial>0&todos$imc_12meses>0&todos$tsh_previo>0&todos$tsh_12meses>0),]
means(pre_post,pre_post$imc_12meses)
## 
##                                    imc_12meses
## n                                           54
## Mean                                     33.53
## Median                                   33.22
## Sd                                        6.16
## Min                                      23.43
## Max                                      47.26
## Range                                    23.83
## Q1                                       28.15
## Q3                                       37.39
## Iqr                                       9.24
## Normality                                0.009
## ICI                                      33.48
## SCI                                      33.59
## Summary   Median[Q1-Q3]  -->33.22(28.15-37.39)

means(pre_post,pre_post$tsh_12meses)
## 
##                                tsh_12meses
## n                                       54
## Mean                                  1.62
## Median                                 1.6
## Sd                                    0.87
## Min                                    0.4
## Max                                   4.08
## Range                                 3.68
## Q1                                    0.91
## Q3                                    2.18
## Iqr                                   1.26
## Normality                            0.013
## ICI                                   1.62
## SCI                                   1.63
## Summary   Median[Q1-Q3]  -->1.6(0.91-2.18)

matched_means(pre_post,pre_post$imc_inicial,pre_post$imc_12meses)
## 
##                                       imc_inicial imc_12meses
## n                                              54          54
## Mean                                        50.93       33.53
## Median                                      49.01       33.22
## Sd                                           8.83        6.16
## Min                                         36.32       23.43
## Max                                         74.21       47.26
## Range                                       37.89       23.83
## Q1                                          43.89       28.15
## Q3                                          58.66       37.39
## Iqr                                         14.78        9.24
## Normal                                      0.029       0.009
## IIC                                         50.86       33.48
## ICS                                         51.01       33.59
## Summary     Median[Q1-Q3] 33.22 ( 28.15 - 37.39 )            
## Groups                            Heteroscedastic            
## Normality                                      No            
## Differences                                   Yes            
## p-value                                    <0.001            
## Method                                   Wilcoxon

matched_means(pre_post,pre_post$tsh_previo,pre_post$tsh_12meses)
## 
##                                    tsh_previo tsh_12meses
## n                                          54          54
## Mean                                     3.59        1.62
## Median                                   2.84         1.6
## Sd                                       1.98        0.87
## Min                                      0.97         0.4
## Max                                      9.07        4.08
## Range                                     8.1        3.68
## Q1                                       2.12        0.91
## Q3                                       4.53        2.18
## Iqr                                      2.41        1.26
## Normal                                  0.001       0.013
## IIC                                      3.58        1.62
## ICS                                      3.61        1.63
## Summary     Median[Q1-Q3] 1.6 ( 0.91 - 2.18 )            
## Groups                        Heteroscedastic            
## Normality                                  No            
## Differences                               Yes            
## p-value                                <0.001            
## Method                               Wilcoxon

lineal(pre_post$tsh_previo,pre_post$imc_inicial,labely="tsh previo",labelx="imc inicial")
## 
## Call:
## lm(formula = y ~ x)
## 
## Coefficients:
## (Intercept)            x  
##      2.2787       0.0258  
## 
## [1] "r2=0.013"
## [1] "p=0.408"