# rcorr: Matrix of Correlations and P-values In Hmisc: Harrell Miscellaneous

## Description

`rcorr` Computes a matrix of Pearson's `r` or Spearman's `rho` rank correlation coefficients for all possible pairs of columns of a matrix. Missing values are deleted in pairs rather than deleting all rows of `x` having any missing variables. Ranks are computed using efficient algorithms (see reference 2), using midranks for ties.

## Usage

 ```1 2 3 4``` ```rcorr(x, y, type=c("pearson","spearman")) ## S3 method for class 'rcorr' print(x, ...) ```

## Arguments

 `x` a numeric matrix with at least 5 rows and at least 2 columns (if `y` is absent). For `print`, `x` is an object produced by `rcorr`. `y` a numeric vector or matrix which will be concatenated to `x`. If `y` is omitted for `rcorr`, `x` must be a matrix. `type` specifies the type of correlations to compute. Spearman correlations are the Pearson linear correlations computed on the ranks of non-missing elements, using midranks for ties. `...` argument for method compatiblity.

## Details

Uses midranks in case of ties, as described by Hollander and Wolfe. P-values are approximated by using the `t` or `F` distributions.

## Value

`rcorr` returns a list with elements `r`, the matrix of correlations, `n` the matrix of number of observations used in analyzing each pair of variables, and `P`, the asymptotic P-values. Pairs with fewer than 2 non-missing values have the r values set to NA. The diagonals of `n` are the number of non-NAs for the single variable corresponding to that row and column.

## Author(s)

Frank Harrell
Department of Biostatistics
Vanderbilt University
fh@fharrell.com

## References

Hollander M. and Wolfe D.A. (1973). Nonparametric Statistical Methods. New York: Wiley.

Press WH, Flannery BP, Teukolsky SA, Vetterling, WT (1988): Numerical Recipes in C. Cambridge: Cambridge University Press.

`hoeffd`, `cor`, `combine.levels`, `varclus`, `dotchart3`, `impute`, `chisq.test`, `cut2`.

## Examples

 ```1 2 3 4 5``` ```x <- c(-2, -1, 0, 1, 2) y <- c(4, 1, 0, 1, 4) z <- c(1, 2, 3, 4, NA) v <- c(1, 2, 3, 4, 5) rcorr(cbind(x,y,z,v)) ```

### Example output

```Loading required package: lattice

Attaching package: 'Hmisc'

The following objects are masked from 'package:base':

format.pval, round.POSIXt, trunc.POSIXt, units

x     y     z v
x 1  0.00  1.00 1
y 0  1.00 -0.75 0
z 1 -0.75  1.00 1
v 1  0.00  1.00 1

n
x y z v
x 5 5 4 5
y 5 5 4 5
z 4 4 4 4
v 5 5 4 5

P
x      y      z      v
x        1.0000 0.0000 0.0000
y 1.0000        0.2546 1.0000
z 0.0000 0.2546        0.0000
v 0.0000 1.0000 0.0000
```

Hmisc documentation built on Feb. 28, 2021, 9:05 a.m.