Luca De Benedictis
2003-May-11 22:36 UTC
[R] rank correlation and distance between two different matrices
Dear all, in package Hmisc `rcorr' computes a matrix of Spearman's `rho' rank correlation coefficients for all possible pairs of columns of a matrix. What if I want a matrix of rank correlation coefficients for pair of columns of two different matrices? I have the same question about distance metrics in package Vegan. The function 'vegdist' computes distance indexes for all possible pairs of row of a matrix. What if I am interested in comparing each single row of matrix A with the correspondent row of matrix B? Any help would be appreciated. Luca
Prof Brian Ripley
2003-May-12 07:28 UTC
[R] rank correlation and distance between two different matrices
Apply these to c/rbind(A,B) and extract the part of the result which you want. On Mon, 12 May 2003, Luca De Benedictis wrote:> in package Hmisc `rcorr' computes a matrix of Spearman's `rho' rank > correlation coefficients for all possible pairs of columns of a matrix. > What if I want a matrix of rank correlation coefficients for pair of > columns of two different matrices? > > I have the same question about distance metrics in package Vegan. The > function 'vegdist' computes distance indexes for all possible pairs of > row of a matrix. What if I am interested in comparing each single row of > matrix A with the correspondent row of matrix B?-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Jari Oksanen
2003-May-12 07:44 UTC
[R] rank correlation and distance between two different matrices
On Mon, 2003-05-12 at 01:36, Luca De Benedictis wrote:> Dear all, > in package Hmisc `rcorr' computes a matrix of Spearman's `rho' rank > correlation coefficients for all possible pairs of columns of a matrix. > What if I want a matrix of rank correlation coefficients for pair of > columns of two different matrices? > > I have the same question about distance metrics in package Vegan. The > function 'vegdist' computes distance indexes for all possible pairs of > row of a matrix. What if I am interested in comparing each single row of > matrix A with the correspondent row of matrix B?Wasteful, but may do what you asked for:> A <- matrix(runif(120), nrow=10, ncol=12) > B <- matrix(runif(120), nrow=10, ncol=12) > diag(as.matrix(dist(rbind(A,B)))[11:20, 1:10])[1] 1.362722 1.381713 1.526918 1.565419 1.103431 1.384486 1.186895 [8] 1.512283 1.401761 1.817098 cheers, jari oksanen -- Jari Oksanen <jarioksa at sun3.oulu.fi>