Last chance! 50% off unlimited learning
Sale ends in
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 rcorr
tidy(x, diagonal = FALSE, ...)
An object of class "rcorr"
Whether to include diagonal elements (where
estimate
is 1 and p.value
is NA), default FALSE
extra arguments (not used)
A data.frame with one row for each pairing in the correlation matrix. Columns are:
Name or index of the first column being described
Name or index of the second column being described
Estimate of Pearson's r or Spearman's rho
Number of observations used to compute the correlation
P-value of correlation
Only half the symmetric matrix is shown.
# NOT RUN {
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()
}
# }
Run the code above in your browser using DataLab