Replace non-zero entries in a sparse matrix with non-zero ranks
SparsifiedRanks2.RdCreates a rank matrix for a sparse matrix X using the following approach: 1. Use non-zero enries in a column to calculate the ranks 2. Add (z-1)/2 to the ranks (only non-zero entries are changed). z is the number of zeros in the column Since all the entries are shifted by the same constant (the zeros are already shifted), the covariance matrix of this shifted matrix is the same as the rank matrix of the entire matrix (where the zeros would all also have a rank = (z+1)/2) where z is the number of zeros This rank matrix can then be used to calculate Spearman's correlation coefficient (via pearson correlation) Copied without code changes and only minor changes to the comments, from the public blog repository https://github.com/saketkc/blog/blob/main/2022-03-10/SparseSpearmanCorrelation2.ipynb owned by Saket Choudhary of Mumbai, India 23 Mar 2024