knitr::opts_chunk$set(echo = TRUE)
library(ez)
library(ggplot2)
library(lattice)
bda=read.csv("C:\\Users\\gabri\\Downloads\\tccalenerma.csv",header=TRUE)
bda$antral.volume.ml.kg=bda$antral.volume / bda$weight
# for non-repeated-measures analysis
bd2a=subset(bda,bda$t==0)
# restrict to per protocol analysis
bdpa=subset(bda,bda$selection=="included")
bdpa2=subset(bdpa,bdpa$t==0)

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

oj=subset(bdpa, bdpa$study.goup=="OJ")
m=subset(bdpa, bdpa$study.goup=="M")
cm=subset(bdpa, bdpa$study.goup=="CM")

Data summary at time 0

summary(bd2a)
##        id        selection                              selection.reason
##  Min.   : 1   excluded:11                                       : 4     
##  1st Qu.:17   included:54   cesarean indicated before completion: 5     
##  Median :33                 early birth                         : 2     
##  Mean   :33                 ingested another solution           : 2     
##  3rd Qu.:49                 vomited                             : 2     
##  Max.   :65                 NA's                                :50     
##                                                                         
##  study.goup      age            weight          height     
##  CM:22      Min.   :18.00   Min.   :52.30   Min.   :1.450  
##  M :19      1st Qu.:21.00   1st Qu.:66.00   1st Qu.:1.570  
##  OJ:24      Median :26.00   Median :71.30   Median :1.600  
##             Mean   :26.52   Mean   :72.71   Mean   :1.603  
##             3rd Qu.:30.00   3rd Qu.:78.00   3rd Qu.:1.630  
##             Max.   :42.00   Max.   :99.00   Max.   :1.720  
##                                                            
##  gestational.age    parityG         parityP          parityC      
##  Min.   :24.42   Min.   :1.000   Min.   :0.0000   Min.   :0.0000  
##  1st Qu.:38.14   1st Qu.:1.000   1st Qu.:0.0000   1st Qu.:0.0000  
##  Median :39.00   Median :2.000   Median :0.0000   Median :0.0000  
##  Mean   :38.63   Mean   :2.015   Mean   :0.6308   Mean   :0.1385  
##  3rd Qu.:39.85   3rd Qu.:2.000   3rd Qu.:1.0000   3rd Qu.:0.0000  
##  Max.   :41.57   Max.   :7.000   Max.   :6.0000   Max.   :1.0000  
##                                                                   
##     parityA       labor.induction labor   labor.hours
##  Min.   :0.0000   N:45            S:65   ?      :13  
##  1st Qu.:0.0000   S:20                   6      : 3  
##  Median :0.0000                          1      : 2  
##  Mean   :0.2308                          9      : 2  
##  3rd Qu.:0.0000                          12     : 1  
##  Max.   :2.0000                          (Other): 2  
##                                          NA's   :42  
##                 morbidity  labor.analgesia advese.outcomes
##  ArterialHypertension: 4   N:62            N     :63      
##  N                   :61   S: 3            nausea: 2      
##                                                           
##                                                           
##                                                           
##                                                           
##                                                           
##  fasted.antral.volume     time.0         time.30         time.60      
##  Min.   : 0.00        Min.   :119.7   Min.   : 20.2   Min.   :  0.00  
##  1st Qu.:10.50        1st Qu.:183.2   1st Qu.: 57.6   1st Qu.: 27.40  
##  Median :15.10        Median :282.0   Median :150.8   Median : 68.85  
##  Mean   :16.24        Mean   :273.2   Mean   :138.8   Mean   : 65.62  
##  3rd Qu.:22.80        3rd Qu.:339.1   3rd Qu.:191.6   3rd Qu.: 85.67  
##  Max.   :60.70        Max.   :431.7   Max.   :279.1   Max.   :177.60  
##                                       NA's   :4       NA's   :9       
##     time.90         time.120            t     antral.volume full.0.8      
##  Min.   : 0.00   Min.   : 0.000   Min.   :0   Min.   :450   Mode:logical  
##  1st Qu.:14.75   1st Qu.: 6.125   1st Qu.:0   1st Qu.:450   TRUE:65       
##  Median :28.80   Median :14.100   Median :0   Median :450                 
##  Mean   :30.32   Mean   :16.428   Mean   :0   Mean   :450                 
##  3rd Qu.:43.65   3rd Qu.:25.775   3rd Qu.:0   3rd Qu.:450                 
##  Max.   :82.00   Max.   :66.000   Max.   :0   Max.   :450                 
##  NA's   :10      NA's   :11                                               
##  full.1.5       antral.volume.ml.kg
##  Mode:logical   Min.   :4.545      
##  TRUE:65        1st Qu.:5.769      
##                 Median :6.311      
##                 Mean   :6.308      
##                 3rd Qu.:6.818      
##                 Max.   :8.604      
## 

Orange juice group

oj=subset(bd2a, bda$study.goup=="OJ")

summary(oj)
##        id           selection  
##  Min.   : 1.00   excluded:  8  
##  1st Qu.:14.00   included: 21  
##  Median :39.00   NA's    :115  
##  Mean   :32.38                 
##  3rd Qu.:46.00                 
##  Max.   :65.00                 
##  NA's   :115                   
##                              selection.reason study.goup      age       
##                                      :  2     CM  : 12   Min.   :18.00  
##  cesarean indicated before completion:  4     M   :  6   1st Qu.:21.00  
##  early birth                         :  2     OJ  : 11   Median :27.00  
##  ingested another solution           :  1     NA's:115   Mean   :26.55  
##  vomited                             :  1                3rd Qu.:31.00  
##  NA's                                :134                Max.   :41.00  
##                                                          NA's   :115    
##      weight          height      gestational.age    parityG     
##  Min.   :52.30   Min.   :1.450   Min.   :37.00   Min.   :1.000  
##  1st Qu.:66.00   1st Qu.:1.580   1st Qu.:38.42   1st Qu.:1.000  
##  Median :72.20   Median :1.600   Median :39.28   Median :1.000  
##  Mean   :74.26   Mean   :1.598   Mean   :39.18   Mean   :1.793  
##  3rd Qu.:80.00   3rd Qu.:1.620   3rd Qu.:39.71   3rd Qu.:2.000  
##  Max.   :99.00   Max.   :1.720   Max.   :41.57   Max.   :5.000  
##  NA's   :115     NA's   :115     NA's   :115     NA's   :115    
##     parityP          parityC           parityA       labor.induction
##  Min.   :0.0000   Min.   :0.00000   Min.   :0.0000   N   : 21       
##  1st Qu.:0.0000   1st Qu.:0.00000   1st Qu.:0.0000   S   :  8       
##  Median :0.0000   Median :0.00000   Median :0.0000   NA's:115       
##  Mean   :0.4138   Mean   :0.06897   Mean   :0.2759                  
##  3rd Qu.:1.0000   3rd Qu.:0.00000   3rd Qu.:0.0000                  
##  Max.   :2.0000   Max.   :1.00000   Max.   :2.0000                  
##  NA's   :115      NA's   :115       NA's   :115                     
##   labor      labor.hours                 morbidity   labor.analgesia
##  S   : 29   ?      :  5   ArterialHypertension:  2   N   : 27       
##  NA's:115   1      :  2   N                   : 27   S   :  2       
##             6      :  2   NA's                :115   NA's:115       
##             12     :  1                                             
##             2      :  1                                             
##             (Other):  2                                             
##             NA's   :131                                             
##  advese.outcomes fasted.antral.volume     time.0         time.30     
##  N     : 28      Min.   : 0.00        Min.   :145.3   Min.   : 30.6  
##  nausea:  1      1st Qu.:10.50        1st Qu.:230.9   1st Qu.:126.9  
##  NA's  :115      Median :13.90        Median :284.2   Median :154.8  
##                  Mean   :16.48        Mean   :279.4   Mean   :157.0  
##                  3rd Qu.:18.90        3rd Qu.:337.9   3rd Qu.:196.9  
##                  Max.   :60.70        Max.   :431.7   Max.   :279.1  
##                  NA's   :115          NA's   :115     NA's   :117    
##     time.60          time.90         time.120          t      
##  Min.   :  6.10   Min.   : 0.10   Min.   : 0.0   Min.   :0    
##  1st Qu.: 61.45   1st Qu.:24.50   1st Qu.: 9.4   1st Qu.:0    
##  Median : 75.70   Median :38.00   Median :18.5   Median :0    
##  Mean   : 77.66   Mean   :37.37   Mean   :20.3   Mean   :0    
##  3rd Qu.: 87.17   3rd Qu.:46.48   3rd Qu.:25.8   3rd Qu.:0    
##  Max.   :177.20   Max.   :82.00   Max.   :66.0   Max.   :0    
##  NA's   :122      NA's   :122     NA's   :123    NA's   :115  
##  antral.volume full.0.8       full.1.5       antral.volume.ml.kg
##  Min.   :450   Mode:logical   Mode:logical   Min.   :4.545      
##  1st Qu.:450   TRUE:29        TRUE:29        1st Qu.:5.625      
##  Median :450   NA's:115       NA's:115       Median :6.233      
##  Mean   :450                                 Mean   :6.193      
##  3rd Qu.:450                                 3rd Qu.:6.818      
##  Max.   :450                                 Max.   :8.604      
##  NA's   :115                                 NA's   :115

Maltodextrin group

m=subset(bd2a, bda$study.goup=="M")
summary(m)
##        id           selection 
##  Min.   : 7.00   excluded: 3  
##  1st Qu.:17.25   included:21  
##  Median :36.50   NA's    :90  
##  Mean   :35.00                
##  3rd Qu.:54.25                
##  Max.   :60.00                
##  NA's   :90                   
##                              selection.reason study.goup      age       
##                                      :  2     CM  : 7    Min.   :18.00  
##  cesarean indicated before completion:  1     M   : 8    1st Qu.:21.75  
##  early birth                         :  0     OJ  : 9    Median :25.50  
##  ingested another solution           :  1     NA's:90    Mean   :26.33  
##  vomited                             :  1                3rd Qu.:30.00  
##  NA's                                :109                Max.   :40.00  
##                                                          NA's   :90     
##      weight          height      gestational.age    parityG     
##  Min.   :53.30   Min.   :1.480   Min.   :37.00   Min.   :1.000  
##  1st Qu.:67.00   1st Qu.:1.597   1st Qu.:37.89   1st Qu.:1.000  
##  Median :70.90   Median :1.620   Median :38.64   Median :2.000  
##  Mean   :72.12   Mean   :1.611   Mean   :38.95   Mean   :2.083  
##  3rd Qu.:75.20   3rd Qu.:1.643   3rd Qu.:40.07   3rd Qu.:2.000  
##  Max.   :98.00   Max.   :1.720   Max.   :41.00   Max.   :7.000  
##  NA's   :90      NA's   :90      NA's   :90      NA's   :90     
##     parityP          parityC        parityA       labor.induction
##  Min.   :0.0000   Min.   :0.00   Min.   :0.0000   N   :15        
##  1st Qu.:0.0000   1st Qu.:0.00   1st Qu.:0.0000   S   : 9        
##  Median :0.0000   Median :0.00   Median :0.0000   NA's:90        
##  Mean   :0.6667   Mean   :0.25   Mean   :0.1667                  
##  3rd Qu.:1.0000   3rd Qu.:0.25   3rd Qu.:0.0000                  
##  Max.   :6.0000   Max.   :1.00   Max.   :1.0000                  
##  NA's   :90       NA's   :90     NA's   :90                      
##   labor     labor.hours                 morbidity  labor.analgesia
##  S   :24   ?      :  8   ArterialHypertension: 1   N   :23        
##  NA's:90   6      :  1   N                   :23   S   : 1        
##            9      :  1   NA's                :90   NA's:90        
##            1      :  0                                            
##            12     :  0                                            
##            (Other):  0                                            
##            NA's   :104                                            
##  advese.outcomes fasted.antral.volume     time.0         time.30      
##  N     :23       Min.   : 0.00        Min.   :119.7   Min.   : 31.20  
##  nausea: 1       1st Qu.:10.68        1st Qu.:182.9   1st Qu.: 48.25  
##  NA's  :90       Median :16.40        Median :287.4   Median :140.25  
##                  Mean   :15.82        Mean   :276.0   Mean   :126.90  
##                  3rd Qu.:22.25        3rd Qu.:356.1   3rd Qu.:185.53  
##                  Max.   :30.90        Max.   :416.4   Max.   :252.50  
##                  NA's   :90           NA's   :90      NA's   :92      
##     time.60          time.90         time.120           t     
##  Min.   :  3.50   Min.   : 0.00   Min.   : 0.00   Min.   :0   
##  1st Qu.: 17.27   1st Qu.: 7.90   1st Qu.: 7.50   1st Qu.:0   
##  Median : 69.55   Median :27.20   Median :11.50   Median :0   
##  Mean   : 63.00   Mean   :26.31   Mean   :13.95   Mean   :0   
##  3rd Qu.: 81.22   3rd Qu.:36.40   3rd Qu.:19.20   3rd Qu.:0   
##  Max.   :177.60   Max.   :62.90   Max.   :30.40   Max.   :0   
##  NA's   :92       NA's   :93      NA's   :93      NA's   :90  
##  antral.volume full.0.8       full.1.5       antral.volume.ml.kg
##  Min.   :450   Mode:logical   Mode:logical   Min.   :4.592      
##  1st Qu.:450   TRUE:24        TRUE:24        1st Qu.:5.985      
##  Median :450   NA's:90        NA's:90        Median :6.347      
##  Mean   :450                                 Mean   :6.346      
##  3rd Qu.:450                                 3rd Qu.:6.716      
##  Max.   :450                                 Max.   :8.443      
##  NA's   :90                                  NA's   :90

Coffee with milk group

tm=subset(bd2a, bda$study.goup=="CM")
summary(tm)
##        id           selection  
##  Min.   :25.00   excluded:  0  
##  1st Qu.:27.75   included: 12  
##  Median :30.50   NA's    :120  
##  Mean   :30.50                 
##  3rd Qu.:33.25                 
##  Max.   :36.00                 
##  NA's   :120                   
##                              selection.reason study.goup      age       
##                                      :  0     CM  :  3   Min.   :20.00  
##  cesarean indicated before completion:  0     M   :  5   1st Qu.:22.75  
##  early birth                         :  0     OJ  :  4   Median :24.50  
##  ingested another solution           :  0     NA's:120   Mean   :26.83  
##  vomited                             :  0                3rd Qu.:31.00  
##  NA's                                :132                Max.   :42.00  
##                                                          NA's   :120    
##      weight          height      gestational.age    parityG     
##  Min.   :57.00   Min.   :1.520   Min.   :24.42   Min.   :1.000  
##  1st Qu.:63.00   1st Qu.:1.550   1st Qu.:37.43   1st Qu.:1.000  
##  Median :70.90   Median :1.590   Median :38.85   Median :2.000  
##  Mean   :70.14   Mean   :1.601   Mean   :36.64   Mean   :2.417  
##  3rd Qu.:75.20   3rd Qu.:1.653   3rd Qu.:39.07   3rd Qu.:3.000  
##  Max.   :84.00   Max.   :1.720   Max.   :41.00   Max.   :7.000  
##  NA's   :120     NA's   :120     NA's   :120     NA's   :120    
##     parityP         parityC           parityA     labor.induction
##  Min.   :0.000   Min.   :0.00000   Min.   :0.00   N   :  9       
##  1st Qu.:0.000   1st Qu.:0.00000   1st Qu.:0.00   S   :  3       
##  Median :1.000   Median :0.00000   Median :0.00   NA's:120       
##  Mean   :1.083   Mean   :0.08333   Mean   :0.25                  
##  3rd Qu.:1.250   3rd Qu.:0.00000   3rd Qu.:0.00                  
##  Max.   :4.000   Max.   :1.00000   Max.   :2.00                  
##  NA's   :120     NA's   :120       NA's   :120                   
##   labor      labor.hours                 morbidity   labor.analgesia
##  S   : 12   ?      :  0   ArterialHypertension:  1   N   : 12       
##  NA's:120   1      :  0   N                   : 11   S   :  0       
##             12     :  0   NA's                :120   NA's:120       
##             2      :  0                                             
##             4      :  0                                             
##             (Other):  0                                             
##             NA's   :132                                             
##  advese.outcomes fasted.antral.volume     time.0         time.30     
##  N     : 12      Min.   : 0.00        Min.   :140.6   Min.   : 20.2  
##  nausea:  0      1st Qu.:13.35        1st Qu.:174.3   1st Qu.: 42.5  
##  NA's  :120      Median :16.15        Median :262.8   Median :149.2  
##                  Mean   :16.51        Mean   :252.5   Mean   :119.4  
##                  3rd Qu.:23.48        3rd Qu.:325.8   3rd Qu.:172.6  
##                  Max.   :29.80        Max.   :382.9   Max.   :222.0  
##                  NA's   :120          NA's   :120     NA's   :120    
##     time.60          time.90        time.120           t      
##  Min.   :  0.00   Min.   : 0.0   Min.   : 0.00   Min.   :0    
##  1st Qu.: 20.55   1st Qu.:12.7   1st Qu.: 4.23   1st Qu.:0    
##  Median : 48.75   Median :20.6   Median :12.40   Median :0    
##  Mean   : 48.35   Mean   :24.4   Mean   :13.99   Mean   :0    
##  3rd Qu.: 77.30   3rd Qu.:40.2   3rd Qu.:26.90   3rd Qu.:0    
##  Max.   :100.50   Max.   :53.4   Max.   :31.50   Max.   :0    
##  NA's   :120      NA's   :120    NA's   :120     NA's   :120  
##  antral.volume full.0.8       full.1.5       antral.volume.ml.kg
##  Min.   :450   Mode:logical   Mode:logical   Min.   :5.357      
##  1st Qu.:450   TRUE:12        TRUE:12        1st Qu.:5.985      
##  Median :450   NA's:120       NA's:120       Median :6.347      
##  Mean   :450                                 Mean   :6.508      
##  3rd Qu.:450                                 3rd Qu.:7.148      
##  Max.   :450                                 Max.   :7.895      
##  NA's   :120                                 NA's   :120

Hypothesis test

Main outcome

ezANOVA(data=bdpa,dv=antral.volume,wid=factor(id),between=study.goup,within=t)
## Warning: Converting "id" to factor for ANOVA.
## Warning: "t" will be treated as numeric.
## Warning: There is at least one numeric within variable, therefore aov()
## will be used for computation and no assumption checks will be obtained.
## $ANOVA
##         Effect DFn DFd           F            p p<.05       ges
## 1   study.goup   2  51    87.77940 3.061437e-17     * 0.7324230
## 2            t   1  51 11842.39845 4.673706e-62     * 0.9794078
## 3 study.goup:t   2  51    61.32947 2.696263e-14     * 0.3300412

Figures (intention to treat)

Main outcome

p=ggplot(aes(y = antral.volume, x = factor(t), fill=study.goup), data = bdpa) + geom_boxplot() 
p= p + labs(x = "Time in minutes", y = "Estimated antral volume in ml", colour = "Study group")
print(p)

p=ggplot(aes(y = antral.volume.ml.kg, x = factor(t), fill=study.goup), data = bdpa) + geom_boxplot() 
p= p + labs(x = "Time in minutes", y = "Estimated antral volume in ml/kg", colour = "Study group")
p=p+ geom_hline(yintercept = 1.5) + annotate("text", min(0), 1.5, vjust = -1, label = "                     1.5ml/kg")
p=p+ geom_hline(yintercept = 0.8) + 
    annotate("text", min(0), 0.8, vjust = -1, label = "                  0.8ml/kg")
print(p)

Fitted curves

p=ggplot(data = bdpa, aes(x = bdpa$t, y = bdpa$antral.volume, group = bdpa$id, color=bdpa$study.goup)) + labs(
    x = "Time in minutes",
    y = "Estimated antral volume in ml",
    colour = "Study group"
   )
p=p + stat_smooth(aes(group = bdpa$study.goup))
p=p+ theme(legend.background = element_rect(fill=rgb(1,1,1), size=0.5, linetype=2));
print(p)
## `geom_smooth()` using method = 'loess'

p=ggplot(data = bdpa, aes(x = bdpa$t, y = bdpa$antral.volume.ml.kg, group = bdpa$id, color=bdpa$study.goup)) + labs(
    x = "Time in minutes",
    y = "Estimated antral volume in ml/kg",
    colour = "Study group"
   )
p=p + stat_smooth(aes(group = bdpa$study.goup))
p=p+ geom_hline(yintercept = 1.5) + annotate("text", min(0), 1.5, vjust = -1, label = "    1.5ml/kg")
p=p+ geom_hline(yintercept = 0.8) + 
    annotate("text", min(0), 0.8, vjust = -1, label = "    0.8ml/kg")
p=p+ theme(legend.background = element_rect(fill=rgb(1,1,1), size=0.5, linetype=2));
print(p)
## `geom_smooth()` using method = 'loess'