Dear R-users: I am runing R 1.6.2 with Windows XP. I try to calculate Pearson correlation and Spearman correlation of any pairwise columns of 8000 x 80 data matrix with missing values and randomize the matix 1000 times and calculate this two correlations again. The code bellow for Pearson is working fine but for Spearman got the error bellow for randomized data matrix and R console is stop working: cor (raw2[,i], raw2[,j], use="complete.obs") cor.test (raw2[,i], raw2[,j], method="spearman", na.action = "na.omit") $estimate Error in cor.test.default(raw2[, i], raw2[, j], method = "spearman", na.action = "na.omit") : not enough finite observations In addition: There were 50 or more warnings (use warnings() to see the first 50) What does the Error mean? How to fix it? Any suggestion are highly appreciated? Josh
cor.test does not have an na.action argument unless used with the formula interface, when it is better to use na.action=na.omit, not "na.omit". The error message occurs if less than 2 rows are completely non-missing. So take a closer look at your data. BTW, I would compare the different methods of cor.test, not cor.test with cor, to check I really had this right. On Sat, 13 Sep 2003 szhan at uoguelph.ca wrote:> Dear R-users: > I am runing R 1.6.2 with Windows XP. I try to calculate Pearson correlationThat's long obselete, as you know.> and Spearman correlation of any pairwise columns of 8000 x 80 data > matrix with missing values and randomize the matix 1000 times and > calculate this two correlations again. The code bellow for Pearson is > working fine but for Spearman got the error bellow for randomized data > matrix and R console is stop working:And what does that last phrase mean? (And `bellow' is not something you should do on a public list.)> cor (raw2[,i], raw2[,j], use="complete.obs") > cor.test (raw2[,i], raw2[,j], method="spearman", na.action = "na.omit") > $estimate > > Error in cor.test.default(raw2[, i], raw2[, j], method = "spearman", na.action > = "na.omit") : > not enough finite observations > In addition: There were 50 or more warnings (use warnings() to see the first > 50) > > What does the Error mean? How to fix it? > Any suggestion are highly appreciated? > Josh-- 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
Josh - See the example "run a simulation" in help("try"). This won't be able to tell you the Spearman correlation when there are fewer than two pairs of non-missing values, but it will allow the loop to keep running. Caution: the return value from try() will be a string with the error message, when cor.test() fails, so whatever variable you accumulate the simulation results in must be able to tolerate string values. That suggests using a list. - tom blackwell - u michigan medical school - ann arbor - On Sat, 13 Sep 2003 szhan at uoguelph.ca wrote:> Dear R-users: > I am runing R 1.6.2 with Windows XP. I try to calculate Pearson correlation > and Spearman correlation of any pairwise columns of 8000 x 80 data matrix with > missing values and randomize the matix 1000 times and calculate this two > correlations again. The code bellow for Pearson is working fine but for > Spearman got the error bellow for randomized data matrix and R console is stop > working: > > cor (raw2[,i], raw2[,j], use="complete.obs") > cor.test (raw2[,i], raw2[,j], method="spearman", na.action = "na.omit") > $estimate > > Error in cor.test.default(raw2[, i], raw2[, j], method = "spearman", > na.action = "na.omit") : > not enough finite observations > In addition: There were 50 or more warnings (use warnings() to see > the first 50) > > What does the Error mean? How to fix it? > Any suggestion are highly appreciated? > Josh