我想对我的数据进行更新(我使用的包,惊喜,是{corrplot})并显示成对相关的p值。
现在我发现了一些有用的东西here如何做到这一点,乍一看,它出奇的好。但后来我注意到p值完全是奇怪的,它们与cor.test()的实际p值并不对应。
我已经发现(使用示例性数据)它不是由于我的数据,但是我错误地认为我试图包含p值的代码。
所以这是一个可重复的例子:
#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)
这就是我得到的:
(didn't let me upload the file, so you have to click the link...)
无论如何,为了说明这些不是实际的p值,让我们选择一对,即&#34; qsec&#34;和&#34; drat&#34;:
cor.test(mtcars$qsec, mtcars$drat, use="complete.obs")
得到的p值(&#34; p值= 0.6196&#34;)绝对不是你在corrplot中看到的那个(&#34; 0.14&#34;)。
这可能真的很愚蠢,我确定(p <.0001)我忽略了一些东西 - 但我不知道它是什么。帮助
答案 0 :(得分:0)
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.