简体   繁体   中英

Two different p-values for one variable combination? corrplot::corrplot

I woult like to corrplot my data (the package I use, surprise surprise, is {corrplot}) and display the p-values of the pairwise correlations in it.

Now I found some useful stuff here on how to do exactly that and at first glance, it went surprisingly well. But then I noticed that the p-values were completely strange and they didn't correspond to the actual p-values from cor.test().

I already found out (using exemplary data) that it's not due to my data, but something I got wrong about the code with which I'm trying to include the p-values.

So here's a reproducible example:

#using built-in r-data:
data("mtcars")

#now for the corrplot:
M = cor(mtcars, use="complete.obs")
pval <- corr.test(M, adjust="none")$p
corrplot(M, method = "color", type = "upper", 
     order = "original", tl.col = "black", tl.srt = 45,
     family="serif", p.mat=pval, insig="p-value", sig.level=0)

This is what I get:

(didn't let me upload the file, so you have to click the link...)

Anyway, to illustrate that these are not the actual p-values, let's take juts one pair, namely "qsec" and "drat":

cor.test(mtcars$qsec, mtcars$drat, use="complete.obs")

And the resulting p-value ("p-value = 0.6196") is definitely not the one you see in the corrplot ("0.14").

This is probably really stupid and I'm sure (p<.0001) that I'm overlooking something - but I don't know what it is. Help?

By using corr.test(M, adjust="none") you're passing the matrix M into the function. And matrix M is something different than the data you have. Try to use corr.test(mtcars, adjust="none") instead. You need to pass your actual dataset and not a matrix of correlations.

If you check how data.frame(M) looks like you'll see that your drat variable has 11 values and those are the correlations of drat and the rest of the variables. However, you want drat to be the drat column from mtcars with 32 values.

You can pass the correlation matrix M to the corrplot function, but not in the corr.test function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM