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.
rcorr(x, y, type=c("pearson","spearman"))
"print"(x, ...)
y
is absent). For print
, x
is an object
produced by rcorr
.
x
. If
y
is omitted for rcorr
, x
must be a matrix.
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.
t
or F
distributions.
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
.
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))
Run the code above in your browser using DataLab