简体   繁体   English

在 corrplot() 中报告显着性水平

[英]Reporting significance level in corrplot()

I'm currently using corrplot() from the corrplot package in R and I've stumbled across two problems.我目前正在使用 R 中corrplot包中的corrplot() ,我偶然发现了两个问题。 For simplicity, I'll use the same notation as the help/introduction page for corrplot.为简单起见,我将使用与 corrplot 的帮助/介绍页面相同的符号。

  1. I'd like to inscribe either my p-value or how significant the test was (or both!) in all cells, not just the insignificant ones.我想在所有单元格中记录我的 p 值或测试的重要性(或两者都有!),而不仅仅是无关紧要的单元格。

  2. I'd like these inscriptions only in the upper triangular.我只想要上三角形的这些铭文。

To address 2) first, I've been able to use this, but if feels kind of hacky:要解决 2) 首先,我已经能够使用它,但如果感觉有点 hacky:

corrplot(M, type="upper", p.mat = res1[[1]], insig="p-value", tl.pos="n")
corrplot(M, type="lower", add=T, tl.pos="d", cl.pos="n"))

However I haven't been able to figure out number 1. Any suggestions would be helpful!但是我一直无法弄清楚数字 1。任何建议都会有所帮助!

The quick way is to add sig.level=0 to the first plot, so all p-values are shown (actually, due to numerical precision some p-values will be exactly zero, so you may need to set it to sig.level=-0.1 , for example)快速的方法是将sig.level=0添加到第一个图中,因此显示所有 p 值(实际上,由于数值精度,一些 p 值将完全为零,因此您可能需要将其设置为sig.level=-0.1 ,例如)

require(corrplot)

# Data
M <- mtcars[3:7]
pval <- psych::corr.test(M, adjust="none")$p

# Corrplot
corrplot(cor(M), type="upper", p.mat=pval, insig="p-value", 
                                               tl.pos="n", sig.level=0)
corrplot(cor(M), type="lower", add=T, tl.pos="d", cl.pos="n")

This gives这给

在此处输入图像描述

However, if you want to add more detail to the p values it is probably easier to post-format the plot and add them using a text call但是,如果您想为 p 值添加更多细节,则可能更容易对绘图进行后期格式化并使用text调用添加它们

# Plot
corrplot(cor(M), type="upper", tl.pos="n")

# Get positions & plot formatted p-values
pos <- expand.grid(1:ncol(pval), ncol(pval):1)
text(pos, p_format(pval))

# lower tri
corrplot(cor(M), type="lower", add=T, tl.pos="d", cl.pos="n")

To give给予

在此处输入图像描述

Format function格式功能

p_format <- function(x, ndp=3)
{
  out <- format(round(as.numeric(x),ndp),ns=ndp,scientific=F,just="none")
  ifelse(out=="0.000","<0.0001", out)
}

My view (fwiw) is that this is adding too much info to the plot我的观点(fwiw)是这给情节添加了太多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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