vegandevs / vegan

R package for community ecologists: popular ordination methods, ecological null models & diversity analysis
https://vegandevs.github.io/vegan/
GNU General Public License v2.0
449 stars 96 forks source link

Mantel test stops as NAs are present in the matrices (but they are not). #215

Closed sciabola closed 7 years ago

sciabola commented 7 years ago

I have a script I have used hundred of times with vegan that computes a mantel test over 2 distance matrices. With version 2.4-1 it gives

Error in quantile.default(x$perm, c(0.9, 0.95, 0.975, 0.99)) : 
  missing values and NaN's not allowed if 'na.rm' is FALSE
In addition: There were 50 or more warnings (use warnings() to see the first 50)

No matter of what matrices I am using, including those who successfully worked in the past.

jarioksa commented 7 years ago

We have no way of reproducing this, and none of the examples I tried had any problems. However, if a computer claims that there are missing values or NaN's, I believe the computer: it is much more pedantic than I. You also got more than 50 warnings: did you look at them and did they give any hints to solve your problem?

The na.rm argument was added to vegan version 2.0-5 (Oct 8, 2012). Before that the missing values were not explicitly handled, and they may have been erroneously accepted.

sciabola commented 7 years ago

The Warnings are simply as this?

mantel(xdis = xdata2.dists, ydis = x_model2.dists, method = "pearson", permutations = 9999)Pearson's product-moment correlationNANAc(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA [... truncated]

I am happy to attach my matrices here and see what you suggest. All the best.

Marco

Marco Gamba, PhD Dipartimento di Scienze della Vita e Biologia dei Sistemi - Life Sciences and Systems Biology Via Accademia Albertina, 13 10123 Torino, Italia mail: marco.gamba@unito.it mailto:marco.gamba@unito.it tel: (+39) 011-670-4560/4559

On 04 Nov 2016, at 10:03, Jari Oksanen notifications@github.com wrote:

We have no way of reproducing this, and none of the examples I tried had any problems. However, if a computer claims that there are missing values or NaN's, I believe the computer: it is much more pedantic than I. You also got more than 50 warnings: did you look at them and did they give any hints to solve your problem?

The na.rm argument was added to vegan version 2.0-5 (Oct 8, 2012). Before that the missing values were not explicitly handled, and they may have been erroneously accepted.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vegandevs/vegan/issues/215#issuecomment-258376342, or mute the thread https://github.com/notifications/unsubscribe-auth/AG36QfpErSC9nJ9bTsS7UAJTMQGK_yYZks5q6vTRgaJpZM4Ko04Z.

jarioksa commented 7 years ago

It may be better to send them off-list.

jarioksa commented 7 years ago

Thanks for the files that I got in email. This indeed fails, but I got more meaningful warnings:

50: In cor(permvec, ydis, method = method, use = use) :
  the standard deviation is zero

The problem was that your second dissimilarities (x_model2.dists) are constant (all == 1), and calculation of correlation fails when one of the variables is constant.

Are you sure you have earlier analysed these very same data? They should have failed earlier, and the failure should come from R stats.