[英]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. 我想校正我的数据(我使用的包,令人惊讶的是{corrplot}),并在其中显示成对相关的p值。
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().
但是后来我注意到,p值完全奇怪,它们与cor.test()中的实际p值不对应。
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. 我已经发现(使用示例性数据)不是由于我的数据,而是我尝试包含p值的代码出了点问题。
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": 无论如何,为了说明这些不是实际的p值,让我们举个对,即“ qsec”和“ 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"). 而且,所得的p值(“ p值= 0.6196”)绝对不是您在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. 这可能真是愚蠢,我确定(p <.0001)我正在忽略某些内容-但我不知道它是什么。 Help?
救命?
By using corr.test(M, adjust="none")
you're passing the matrix M
into the function. 通过使用
corr.test(M, adjust="none")
您可以将矩阵M
传递给函数。 And matrix M
is something different than the data you have. 矩阵
M
与您拥有的数据有所不同。 Try to use corr.test(mtcars, adjust="none")
instead. 尝试改用
corr.test(mtcars, adjust="none")
。 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. 如果检查有
data.frame(M)
的样子,你会看到你的drat
变量有11个值,而这些都是的相关drat
和变量的其余部分。 However, you want drat
to be the drat
column from mtcars
with 32 values. 但是,你要
drat
是drat
从柱mtcars
有32个值。
You can pass the correlation matrix M
to the corrplot
function, but not in the corr.test
function. 您可以将相关矩阵
M
传递给corrplot
函数,但不能corr.test
给corr.test
函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.