rcorr_tidiers {broom} | R Documentation |
Tidies a correlation matrix from the rcorr
function in the
"Hmisc" package, including correlation estimates, p-values,
and the number of observations in each pairwise correlation.
Note that it returns these in "long", or "melted", format,
with one row for each pair of columns being compared.
## S3 method for class 'rcorr' tidy(x, diagonal = FALSE, ...)
x |
An object of class "rcorr" |
diagonal |
Whether to include diagonal elements (where
|
... |
extra arguments (not used) |
Only half the symmetric matrix is shown.
A data.frame with one row for each pairing in the correlation matrix. Columns are:
column1 |
Name or index of the first column being described |
column2 |
Name or index of the second column being described |
estimate |
Estimate of Pearson's r or Spearman's rho |
n |
Number of observations used to compute the correlation |
p.value |
P-value of correlation |
if (require("Hmisc", quietly = TRUE)) { mat <- replicate(52, rnorm(100)) # add some NAs mat[sample(length(mat), 2000)] <- NA # also column names colnames(mat) <- c(LETTERS, letters) rc <- rcorr(mat) td <- tidy(rc) head(td) library(ggplot2) ggplot(td, aes(p.value)) + geom_histogram(binwidth = .1) ggplot(td, aes(estimate, p.value)) + geom_point() + scale_y_log10() }