Reporting significance level in corrplot()

◇◆丶佛笑我妖孽 提交于 2019-11-29 12:24:48

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

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

# 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!