[英]Add p-values in corrplot matrix
I calculated the Spearman correlation between two matrices and I'm plotting the r values using corrplot
. 我计算了两个矩阵之间的Spearman相关性,并使用corrplot
绘制了r值。 How can I plot only the significant correlations (so only those correlations having p value lower than 0.00 and delete those having higher p value, even if are strong correlations - high value of r). 我如何仅绘制显着的相关性(因此,即使p值小于0.00的那些相关性,即使是强相关性-r的高值,也仅删除那些具有较高p值的相关性)。 I generated the correlation matrix using corr.test
in psych
package, so I already have the p values in cor.matrix$p
我在psych
软件包中使用corr.test
生成了相关矩阵,所以我在cor.matrix$p
已经有了p值
This is the code I'm using: 这是我正在使用的代码:
library(corrplot)
library(psych)
corr.test(mydata_t1, mydata_t2, method="spearman")
M <- corrplot(cor.matrix$r, method="square",type="lower",col=col1(100),is.corr=T,mar=c(1,1,1,1),tl.cex=0.5)
How can I modify it to plot only significant corelations? 如何修改它以仅显示重要的关联?
Take a look at the examples of corrplot. 看一下corrplot的示例。 do ?corrplot
. 做?corrplot
。 It has options for doing what you want. 它具有执行所需功能的选项。 You can plot the p-values on the graph itself, which I think is better than putting stars, as people not familiar with that terminology have one more thing to look up. 您可以在图表本身上绘制p值,我认为这比放星星好,因为不熟悉该术语的人还有更多需要查找的内容。 to put p-values on graph do this corrplot(cor.matrix$r, p.mat = cor.matrix$p, insig = "p-value")
where cor.matrix is object holding the result of cor.test. 将p值放在图上,请执行以下corrplot(cor.matrix$r, p.mat = cor.matrix$p, insig = "p-value")
,其中cor.matrix是持有cor.test结果的对象。 The insig
option can put: insig
选项可以放入:
corrplot(cor.matrix$r, p.mat = cor.matrix$p, insig = "pch")
(DEFAULT) 使用选项corrplot(cor.matrix$r, p.mat = cor.matrix$p, insig = "pch")
在不相关的关系上加上X corrplot(cor.matrix$r, p.mat = cor.matrix$p, insig = "pch")
(默认) corrplot(cor.matrix$r, p.mat = cor.matrix$p, insig = "n")
使用corrplot(cor.matrix$r, p.mat = cor.matrix$p, insig = "n")
对图不执行任何操作 If you do want stars, p-value on the correlation matrix plot - take a look at this thread Correlation Corrplot Configuration 如果您确实想要星星,请在相关矩阵图上显示p值-查看此线程Correlation Corrplot Configuration
Though I have to say I really like @sven hohenstein's elegant subset solution. 虽然我不得不说我真的很喜欢@sven hohenstein的优雅子集解决方案。
Create a copy of cor.mat
and replace the corresponding correlation coefficients with zero: 创建cor.mat
的副本并将相应的相关系数替换为零:
cor.matrix2 <- cor.matrix
# find cells with p-values > 0.05 and replace corresponding
# correlations coefficients with zero
cor.matrix2$r[cor.matrix2$p > 0.05] <- 0
# use this matrix for corrplot
M <- corrplot(cor.matrix2$r, method="square",type="lower",col=col1(100),
is.corr=T,mar=c(1,1,1,1),tl.cex=0.5)
The replaced values will appear as a white cell. 替换的值将显示为白色单元格。
What you are asking is similar to what subset
does: 您要问的内容类似于subset
作用:
Return subsets of vectors, matrices or data frames which meet conditions. 返回满足条件的向量,矩阵或数据帧的子集。
So you can do: 因此,您可以执行以下操作:
cor.matrix <- subset(cor.matrix, p<0.00)
P <- corrplot(cor.matrix$r, method="square",type="lower",col=col1(100),is.corr=T,mar=c(1,1,1,1),tl.cex=0.5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.