报告corrplot()中的显着性水平 [英] Reporting significance level in corrplot()

查看:74
本文介绍了报告corrplot()中的显着性水平的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用R中corrplot包中的corrplot(),我偶然发现了两个问题.为简单起见,我将使用与Corrplot的帮助/介绍页面相同的符号.

I'm currently using corrplot() from the corrplot package in R and I've stumbled across two problems. For simplicity, I'll use the same notation as the help/introduction page for corrplot.

  1. 我想记录我的p值或该测试在所有单元格中的重要性(或两者!),而不仅仅是微不足道的那些.

  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.

我只希望上面的三角形中有这些铭文.

I'd like these inscriptions only in the upper triangular.

首先要解决2),我已经可以使用它了,但是如果感觉有点棘手:

To address 2) first, I've been able to use this, but if feels kind of 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"))

但是我仍然无法弄清楚数字1.任何建议都会有所帮助!

However I haven't been able to figure out number 1. Any suggestions would be helpful!

推荐答案

快速方法是将sig.level=0添加到第一个绘图中,因此将显示所有p值(实际上,由于数值精度,某些p值会完全为零,因此您可能需要将其设置为sig.level=-0.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)

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")

这给

但是,如果您想为p值添加更多细节,则可以更容易地对图形进行后格式设置并使用text调用添加它们

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

# 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")

给予

格式化功能

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

这篇关于报告corrplot()中的显着性水平的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆