R - Combine cor.mtest and p.adjust

Is there a way to account for multiple p-value comparisons (like p.adjust) using this cor.mtest function? Code from http://cran.r-project.org/web/packages/corrplot/vignettes/corrplot-intro.html

Thank!

cors<-cor(rel_tnum_data)
cor.mtest <- function(mat, conf.level = 0.95) {
mat <- as.matrix(mat)
n <- ncol(mat)
p.mat <- lowCI.mat <- uppCI.mat <- matrix(NA, n, n)
diag(p.mat) <- 0
diag(lowCI.mat) <- diag(uppCI.mat) <- 1
for (i in 1:(n - 1)) {
    for (j in (i + 1):n) {
        tmp <- cor.test(mat[, i], mat[, j], conf.level = conf.level)
        p.mat[i, j] <- p.mat[j, i] <- tmp$p.value
        lowCI.mat[i, j] <- lowCI.mat[j, i] <- tmp$conf.int[1]
        uppCI.mat[i, j] <- uppCI.mat[j, i] <- tmp$conf.int[2]
    }
}
return(list(p.mat, lowCI.mat, uppCI.mat))
}
res1 <- cor.mtest(rel_tnum_data, 0.95)
res2 <- cor.mtest(rel_tnum_data, 0.99)
corrplot(cors, p.mat = res1[[1]], sig.level=0.05, insig="blank", cl.align="r", tl.cex=0.6, order="hclust", type="lower", tl.srt=60, cl.ratio=0.1)

      

+3


source to share


1 answer


You can vectorize your matrix of p values โ€‹โ€‹(like res1) that was returned by the function cor.mtest

. Subsequently, the function p.adjust

will help you get the adjusted p values.

pAdj <- p.adjust(c(res1[[1]]), method = "BH")

      

Then create the original matrix with the p-values โ€‹โ€‹set.

resAdj <- matrix(pAdj, ncol = dim(res1[[1]])[1])

      



Then you corrplot

should be ready to create your graph with the p-values โ€‹โ€‹set.

corrplot(cors, p.mat = resAdj, sig.level=0.05, insig="blank", cl.align="r", tl.cex=0.6, order="hclust", type="lower", tl.srt=60, cl.ratio=0.1)

      

Please note that p.mat = resAdj

.

+1


source







All Articles