How to compute exact P-values for a small data set for Kendall Correlation Matrix and implement it in the corr plot?
1
0
Entering edit mode
3.0 years ago

I am trying to create a corr plot for a Kendall correlation matrix of sample size 30. But I want to compute the exact P-values ( with no ties). Also, implement it in the corr plot for visualization purposes. I would like to find statistically significant correlation values.

Corr Biostatistics Statistics R • 2.2k views
ADD COMMENT
0
Entering edit mode

What have you tried? Please show us your code at least a small but representative sample of your data

ADD REPLY
0
Entering edit mode
# mat : is a matrix of data
# ... : further arguments to pass to the native R cor.test function
# calculates P but says "cannot calculate exact P value with ties

cor.mtest <- function(mat, ...) {
    mat <- as.matrix(mat)
    n <- ncol(mat)
    p.mat<- matrix(NA, n, n)
    diag(p.mat) <- 0
    for (i in 1:(n - 1)) {
        for (j in (i + 1):n) {
            tmp <- cor.test(mat[, i], mat[, j], ...)
            p.mat[i, j] <- p.mat[j, i] <- tmp$p.value
        }
    }
  colnames(p.mat) <- rownames(p.mat) <- colnames(mat)
  p.mat
}

p.mat <- cor.mtest(my_data , method="kendall")
head(p.mat[, 1:5])


#The corr plot and adding the P values to it 
M<-cor(my_data , method="kendall")
head(round(M,2))
png(height=3000, width=3000, pointsize=15, file="kendallcor_real_P_6.png")
corrplot(M, addCoef.col="black" , number.cex = 1.5, tl.cex = 2.5 , order = "AOE",p.mat=p.mat,sig.level = 0.05 )
ADD REPLY
0
Entering edit mode

I will specify the code I used to get P-values for the Kendall Correlation test in R, but the code cannot compute exact P-values with ties which I would like to improve

cor.mtest <- function(mat, ...) {
    mat <- as.matrix(mat)
    n <- ncol(mat)
    p.mat<- matrix(NA, n, n)
    diag(p.mat) <- 0
    for (i in 1:(n - 1)) {
        for (j in (i + 1):n) {
            tmp <- cor.test(mat[, i], mat[, j], ...)
            p.mat[i, j] <- p.mat[j, i] <- tmp$p.value
        }
    }
    colnames(p.mat) <- rownames(p.mat) <- colnames(mat)
    p.mat
}

# matrix of the p-value of the correlation
p.mat <- cor.mtest(my_data , method="kendall")

head(p.mat[, 1:5])

mat : is a matrix of data
... : further arguments to pass to the native R cor.test function

Is there any other methods where I can find the ties corrected P-values for Kendall's Correlation test and implement it in Corr Plot?

ADD REPLY
0
Entering edit mode
3.0 years ago
Ram 43k

This cor.mtest function calls cor.test which has a parameter called exact which computes exact p values. You can change your cor.mtest call like so:

p.mat <- cor.mtest(my_data, method = 'kendall', exact = TRUE)

Once you have that, you should be able to pass the matrix of correlation values and p.mat as the p-value matrix to corrplot.

ADD COMMENT

Login before adding your answer.

Traffic: 1924 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6