How can I get R to generate p-value when doing a correlation matrix?

CrunchAndSee

New Member
How can I get R to generate p-value for each correlation when doing a correlation matrix?

Here are my current steps:

Code:
> M <- cor(data1)                          # get correlations into Matrix
> library('corrplot')                  # import corrplot library
> corrplot(M, method = "circle")       # circle, ellipse, number, color, pie

TheEcologist

Global Moderator
The shortest way of doing this is by using the package Hmisc:
Code:
require(Hmisc)
## Assuming you only have numeric values in your data
cortests <- rcorr(as.matrix(data1), type="pearson")
Use cortest$r for the correlation matrix and cortest$p to get a matrix with p-values.

As you do multiple comparisons here, note that a significant p-value must be Bonferroni corrected (or it's equivalent): significance p = 0.05 / number of tests.

Good luck,