0

I am trying to run a Canonical Correspondence Analysis on diet composition data (prey.counts) with respect to a suite of environmental variables (envvar). Every row and every column sums to greater than 0, but I keep getting this error message:

diet <- cca(prey.counts, envvar$SL + envvar$Month + envvar$water.temp + 
            envvar$salinity + envvar$DO)

Error in if (any(rowSums(X) <= 0)) stop("All row sums must be >0 in the community data matrix") : 
  missing value where TRUE/FALSE needed

I have double and triple checked the prey.counts dataframe for NAs or empty columns/rows and none of them sum to zero or are missing values. R, RStudio, and all packages are fully up to date. Any help would be appreciated!

Meredith

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
user3303937
  • 13
  • 2
  • 5
  • Does your data.frame contain any NAs? – Marc in the box Feb 13 '14 at 00:05
  • No, originally there were a lot of NAs which I replaced as zeros (the dataframe includes counts of prey items (columns) for every stomach examined (rows)) and I have used the filtering function in excel to make sure none of the boxes are still empty and that none of the rows/columns sum to zero – user3303937 Feb 13 '14 at 00:08

1 Answers1

1

The problem is how you are calling the function, you seem to be mixing the default and formula interfaces (and abusing the formula notation whilst you are at it).

Does this help:

diet <- cca(prey.counts ~ SL + Month + water.temp + salinity + DO, data = envvar)

Alternatively, if the named variables are the only ones in envvar, you could do either of

diet <- cca(prey.counts ~ ., data = envvar)

or

diet <- cca(prey.counts, envvar)

with the latter using the less flexible but simple default method for cca().

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
  • I removed the unused variables from envvar and tried each of your suggestions and got the same error message as before. – user3303937 Feb 12 '14 at 23:55
  • OK, so make sure **vegan** is up-to-date; do `update.packages()` and let R update to the latest versions of the packages. Also do `rowSums(prey.counts)` and check that there really aren't any missing values. Other than that, *this* does work and we use it all all the time, so there must be something about your data that is causing the issue and without seeing it, it will be hard to diagnose. Can you edit into your question the output from `str(prey.counts)` and also show me the call to `cca()` you are now using. Telling me you did something is not the same as pasting in *exactly* the code used – Gavin Simpson Feb 13 '14 at 02:12
  • the rowSums(prey.counts) output showed about 8 completely empty rows at the bottom which were saved as NAs. I reopened prey.counts in excel and resaved it and now the CCA is working fine! Thank you so much for your help! – user3303937 Feb 13 '14 at 15:43
  • @user3303937 perhaps you should ditch Excel and learn to do these operations within R. Will save you a lot of trouble in the long run... – Gavin Simpson Feb 14 '14 at 15:53