rcorr_tidiers {broom} | R Documentation

## Tidying methods for rcorr objects

### Description

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.

### Usage

    ## S3 method for class 'rcorr'
    tidy(x, diagonal = FALSE, ...)

### Arguments

`x` | An object of class "rcorr"
`diagonal` | Whether to include diagonal elements (where `estimate` is 1 and `p.value` is NA), default FALSE
`...` | extra arguments (not used)

### Details

Only half the symmetric matrix is shown.

### Value

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

### Examples

    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()
    }

[Package broom version 0.4.1 Index]