getwd()
## [1] "/Users/alice"
#Loading Data
df = read_excel("cheenu.xlsx")


#Adding My Own Column Titles
names(df) <- c("MRN", "Fracture_XR_Rad_1", "Fracture_MRI_Rad_1", "Fracture_Both_Rad_1", "Fracture_XR_Rad_2", "Fracture_MRI_Rad_2", "Fracture_Both_Rad_2", "Fracture_CT", "ICH_MRI_Rad_1", "ICH_MRI_Rad_2", "ICH_CT", "Scalp_MRI_Rads_1", "Scalp_MRI_Rads_2", "Scalp_CT")
#phi coefficient by pearson correlation
m <- cor(df[,2:8])
m2 <- cor(df[,9:14])

corrplot(m, method = 'number' )

corrplot(m2, method ="number")

#mcnemar testing

#Skull fracture found on x-ray vs MRI (Radiologist 1)
cross_cases(df, Fracture_XR_Rad_1, Fracture_MRI_Rad_1)
 Fracture_MRI_Rad_1 
 0   1 
 Fracture_XR_Rad_1 
   0  14
   1  4 6
   #Total cases  18 6
table(df$Fracture_XR_Rad_1,df$Fracture_MRI_Rad_1)
##    
##      0  1
##   0 14  0
##   1  4  6
mcnemar.test(table(df$Fracture_XR_Rad_1,df$Fracture_MRI_Rad_1))
## 
##  McNemar's Chi-squared test with continuity correction
## 
## data:  table(df$Fracture_XR_Rad_1, df$Fracture_MRI_Rad_1)
## McNemar's chi-squared = 2.25, df = 1, p-value = 0.1336
#Skull fracture found on x-ray vs MRI (Radiologist 2)
cross_cases(df, Fracture_XR_Rad_2, Fracture_MRI_Rad_2)
 Fracture_MRI_Rad_2 
 0   1 
 Fracture_XR_Rad_2 
   0  14 1
   1  4 5
   #Total cases  18 6
table(df$Fracture_XR_Rad_2, df$Fracture_MRI_Rad_2)
##    
##      0  1
##   0 14  1
##   1  4  5
mcnemar.test(table(df$Fracture_XR_Rad_2, df$Fracture_MRI_Rad_2))
## 
##  McNemar's Chi-squared test with continuity correction
## 
## data:  table(df$Fracture_XR_Rad_2, df$Fracture_MRI_Rad_2)
## McNemar's chi-squared = 0.8, df = 1, p-value = 0.3711
#Skull fracture found on x-ray vs CT (Radiologist 1)
table(df$Fracture_XR_Rad_1, df$Fracture_CT)
##    
##      0  1
##   0 12  2
##   1  0 10
mcnemar.test(table(df$Fracture_XR_Rad_1, df$Fracture_CT))
## 
##  McNemar's Chi-squared test with continuity correction
## 
## data:  table(df$Fracture_XR_Rad_1, df$Fracture_CT)
## McNemar's chi-squared = 0.5, df = 1, p-value = 0.4795
#Skull fracture found on x-ray vs CT (Radiologist 2)
table(df$Fracture_XR_Rad_2, df$Fracture_CT)
##    
##      0  1
##   0 12  3
##   1  0  9
mcnemar.test(table(df$Fracture_XR_Rad_2, df$Fracture_CT))
## 
##  McNemar's Chi-squared test with continuity correction
## 
## data:  table(df$Fracture_XR_Rad_2, df$Fracture_CT)
## McNemar's chi-squared = 1.3333, df = 1, p-value = 0.2482
#mcnemar testing

#Skull fracture found on x-ray + MRI vs CT (Radiologist 1)
cross_cases(df, Fracture_Both_Rad_1, Fracture_CT)
 Fracture_CT 
 0   1 
 Fracture_Both_Rad_1 
   0  12 2
   1  10
   #Total cases  12 12
table(df$Fracture_Both_Rad_1,df$Fracture_CT)
##    
##      0  1
##   0 12  2
##   1  0 10
mcnemar.test(table(df$Fracture_Both_Rad_1,df$Fracture_CT))
## 
##  McNemar's Chi-squared test with continuity correction
## 
## data:  table(df$Fracture_Both_Rad_1, df$Fracture_CT)
## McNemar's chi-squared = 0.5, df = 1, p-value = 0.4795
#Skull fracture found on x-ray + MRI vs CT (Radiologist 2)
cross_cases(df, Fracture_Both_Rad_2, Fracture_CT)
 Fracture_CT 
 0   1 
 Fracture_Both_Rad_2 
   0  12 2
   1  10
   #Total cases  12 12
table(df$Fracture_Both_Rad_2,df$Fracture_CT)
##    
##      0  1
##   0 12  2
##   1  0 10
mcnemar.test(table(df$Fracture_Both_Rad_2,df$Fracture_CT))
## 
##  McNemar's Chi-squared test with continuity correction
## 
## data:  table(df$Fracture_Both_Rad_2, df$Fracture_CT)
## McNemar's chi-squared = 0.5, df = 1, p-value = 0.4795
#ICH found on MRI vs CT (Radiologist 1)
cross_cases(df, ICH_MRI_Rad_1, ICH_CT)
 ICH_CT 
 0   1 
 ICH_MRI_Rad_1 
   0  6 1
   1  2 15
   #Total cases  8 16
table(df$ICH_MRI_Rad_1,df$ICH_CT)
##    
##      0  1
##   0  6  1
##   1  2 15
mcnemar.test(table(df$ICH_MRI_Rad_1,df$ICH_CT))
## 
##  McNemar's Chi-squared test with continuity correction
## 
## data:  table(df$ICH_MRI_Rad_1, df$ICH_CT)
## McNemar's chi-squared = 0, df = 1, p-value = 1
#ICH found on MRI vs CT (Radiologist 2)
cross_cases(df, ICH_MRI_Rad_2, ICH_CT)
 ICH_CT 
 0   1 
 ICH_MRI_Rad_2 
   0  4 1
   1  4 15
   #Total cases  8 16
table(df$ICH_MRI_Rad_2,df$ICH_CT)
##    
##      0  1
##   0  4  1
##   1  4 15
mcnemar.test(table(df$ICH_MRI_Rad_2,df$ICH_CT))
## 
##  McNemar's Chi-squared test with continuity correction
## 
## data:  table(df$ICH_MRI_Rad_2, df$ICH_CT)
## McNemar's chi-squared = 0.8, df = 1, p-value = 0.3711
#Incidence of skull fractures on CT compared to scalp hematomas present on MRI
cor(df$Fracture_CT,df$Scalp_MRI_Rads_1)
## [1] 0.7745967
cor(df$Fracture_CT,df$Scalp_MRI_Rads_2)
## [1] 0.5303301
mcnemar.test(table(df$Fracture_CT,df$Scalp_MRI_Rads_1))
## 
##  McNemar's Chi-squared test with continuity correction
## 
## data:  table(df$Fracture_CT, df$Scalp_MRI_Rads_1)
## McNemar's chi-squared = 1.3333, df = 1, p-value = 0.2482
mcnemar.test(table(df$Fracture_CT,df$Scalp_MRI_Rads_2))
## 
##  McNemar's Chi-squared test with continuity correction
## 
## data:  table(df$Fracture_CT, df$Scalp_MRI_Rads_2)
## McNemar's chi-squared = 1.5, df = 1, p-value = 0.2207
#How many MRIs with scalp hematomas had a detected skull fracture?
MRI_hemotoma_fracture1 <- subset(df, Fracture_CT==1 & Scalp_MRI_Rads_1==1)
MRI_hemotoma_fracture2 <- subset(df, Fracture_CT==1 & Scalp_MRI_Rads_2==1)

MRI_ht_fracture1 <- nrow(MRI_hemotoma_fracture1)
MRI_ht_fracture2 <- nrow(MRI_hemotoma_fracture2)

MRI_ht_fracture1 #9 cases for rad 1
## [1] 9
MRI_ht_fracture2 #7 cases for rad 2
## [1] 7
#How many skull fractures on CT were associated with a scalp hematoma?
cor(df$Fracture_CT,df$Scalp_CT)
## [1] 0.5129892
hemotoma_fracture <- subset(df, Fracture_CT==1 & Scalp_CT==1)
ht_with_detected_fracture <- nrow(hemotoma_fracture)

#percentage of scalp hemotomas that also had detected skull fracture ( = 5/5)
ht_with_detected_fracture/sum(df$Scalp_CT)
## [1] 1
#sum(df$Fracture_CT) #12 total CT skull fractures
#sum(df$Scalp_CT) #5 total CT scalp hemotoma 
#every case of hemotoma had a skull fracture.