0

I keep getting this error when trying to perform metaMDS on my ecology data, same as this post.

'comm' has negative data: 'autotransform', 'noshare' and 'wascores' set to FALSE
Error in distfun(comm, method = distance, ...) : 
  input data must be numeric

I have thoroughly checked and do not think I have negative values. I believe it thinks my zeroes are negative values?.

Here is my code with the error after the metaMDS step:

df = read.csv("nmds.csv", header = TRUE)
com = df[,4:ncol(df)]
m_com = as.matrix(com)

set.seed(12345)
nmds = metaMDS(m_com, distance = "bray")
nmds

'comm' has negative data: 'autotransform', 'noshare' and 'wascores' set to FALSE
Error in distfun(comm, method = distance, ...) : 
  input data must be numeric

I've tried removing 0 values using m_com[rowSums(m_com[])>0,] but it gives me this error as well:

Error in rowSums(m_com[]) : 'x' must be numeric

I have gotten this code to work on previous datasets with many zeroes as well I don't know what the issue is this time! See below for what m_com looks like. Thank you all.

What m_com looks like

  • Could you put head of data to see if your data is numeric?! it seems to your data having character or logical. – rezgar Jun 29 '23 at 17:59
  • Do you mean head(m_com)? This is the output: > head(m_com) ASV1 ASV14 ASV4 ASV16 ASV26 ASV11 ASV20 ASV34 ASV22 ASV49 ASV3 ASV5 ASV6 ASV21 ASV25 ASV2 ASV78 ASV92 ASV18 ASV57 ASV36 ASV106 ASV201 ASV15 ASV88 ASV42 ASV73 ASV46 ASV1171 ASV145 ASV32 ASV180 ASV69 ASV12 ASV45 ASV101 ASV71 ASV27 ASV28 ASV68 ASV170 ASV287 ASV142 ASV50 ASV76 ASV19 ASV80 ASV128 ASV72 ASV47 ASV116 ASV38 ASV160 ASV74 ASV7 ASV75 ASV90 ASV216 ASV77 ASV81 ASV152 ASV176 ASV114 ASV181 ASV98 ASV79 ASV206 ASV122 ASV48 ASV91 ASV223 ... –  Jun 29 '23 at 18:03
  • the object 'com' appears to contain numerics: > str(com) 'data.frame': 195 obs. of 4930 variables: $ ASV1 : num 0.007 0.013 0 0.003 0 0.004 0.004 0 0.005 0 ... $ ASV14 : num 0 0.009 0.008 0 0 0 0 0 0 0.005 ... $ ASV4 : num 0 0 0 0 0 0 0 0 0 0 ... $ ASV16 : num 0 0 0 0 0 0 0 0 0 0 ... $ ASV26 : num 0.175 0.138 0.156 0.128 0.147 0.142 0.188 0.133 0.17 ... but m_com appears to not: > str(m_com) num [1:195, 1:4930] 0.007 0.013 0 0.003 0 0.004 0.004 0 0.005 0 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:4930] "ASV1" "ASV14" "ASV4" "ASV16" ... –  Jun 29 '23 at 18:05
  • you can ignor header argoman in read.csv function and try again like below cod df = read.csv("nmds.csv", header = F) – rezgar Jun 29 '23 at 18:07
  • Hi thank you but then my matrix has ASV1, ASV2, ASV3 as the first column of the dataset instead of the abundance information. Running metaMDS yields: Error in sqrt(comm) : non-numeric argument to mathematical function –  Jun 29 '23 at 18:11
  • Please add new function `df<-as.numeric(df)` – rezgar Jun 29 '23 at 18:25
  • Hi there, should I do this after the read.csv step? I get an error: > pc = read.csv("nmds.csv", header = F) > df<-as.numeric(pc) Error: 'list' object cannot be coerced to type 'double' –  Jun 29 '23 at 18:49
  • read.csv(..., head = FALSE) means that your data has no heade and every row is data. You clearly have header (ASV1 etc.), so you must say so. You cannot turn ASV1 to numeric but you get an error when trying to do so. – Jari Oksanen Jun 30 '23 at 14:13
  • Once you get over reading in your data you still need to find the negative values. You should not argue with your computer: you will lose. If your computer finds negative values and you don't find them, you should try harder. Try these any(m_com < 0) and if this is TRUE you have negative values. This will show the indices of negative data: which(m_com < 0, arr.ind = TRUE). – Jari Oksanen Jun 30 '23 at 14:17

0 Answers0