knitr::opts_chunk$set(echo = TRUE)
library(openxlsx)
library(BayesFactor)
## Loading required package: coda
## Loading required package: Matrix
## ************
## Welcome to BayesFactor 0.9.12-4.2. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).
## 
## Type BFManual() to open the manual.
## ************
read.xlsx2 = function(bdata){
    bdata=read.xlsx(bdata)
    nv=length(bdata)
    ischar=rep(FALSE,nv)
    for(i in c(1:nv)){
        if(is.character(bdata[,i][0])){
            bdata[,i]=factor(bdata[,i])
        }
    }
    bdata
}

TwoByTwoBFc = function (x,y){
    a=sum(x & y,na.rm=TRUE)
    b=sum(x & !y,na.rm=TRUE)
    c=sum(!x & y,na.rm=TRUE)
    d=sum(!x & !y,na.rm=TRUE)
    table=as.matrix(data.frame(yes=c(a,c),no=c(b,d)))
    bf=extractBF(contingencyTableBF(table, sampleType = "indepMulti", fixedMargin = "cols"))[1]$bf
    rownames(table)=c("Intervention","Control")
    r1=a/(a+c)
    r2=b/(b+d)
    print(paste("Risco no grupo sim",r1))
    print(paste("Risco no grupo não",r2))
    print(paste("Risco relativo",r1/r2))
    print("Fator bayesiano:")
    print(bf)
    print("p-valor, teste exato de Fisher:")
    print(fisher.test(table)[1]$`p.value`)
    print(substitute(y))
    table
  }

Summary

This is a MARKDOWN file describing the data analysis of an experimental trial. Pigs were randomly allocated in two groups:

Bayes factors were calculated also for the main study hypothesis. Data Analysis contact information: gabriel@gabriel.med.br

Raw data

datafile="D:\\DataAnalysis\\Bastos2019\\Bastos2019.xlsx";
data=read.xlsx2(datafile)
data$weight=as.numeric(as.character(data$weight))
data
##    id  male weight Intervention return.circulation cpr.minutes
## 1   1 FALSE  24.45         TRUE              FALSE          28
## 2   2  TRUE  24.80        FALSE               TRUE          13
## 3   3 FALSE  26.00        FALSE               TRUE          14
## 4   4  TRUE  22.80         TRUE               TRUE          18
## 5   5 FALSE  28.20         TRUE              FALSE          30
## 6   6 FALSE  27.45        FALSE               TRUE          16
## 7   7  TRUE  28.00         TRUE              FALSE          30
## 8   8  TRUE  28.00        FALSE              FALSE          30
## 9   9 FALSE  31.10         TRUE              FALSE          30
## 10 10 FALSE  27.80        FALSE               TRUE          14
## 11 11  TRUE  26.00        FALSE               TRUE          16
## 12 12  TRUE  28.00         TRUE              FALSE          30
## 13 13 FALSE  31.00        FALSE              FALSE          30
## 14 14 FALSE  29.85         TRUE              FALSE          30
## 15 15  TRUE  32.00        FALSE               TRUE          19
## 16 16  TRUE  30.00         TRUE               TRUE          21
## 17 17 FALSE  27.00        FALSE               TRUE          17
## 18 18 FALSE  26.15         TRUE               TRUE          15
## 19 19  TRUE  29.00        FALSE              FALSE          30
## 20 20  TRUE  28.15         TRUE              FALSE          30
## 21 21 FALSE  25.60        FALSE              FALSE          30
## 22 22 FALSE  27.10         TRUE              FALSE          30
## 23 23  TRUE  27.85        FALSE              FALSE          30
## 24 24  TRUE  27.60         TRUE              FALSE          30
## 25 25 FALSE  24.00         TRUE              FALSE          30
## 26 26 FALSE  25.00        FALSE              FALSE          30
## 27 27  TRUE  24.30        FALSE              FALSE          30
## 28 28  TRUE  24.65         TRUE              FALSE          30
## 29 29 FALSE  27.35        FALSE              FALSE          30
## 30 30 FALSE  23.45         TRUE              FALSE          30
## 31 31  TRUE  27.05         TRUE              FALSE          30
## 32 32  TRUE  25.75        FALSE              FALSE          30
## 33 33 FALSE  28.00         TRUE              FALSE          30
##    epinephrine.doses survival.30d
## 1                  3        FALSE
## 2                  0         TRUE
## 3                  0         TRUE
## 4                  1        FALSE
## 5                  3        FALSE
## 6                  1         TRUE
## 7                  3        FALSE
## 8                  3        FALSE
## 9                  3        FALSE
## 10                 1         TRUE
## 11                 1         TRUE
## 12                 3        FALSE
## 13                 3        FALSE
## 14                 3        FALSE
## 15                 2        FALSE
## 16                 3        FALSE
## 17                 1        FALSE
## 18                 0        FALSE
## 19                 3        FALSE
## 20                 3        FALSE
## 21                 3        FALSE
## 22                 3        FALSE
## 23                 3        FALSE
## 24                 3        FALSE
## 25                 3        FALSE
## 26                 3        FALSE
## 27                 3        FALSE
## 28                 3        FALSE
## 29                 3        FALSE
## 30                 3        FALSE
## 31                 3        FALSE
## 32                 3        FALSE
## 33                 3        FALSE

Data summary

summary(data)
##        id        male             weight      Intervention   
##  Min.   : 1   Mode :logical   Min.   :22.80   Mode :logical  
##  1st Qu.: 9   FALSE:17        1st Qu.:25.60   FALSE:16       
##  Median :17   TRUE :16        Median :27.35   TRUE :17       
##  Mean   :17                   Mean   :27.07                  
##  3rd Qu.:25                   3rd Qu.:28.00                  
##  Max.   :33                   Max.   :32.00                  
##  return.circulation  cpr.minutes    epinephrine.doses survival.30d   
##  Mode :logical      Min.   :13.00   Min.   :0.000     Mode :logical  
##  FALSE:23           1st Qu.:19.00   1st Qu.:2.000     FALSE:28       
##  TRUE :10           Median :30.00   Median :3.000     TRUE :5        
##                     Mean   :25.79   Mean   :2.394                    
##                     3rd Qu.:30.00   3rd Qu.:3.000                    
##                     Max.   :30.00   Max.   :3.000

Hypothesis testing

TwoByTwoBFc(data$return.circulation,data$Intervention)
## [1] "Risco no grupo sim 0.176470588235294"
## [1] "Risco no grupo não 0.4375"
## [1] "Risco relativo 0.403361344537815"
## [1] "Fator bayesiano:"
## [1] 1.322059
## [1] "p-valor, teste exato de Fisher:"
## [1] 0.1410703
## data$Intervention
##              yes no
## Intervention   3  7
## Control       14  9
TwoByTwoBFc(data$survival.30d,data$Intervention)
## [1] "Risco no grupo sim 0"
## [1] "Risco no grupo não 0.3125"
## [1] "Risco relativo 0"
## [1] "Fator bayesiano:"
## [1] 6.037241
## [1] "p-valor, teste exato de Fisher:"
## [1] 0.01840429
## data$Intervention
##              yes no
## Intervention   0  5
## Control       17 11
TwoByTwoBFc(data$survival.30d,data$male)
## [1] "Risco no grupo sim 0.125"
## [1] "Risco no grupo não 0.176470588235294"
## [1] "Risco relativo 0.708333333333333"
## [1] "Fator bayesiano:"
## [1] 0.3231699
## [1] "p-valor, teste exato de Fisher:"
## [1] 1
## data$male
##              yes no
## Intervention   2  3
## Control       14 14
wilcox.test(data$weight~data$survival.30d)
## Warning in wilcox.test.default(x = c(24.45, 22.8, 28.2, 28, 28, 31.1, 28, :
## cannot compute exact p-value with ties
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  data$weight by data$survival.30d
## W = 87, p-value = 0.407
## alternative hypothesis: true location shift is not equal to 0

CPR minutes

boxplot(data$cpr.minutes~data$survival.30d)

boxplot(data$cpr.minutes~data$return.circulation)

Epidephrine doses

table(data$epinephrine.doses,data$return.circulation)
##    
##     FALSE TRUE
##   0     0    3
##   1     0    5
##   2     0    1
##   3    23    1
wilcox.test(data$epinephrine.doses~data$return.circulation)
## Warning in wilcox.test.default(x = c(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, :
## cannot compute exact p-value with ties
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  data$epinephrine.doses by data$return.circulation
## W = 218.5, p-value = 2.48e-07
## alternative hypothesis: true location shift is not equal to 0
table(data$epinephrine.doses,data$survival.30d)
##    
##     FALSE TRUE
##   0     1    2
##   1     2    3
##   2     1    0
##   3    24    0
wilcox.test(data$epinephrine.doses~data$survival.30d)
## Warning in wilcox.test.default(x = c(3, 1, 3, 3, 3, 3, 3, 3, 3, 2, 3, 1, :
## cannot compute exact p-value with ties
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  data$epinephrine.doses by data$survival.30d
## W = 133, p-value = 6.006e-05
## alternative hypothesis: true location shift is not equal to 0

If no return of spontaneous circulation before third dose, there was a remote (4%) chance of survival (p=0.0000024) and no chance of 30-day survival (p=0.00006).

30-Day survival proportion by number of needed epinephrine doses from 0 to 3: 66.6%, 60%, 0, 0.