library("metan")
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
## |=========================================================|
## | Multi-Environment Trial Analysis (metan) v1.18.0        |
## | Author: Tiago Olivoto                                   |
## | Type 'citation('metan')' to know how to cite metan      |
## | Type 'vignette('metan_start')' for a short tutorial     |
## | Visit 'https://bit.ly/pkgmetan' for a complete tutorial |
## |=========================================================|
library("ggplot2")
library("ggpubr")
library("cowplot")
## 
## Attaching package: 'cowplot'
## The following object is masked from 'package:ggpubr':
## 
##     get_legend
library("metan")

validity <- read.csv("/home/mchopra/Documents/PhD-Year1/results_imaging/validation_run_only/validation.csv")
#validity_clean <- na.omit(validity)
validity[1:2, 1:6]
##   their_eid my_eids their_aao    my_aao their_dao    my_dao
## 1   1000213 2859809 1.3929732 1.1368660 1.6834230 1.3739147
## 2   1000232 2082542 0.6606607 0.6606607 0.8736009 0.8736009
#scatterplot
#scatterplot in between the Ascending distensibilities
sp1 <- ggplot(data = validity, aes(x = their_aao, y = my_aao)) + geom_point() + theme_cowplot()

#scatterplot in between the Descending distensibilities
sp2 <- ggplot(data = validity, aes(x = their_dao, y = my_dao)) + geom_point() + theme_cowplot()

plot_grid(sp1, sp2, labels = c('AAo', 'DAo')) 

#ggsave("mehakVSwbai.png", plot = r, device = "png")
aao <- cor.test(validity$their_aao, validity$my_aao, method = c("pearson", "kendall", "spearman"))
aao
## 
##  Pearson's product-moment correlation
## 
## data:  validity$their_aao and validity$my_aao
## t = 688.32, df = 22893, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.9760770 0.9772713
## sample estimates:
##       cor 
## 0.9766817
dao <- cor.test(validity$their_dao, validity$my_dao, method = c("pearson", "kendall", "spearman"))
dao
## 
##  Pearson's product-moment correlation
## 
## data:  validity$their_dao and validity$my_dao
## t = 631.01, df = 22893, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.9717219 0.9731307
## sample estimates:
##       cor 
## 0.9724352

##The reason why it is not 1 is because i used more values to calculate mean comparative to their study.

#Total number of common samples = 22,938
corr_data = validity %>%
select("their_aao", "my_aao", "their_dao", "my_dao")

overall_corr <- corr_coef(
  corr_data,
  use = c("pairwise.complete.obs")
)

overall_corr
## ---------------------------------------------------------------------------
## Pearson's correlation coefficient
## ---------------------------------------------------------------------------
##           their_aao my_aao their_dao my_dao
## their_aao     1.000  0.977     0.834  0.811
## my_aao        0.977  1.000     0.806  0.831
## their_dao     0.834  0.806     1.000  0.972
## my_dao        0.811  0.831     0.972  1.000
## ---------------------------------------------------------------------------
## p-values for the correlation coefficients
## ---------------------------------------------------------------------------
##           their_aao my_aao their_dao my_dao
## their_aao         0      0         0      0
## my_aao            0      0         0      0
## their_dao         0      0         0      0
## my_dao            0      0         0      0
plot(overall_corr)

library(corrplot)
## corrplot 0.92 loaded
res <- cor(validity)
round(res,2)
##           their_eid my_eids their_aao my_aao their_dao my_dao
## their_eid      1.00   -0.01      0.00   0.00      0.01   0.01
## my_eids       -0.01    1.00      0.00   0.00      0.00   0.00
## their_aao      0.00    0.00      1.00   0.98      0.83   0.81
## my_aao         0.00    0.00      0.98   1.00      0.81   0.83
## their_dao      0.01    0.00      0.83   0.81      1.00   0.97
## my_dao         0.01    0.00      0.81   0.83      0.97   1.00
cor(validity, use = "complete.obs")
##              their_eid      my_eids   their_aao      my_aao   their_dao
## their_eid  1.000000000 -0.007388752 0.003730941 0.003625228 0.005968000
## my_eids   -0.007388752  1.000000000 0.001105821 0.001069433 0.002425072
## their_aao  0.003730941  0.001105821 1.000000000 0.976681743 0.833738015
## my_aao     0.003625228  0.001069433 0.976681743 1.000000000 0.806212493
## their_dao  0.005968000  0.002425072 0.833738015 0.806212493 1.000000000
## my_dao     0.006116301  0.002779365 0.811035291 0.830640894 0.972435161
##                my_dao
## their_eid 0.006116301
## my_eids   0.002779365
## their_aao 0.811035291
## my_aao    0.830640894
## their_dao 0.972435161
## my_dao    1.000000000
# Create the basic correlation plot with correlation values displayed
corr_plot <- corrplot(res, type = "upper", order = "hclust", tl.col = "black", tl.srt = 45, addCoef.col = "white", number.cex = 1.0)