source("/Users/mauriciogutierrez/Library/Mobile Documents/com~apple~CloudDocs/estadisticas/general_functions_new.R")
## 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
# Analisis de las pacientes que tienen dosificacion de vitamina D 

data=readexcel("/Users/mauriciogutierrez/Library/Mobile Documents/com~apple~CloudDocs/estadisticas/Pilar_Serra/datos_230315_mes.xls","Hoja2")
datavd=data[which(data$tienevitaminad==1),]

#============================================================= Demograficos

# Edad 
means(datavd,datavd$Edad)
## 
##                                       Edad
## n                                       60
## Mean                                 27.35
## Median                                26.5
## Sd                                    7.54
## Min                                     16
## Max                                     42
## Range                                   26
## Q1                                   21.75
## Q3                                      33
## Iqr                                  11.25
## Normality                            0.014
## ICI                                  27.29
## SCI                                  27.41
## Summary   Median[Q1-Q3]  -->26.5(21.75-33)

# Raza
freq(datavd,datavd$Raza,c("B","AF"),using_na=T)

## 
##       absolute relative cumulative   ici   ics
## B           53    98.15      98.15 90.11 99.95
## AF           1     1.85        100  0.05  9.89
## Total       54   100.00
#============================================================= AP
freq(datavd,datavd$ap_diabetes,c("No","DM1","DM2"))

## 
##         absolute relative cumulative   ici   ics
## No            38    63.33      63.33  49.9 75.41
## DM1            5     8.33      71.67  2.76 18.39
## DM2           16    26.67      98.33 16.07 39.66
## Missing        1     1.67     100.00  0.04  8.94
## Total         59   100.00
freq(datavd,datavd$ap_tiroides,c("No","Hipotiroidismo","Bocio","Otra"))

## 
##                absolute relative cumulative   ici   ics
## No                   36       60         60 46.54 72.44
## Hipotiroidismo       19    31.67      91.67 20.26 44.96
## Bocio                 2     3.33         95  0.41 11.53
## Otra                  3        5        100  1.04 13.92
## Missing               0        0     100.00     0  5.96
## Total                60   100.00
freq(datavd,datavd$ap_hta,c("No","Si"))

## 
##         absolute relative cumulative   ici   ics
## No            48       80         80 67.67 89.22
## Si            11    18.33      98.33  9.52 30.44
## Missing        1     1.67     100.00  0.04  8.94
## Total         59   100.00
freq(datavd,datavd$tabaquismo,c("No","Si"))

## 
##         absolute relative cumulative   ici   ics
## No            46    76.67      76.67 63.96 86.62
## Si            13    21.67      98.33 12.07  34.2
## Missing        1     1.67     100.00  0.04  8.94
## Total         59   100.00
#============================================================= AF
freq(datavd,datavd$af_dm2,c("No","Si"))

## 
##         absolute relative cumulative   ici   ics
## No            27       45         45 32.12 58.39
## Si            33       55        100 41.61 67.88
## Missing        0        0     100.00     0  5.96
## Total         60   100.00
freq(datavd,datavd$af_tiroides,c("No","Si"))

## 
##         absolute relative cumulative   ici   ics
## No            28    46.67      46.67 33.67    60
## Si            29    48.33         95 35.23 61.61
## Missing        3        5     100.00  1.04 13.92
## Total         57   100.00
#============================================================= AO
freq(datavd,datavd$ap_dg,c("No","Si"))

## 
##         absolute relative cumulative   ici   ics
## No            46    76.67      76.67 63.96 86.62
## Si            11    18.33         95  9.52 30.44
## Missing        3        5     100.00  1.04 13.92
## Total         57   100.00
freq(datavd,datavd$ap_rnmacrosomico,c("No","Si"))

## 
##         absolute relative cumulative   ici   ics
## No            53    88.33      88.33 77.43 95.18
## Si             6       10      98.33  3.76 20.51
## Missing        1     1.67     100.00  0.04  8.94
## Total         59   100.00
freq(datavd,datavd$ap_rnbajopeso,c("No","Si"))

## 
##         absolute relative cumulative   ici   ics
## No            54       90         90 79.49 96.24
## Si             3        5         95  1.04 13.92
## Missing        3        5     100.00  1.04 13.92
## Total         57   100.00
datavd$esmultipara=ifelse(datavd$multipara>=2,1,0)
freq(datavd,datavd$esmultipara,c("No","Si"))

## 
##         absolute relative cumulative   ici   ics
## No            30       50         50 36.81 63.19
## Si            29    48.33      98.33 35.23 61.61
## Missing        1     1.67     100.00  0.04  8.94
## Total         59   100.00
freq(datavd,datavd$perdidarecurrenteembarazo,c("No","Si"))

## 
##         absolute relative cumulative   ici   ics
## No            49    81.67      81.67 69.56 90.48
## Si             9       15      96.67   7.1 26.57
## Missing        2     3.33     100.00  0.41 11.53
## Total         58   100.00
#============================================================= Gestacion
freq(datavd,datavd$imc_pre,c("","NP","SP","OB","BP"),using_na=T)

## 
##       absolute relative cumulative   ici   ics
##              1     1.75       1.75  0.04  9.39
## NP          14    24.56      26.32 14.13 37.76
## SP           9    15.79      42.11  7.48 27.87
## OB          32    56.14      98.25 42.36 69.26
## BP           1     1.75        100  0.04  9.39
## Total       57   100.00
means(datavd,datavd$edad_gestacional_1c)
## 
##                      edad_gestacional_1c
## n                                     60
## Mean                               20.25
## Median                                22
## Sd                                  9.15
## Min                                    3
## Max                                   36
## Range                                 33
## Q1                                 12.75
## Q3                                    28
## Iqr                                15.25
## Normality                          0.034
## ICI                                20.18
## SCI                                20.32
## Summary   Median[Q1-Q3]  -->22(12.75-28)

freq(datavd,datavd$embarazo_fetos)

## 
##         absolute relative cumulative   ici   ics
## 1             57       95         95 86.08 98.96
## 2              2     3.33      98.33  0.41 11.53
## Missing        1     1.67     100.00  0.04  8.94
## Total         59   100.00
# Presencia de DM en embarazo actual
freq(datavd,datavd$dg_actual,c("No","Pregestacional","Gestacional"))

## 
##                absolute relative cumulative   ici   ics
## No                   15       25         25 14.72 37.86
## Pregestacional       20    33.33      58.33 21.69 46.69
## Gestacional          15       25      83.33 14.72 37.86
## Missing              10    16.67     100.00  8.29 28.52
## Total                50   100.00
# Presencia de EHE en embarazo actual
freq(datavd,datavd$ehe_actual,c("No","Si"))

## 
##         absolute relative cumulative   ici   ics
## No            40    66.67      66.67 53.31 78.31
## Si            12       20      86.67 10.78 32.33
## Missing        8    13.33     100.00  5.94 24.59
## Total         52   100.00
#============================================================= Parto

# Peso RN
freq(datavd,datavd$peso_rn,c("AEG","PEG","macrosomico"))

## 
##             absolute relative cumulative   ici   ics
## AEG               37    61.67      61.67 48.21 73.93
## PEG                2     3.33         65  0.41 11.53
## macrosomico        5     8.33      73.33  2.76 18.39
## Missing           16    26.67     100.00 16.07 39.66
## Total             44   100.00
# Complicaciones RN
freq(datavd,datavd$complicaciones_rn,c("Si","No"))

## 
##         absolute relative cumulative   ici   ics
## Si             5     8.33       8.33  2.76 18.39
## No            24       40      48.33 27.56 53.46
## Missing       31    51.67     100.00 38.39 64.77
## Total         29   100.00
# Finalizacion parto
freq(datavd,datavd$finalizacion_parto,c("Parto","Cesarea","Aborto"))

## 
##         absolute relative cumulative   ici   ics
## Parto         14    23.33      23.33 13.38 36.04
## Cesarea       30       50      73.33 36.81 63.19
## Aborto         1     1.67         75  0.04  8.94
## Missing       15       25     100.00 14.72 37.86
## Total         45   100.00
#============================================================= Analisis Vitamina D

# Comparacion vitamina D por trimestre
means(datavd,datavd$promediovd,datavd$trimestre)
## 
##                   trimestre = 1       trimestre = 2     trimestre = 3
## n                            15                  20                23
## Mean                      19.17               17.12              15.7
## Median                       14                16.5                14
## Sd                        11.78                7.11              7.09
## Min                           3                   5                 6
## Max                          40                  34                34
## Range                        37                  29                28
## Q1                           10               12.25              11.5
## Q3                        25.25               22.25              21.5
## Iqr                       15.25                  10                10
## Normal                    0.198               0.759             0.071
## IIC                       18.97               17.02              15.6
## ICS                       19.36               17.23             15.79
## Summary2    19.17 (18.97-19.36) 17.12 (17.02-17.23) 15.7 (15.6-15.79)
## Summary           Mean[ICI-ICS]                                      
## Groups            Homocedastics                                      
## Normality                   Yes                                      
## Differences                  No                                      
## p-value                   0.477                                      
## Method                    ANOVA

# Promedio vitamina D
means(datavd,datavd$promediovd)
## 
##                               promediovd
## n                                     60
## Mean                               17.77
## Median                             14.75
## Sd                                  9.14
## Min                                    3
## Max                                   40
## Range                                 37
## Q1                                    11
## Q3                                    24
## Iqr                                   13
## Normality                          0.002
## ICI                                17.69
## SCI                                17.84
## Summary   Median[Q1-Q3]  -->14.75(11-24)

# Comparacion vitamina D por IMC categorizado
means(datavd,datavd$promediovd,datavd$imc_pre,c("","NP","SP","OB","BP"))
## Warning in specify_decimal(rr[[i]]$sd, decimals): NAs introduced by
## coercion
## Warning in specify_decimal(rr[[i]]$sd, decimals): NAs introduced by
## coercion
## 
##                  imc_pre =    imc_pre = NP imc_pre = SP    imc_pre = OB
## n                         1             14            9              32
## Mean                     13          15.36         20.5           17.48
## Median                   13          13.75           19            14.5
## Sd                     <NA>           9.46        13.84            6.67
## Min                      13              3            6               9
## Max                      13           32.5           40              39
## Range                     0           29.5           34              30
## Q1                       13            7.5            9           12.75
## Q3                       13             24           34              23
## Iqr                       0           16.5           25           10.25
## Normal                   -1          0.217        0.116           0.002
## IIC                      -1           15.2         20.2           17.41
## ICS                      -1          15.52         20.8           17.56
## Summary2         13 (13-13) 13.75 (7.5-24)    19 (9-34) 14.5 (12.75-23)
## Summary       Median[Q1-Q3]                                            
## Groups      Heteroscedastic                                            
## Normality                No                                            
## Differences              No                                            
## p-value               0.514                                            
## Method       Kruskal-Wallis                                            
##             imc_pre = BP
## n                      1
## Mean                  34
## Median                34
## Sd                  <NA>
## Min                   34
## Max                   34
## Range                  0
## Q1                    34
## Q3                    34
## Iqr                    0
## Normal                -1
## IIC                   -1
## ICS                   -1
## Summary2      34 (34-34)
## Summary                 
## Groups                  
## Normality               
## Differences             
## p-value                 
## Method

# Comparacion vitamina D por multiparidad dicotomizada
means(datavd,datavd$promediovd,datavd$esmultipara,c("No","Si"))
## 
##             esmultipara = No esmultipara = Si
## n                         30               29
## Mean                   14.15            21.36
## Median                    13               19
## Sd                      6.98             9.87
## Min                        3                9
## Max                       26               40
## Range                     23               31
## Q1                         9               14
## Q3                     21.75               26
## Iqr                    12.75               12
## Normal                 0.022            0.007
## IIC                    14.07            21.25
## ICS                    14.23            21.48
## Summary2        13 (9-21.75)       19 (14-26)
## Summary        Median[Q1-Q3]                 
## Groups         Homocedastics                 
## Normality                 No                 
## Differences              Yes                 
## p-value                0.003                 
## Method        Kruskal-Wallis

# Promedio vitamina D categorizado
datavd$categoriavitaminad=ifelse(datavd$promediovd<10,"Deficiencia",ifelse(datavd$promediovd<30,"Insuficiencia","Suficiencia"))
freq(datavd,datavd$categoriavitaminad)

## 
##               absolute relative cumulative   ici   ics
## Deficiencia         10    16.67      16.67  8.29 28.52
## Insuficiencia       43    71.67      88.33 58.56 82.55
## Suficiencia          7    11.67        100  4.82 22.57
## Missing              0        0     100.00     0  5.96
## Total               60   100.00
# Relacion entre Edad y vitamina D
lineal(datavd$promediovd,datavd$Edad,"Vitamina D","Edad")
## 
## Call:
## lm(formula = y ~ x)
## 
## Coefficients:
## (Intercept)            x  
##     13.1529       0.1687  
## 
## [1] "r2=0.019"
## [1] "p=0.289"

# Vitamina D segun condicion DM en embarazo
means(datavd,datavd$promediovd,datavd$dg_actual,c("No","Pregestacional","Gestacional"))
## 
##                 dg_actual = No dg_actual = Pregestacional
## n                           15                         20
## Mean                      15.4                      17.55
## Median                      14                         14
## Sd                        7.76                      10.13
## Min                          5                          3
## Max                         34                         40
## Range                       29                         37
## Q1                        10.5                      10.75
## Q3                        18.5                      22.25
## Iqr                          8                       11.5
## Normal                   0.104                      0.054
## IIC                      15.27                      17.41
## ICS                      15.53                      17.69
## Summary2    15.4 (15.27-15.53)        17.55 (17.41-17.69)
## Summary          Mean[ICI-ICS]                           
## Groups           Homocedastics                           
## Normality                  Yes                           
## Differences                 No                           
## p-value                  0.756                           
## Method                   ANOVA                           
##             dg_actual = Gestacional
## n                                15
## Mean                           17.4
## Median                           15
## Sd                             8.61
## Min                               6
## Max                              34
## Range                            28
## Q1                             10.5
## Q3                               25
## Iqr                            14.5
## Normal                         0.29
## IIC                           17.26
## ICS                           17.54
## Summary2         17.4 (17.26-17.54)
## Summary                            
## Groups                             
## Normality                          
## Differences                        
## p-value                            
## Method

# Vitamina D segun EHE
means(datavd,datavd$promediovd,datavd$ehe_actual,c("No","Si"))
## 
##                     ehe_actual = No ehe_actual = Si
## n                                40              12
## Mean                          18.76           13.96
## Median                        19.25              14
## Sd                             9.94            4.67
## Min                               3               6
## Max                              40            25.5
## Range                            37            19.5
## Q1                               10            12.5
## Q3                               25           14.25
## Iqr                              15            1.75
## Normal                        0.067           0.083
## IIC                           18.66           13.87
## ICS                           18.86           14.04
## Summary2              19.25 (10-25) 14 (12.5-14.25)
## Summary               Median[Q1-Q3]                
## Groups              Heteroscedastic                
## Normality                       Yes                
## Differences                     Yes                
## p-value                       0.026                
## Method      t-Student(Satterhwaite)

# Vitamina D segun finalizacion parto 
means(datavd,datavd$promediovd,datavd$finalizacion_parto,c("Parto","Cesarea","Aborto"))
## Warning in specify_decimal(rr[[i]]$sd, decimals): NAs introduced by
## coercion
## 
##             finalizacion_parto = Parto finalizacion_parto = Cesarea
## n                                   14                           30
## Mean                             22.43                        16.97
## Median                            24.5                           14
## Sd                                9.01                         8.53
## Min                                  7                            6
## Max                                 36                           40
## Range                               29                           34
## Q1                               14.25                           11
## Q3                                  26                        21.38
## Iqr                              11.75                        10.38
## Normal                            0.34                        0.001
## IIC                              22.27                        16.87
## ICS                              22.58                        17.07
## Summary2               24.5 (14.25-26)                14 (11-21.38)
## Summary                  Median[Q1-Q3]                             
## Groups                 Heteroscedastic                             
## Normality                           No                             
## Differences                        Yes                             
## p-value                          0.028                             
## Method                  Kruskal-Wallis                             
##             finalizacion_parto = Aborto
## n                                     1
## Mean                                  3
## Median                                3
## Sd                                 <NA>
## Min                                   3
## Max                                   3
## Range                                 0
## Q1                                    3
## Q3                                    3
## Iqr                                   0
## Normal                               -1
## IIC                                  -1
## ICS                                  -1
## Summary2                        3 (3-3)
## Summary                                
## Groups                                 
## Normality                              
## Differences                            
## p-value                                
## Method

# Suplementacion vitamina D  
datavd$tienesuplementacion=ifelse(is.na(datavd$suplemento_vitd),0,1)
freq(datavd,datavd$tienesuplementacion,c("No","Si"))

## 
##         absolute relative cumulative   ici   ics
## No            17    28.33      28.33 17.45 41.44
## Si            43    71.67        100 58.56 82.55
## Missing        0        0     100.00     0  5.96
## Total         60   100.00
# Suplementacion vitamina D y dm en embarazo
tables(datavd,datavd$dg_actual,datavd$tienesuplementacion,c("No","Pregestacional","Gestacional"),c("No","Si"))
## 
##                 tienesuplementacion
## dg_actual        No Si Sum
##   No              4 11  15
##   Pregestacional  2 18  20
##   Gestacional     5 10  15
##   Sum            11 39  50
## 
## by Row (%)
##                   No    Si
## No             26.66 73.33
## Pregestacional 10.00 90.00
## Gestacional    33.33 66.66
##                22.00 78.00
## 
## by Col (%)
##                   No    Si   
## No             36.36 28.20 30
## Pregestacional 18.18 46.15 40
## Gestacional    45.45 25.64 30
## 
## Fischer Test  p = 0.247

# Suplementacion vitamina D y EHE
tables(datavd,datavd$ehe_actual,datavd$tienesuplementacion,c("No","Si"),c("No","Si"))
## 
##           tienesuplementacion
## ehe_actual No Si Sum
##        No  11 29  40
##        Si   2 10  12
##        Sum 13 39  52
## 
## by Row (%)
##       No    Si
## No 27.50 72.50
## Si 16.66 83.33
##    25.00 75.00
## 
## by Col (%)
##       No    Si      
## No 84.61 74.35 76.92
## Si 15.38 25.64 23.07
## 
## Fischer Test  p = 0.706

# Suplementacion vitamina D y finalizacion Parto
tables(datavd,datavd$finalizacion_parto,datavd$tienesuplementacion,c("Parto","Cesarea","Aborto"),c("No","Si"))
## 
##                   tienesuplementacion
## finalizacion_parto No Si Sum
##            Parto    5  9  14
##            Cesarea  6 24  30
##            Aborto   0  1   1
##            Sum     11 34  45
## 
## by Row (%)
##            No     Si
## Parto   35.71  64.28
## Cesarea 20.00  80.00
## Aborto   0.00 100.00
##         24.44  75.55
## 
## by Col (%)
##            No    Si      
## Parto   45.45 26.47 31.11
## Cesarea 54.54 70.58 66.66
## Aborto   0.00  2.94  2.22
## 
## Fischer Test  p = 0.461

# Relacion vitamina D y mes de obtencion
datavd$Mes.de.extraccion
##  [1] NA  8  8  5 12 10  3 10 11  9  1  2 NA 10  5 10  2  9  5 NA 12 12  8
## [24] 12  5  9  3  6 10  3  2  8 10  5  5  9  1  9  9 11  3  2 11  8 12  5
## [47]  9  3 10 12  4 12  9  8  9  4  8 11  2 NA
freq(datavd,datavd$Mes.de.extraccion)

## 
##         absolute relative cumulative  ici   ics
## 1              2     3.33       3.33 0.41 11.53
## 2              5     8.33      11.67 2.76 18.39
## 3              5     8.33         20 2.76 18.39
## 4              2     3.33      23.33 0.41 11.53
## 5              7    11.67         35 4.82 22.57
## 6              1     1.67      36.67 0.04  8.94
## 8              7    11.67      48.33 4.82 22.57
## 9              9       15      63.33  7.1 26.57
## 10             7    11.67         75 4.82 22.57
## 11             4     6.67      81.67 1.85  16.2
## 12             7    11.67      93.33 4.82 22.57
## Missing        4     6.67     100.00 1.85  16.2
## Total         56   100.00
datavd$estacion=ifelse(datavd$Mes.de.extraccion==1|datavd$Mes.de.extraccion==2|datavd$Mes.de.extraccion==12,"Verano",ifelse(datavd$Mes.de.extraccion==3|datavd$Mes.de.extraccion==4|datavd$Mes.de.extraccion==5,"Otono",ifelse(datavd$Mes.de.extraccion==6|datavd$Mes.de.extraccion==7|datavd$Mes.de.extraccion==8,"Invierno","Primavera")))
freq(datavd,datavd$estacion)

## 
##           absolute relative cumulative   ici   ics
## Invierno         8    13.33      13.33  5.94 24.59
## Otono           14    23.33      36.67 13.38 36.04
## Primavera       20    33.33         70 21.69 46.69
## Verano          14    23.33      93.33 13.38 36.04
## Missing          4     6.67     100.00  1.85  16.2
## Total           56   100.00
means(datavd,datavd$promediovd,datavd$estacion)
## 
##             estacion = Invierno   estacion = Otono estacion = Primavera
## n                             8                 14                   20
## Mean                      17.75              21.89                13.47
## Median                     19.5               22.5                 11.5
## Sd                         7.08               7.57                 8.18
## Min                           6                 13                    3
## Max                          25                 34                   36
## Range                        19                 21                   33
## Q1                           13              14.25                    9
## Q3                         23.5              24.75                13.25
## Iqr                        10.5               10.5                 4.25
## Normal                    0.316              0.063                0.003
## IIC                       17.59              21.76                13.36
## ICS                       17.91              22.02                13.59
## Summary2         19.5 (13-23.5) 22.5 (14.25-24.75)       11.5 (9-13.25)
## Summary           Median[Q1-Q3]                                        
## Groups            Homocedastics                                        
## Normality                    No                                        
## Differences                 Yes                                        
## p-value                   0.008                                        
## Method           Kruskal-Wallis                                        
##             estacion = Verano
## n                          14
## Mean                    21.25
## Median                   16.5
## Sd                       10.8
## Min                         9
## Max                        40
## Range                      31
## Q1                      14.25
## Q3                       25.5
## Iqr                     11.25
## Normal                  0.022
## IIC                     21.07
## ICS                     21.43
## Summary2    16.5 (14.25-25.5)
## Summary                      
## Groups                       
## Normality                    
## Differences                  
## p-value                      
## Method

# vitamina D y peso rn
means(datavd,datavd$promediovd,datavd$peso_rn,c("PEG","AEG","GEG"))
## 
##              peso_rn = PEG peso_rn = AEG peso_rn = GEG
## n                       37             2             5
## Mean                 19.19             9            19
## Median                  15             9            15
## Sd                    9.04          4.24          8.57
## Min                      7             6            13
## Max                     40            12            34
## Range                   33             6            21
## Q1                      12           7.5            15
## Q3                      25          10.5            18
## Iqr                     13             3             3
## Normal               0.005            -1         0.021
## IIC                   19.1            -1         18.74
## ICS                  19.28            -1         19.26
## Summary2        15 (12-25)  9 (7.5-10.5)    15 (15-18)
## Summary      Median[Q1-Q3]                            
## Groups       Homocedastics                            
## Normality               No                            
## Differences             No                            
## p-value              0.175                            
## Method      Kruskal-Wallis

# vitamina D y complicaciones rn
means(datavd,datavd$promediovd,datavd$complicaciones_rn)
## 
##             complicaciones_rn = 1 complicaciones_rn = 2
## n                               5                    24
## Mean                         16.2                 19.23
## Median                         13                 18.75
## Sd                           7.22                  7.99
## Min                            10                     6
## Max                            24                    34
## Range                          14                    28
## Q1                             10                    13
## Q3                             24                    25
## Iqr                            14                    12
## Normal                      0.046                 0.194
## IIC                         15.98                 19.13
## ICS                         16.42                 19.33
## Summary2               13 (10-24)         18.75 (13-25)
## Summary             Median[Q1-Q3]                      
## Groups              Homocedastics                      
## Normality                      No                      
## Differences                    No                      
## p-value                     0.325                      
## Method             Kruskal-Wallis

datavd$complicaciones_rn=ifelse(datavd$complicaciones_rn==2,0,1)

# Analisis multivariado por complicaciones del RN
datavd$dg_actual=as.numeric(datavd$dg_actual)
datavd$dg_actual=ifelse(datavd$dg_actual==2,0,1)
 
modelo <- glm(complicaciones_rn ~ promediovd  + Edad + tabaquismo  + imc_pre + embarazo_fetos  + ehe_actual + dg_actual , data = datavd, family = "binomial")
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
summary(modelo)
## 
## Call:
## glm(formula = complicaciones_rn ~ promediovd + Edad + tabaquismo + 
##     imc_pre + embarazo_fetos + ehe_actual + dg_actual, family = "binomial", 
##     data = datavd)
## 
## Deviance Residuals: 
##        Min          1Q      Median          3Q         Max  
## -3.493e-05  -2.100e-08  -2.100e-08  -2.100e-08   3.380e-05  
## 
## Coefficients:
##                  Estimate Std. Error z value Pr(>|z|)
## (Intercept)    -2.953e+02  3.886e+06   0.000    1.000
## promediovd     -9.955e+00  9.113e+03  -0.001    0.999
## Edad            6.509e+00  6.281e+03   0.001    0.999
## tabaquismo      3.837e+01  7.188e+04   0.001    1.000
## imc_pre        -2.231e+01  1.288e+06   0.000    1.000
## embarazo_fetos  1.490e+02  1.349e+06   0.000    1.000
## ehe_actual      2.397e+01  1.286e+06   0.000    1.000
## dg_actual       6.923e+01  1.037e+05   0.001    0.999
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 1.8597e+01  on 25  degrees of freedom
## Residual deviance: 3.4684e-09  on 18  degrees of freedom
##   (34 observations deleted due to missingness)
## AIC: 16
## 
## Number of Fisher Scoring iterations: 25
#exp(cbind(OR = coef(modelo), confint(modelo)))

# Analisis multivariado para peso del del RN

library("foreign")
library(ggplot2)
library(MASS)
library(Hmisc)
## Loading required package: grid
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## 
## The following objects are masked from 'package:plyr':
## 
##     is.discrete, summarize
## 
## The following objects are masked from 'package:base':
## 
##     format.pval, round.POSIXt, trunc.POSIXt, units
library(reshape2)

m <- polr (as.factor(peso_rn) ~ promediovd  + Edad + tabaquismo  + imc_pre + embarazo_fetos  + ehe_actual + dg_actual, data=datavd)
ctable <- coef(summary(m))
## 
## Re-fitting to get Hessian
ci <- confint(m)
## Waiting for profiling to be done...
## 
## Re-fitting to get Hessian
exp(cbind(OR = coef(m), ci))
##                          OR      2.5 %    97.5 %
## promediovd     9.810398e-01 0.85073923  1.129080
## Edad           1.079329e+00 0.90295112  1.318858
## tabaquismo     1.668948e+00 0.11581352 19.151543
## imc_pre        1.435377e+00 0.37318932  9.229692
## embarazo_fetos 1.036712e-06         NA        NA
## ehe_actual     2.739723e+00 0.16570297 42.894424
## dg_actual      1.662305e-01 0.01043718  1.498681
#============================================================= Fin