0

I'm trying to do a Canonical Correspondence Analysis in R using the vegan package. I've run it no problem with my continuous variables, but when I include some categorical variables (which I'm able to do in XLSTAT program), R returns with an error. How do I include this in my code?

my categorical variables are:

  • porifera_preference
  • category

This is my code:

       gastropod_matrix <- as.matrix(mollusca[,21:24])

       gastropod_cca <- cca(gastropod_matrix~porifera_presence + category + 
            average + bpi_st_fi + northing + easting + depth, data=mollusca)

       plot(gastropod_cca)

I know that R will likely be confused with this code but I don't know how to change it. Please help!

  • Can you give any hints about the error **R** returns? – Jari Oksanen Mar 22 '18 at 17:34
  • Just to make it clear: **vegan** function `cca()` has no problems with categorical variables but handles them smoothly, and has handled for 15 years. This is probably a user error, but we cannot know -- in particular as you don't tell us what is the informative error message. – Jari Oksanen Mar 26 '18 at 06:46
  • Hi there! I was offline over the weekend. This is what I get in return: Error in cca.default(d$X, d$Y, d$Z) : All row sums must be >0 in the community data matrix – Sara Fritsch Mar 26 '18 at 08:40
  • It says that some row sums are zero or negative, and they cannot be analysed in correspondence analysis: remove those rows. These row sums are in the community matrix (dependent matrix). – Jari Oksanen Mar 26 '18 at 08:53
  • How would I exclude rows with sums that are zero? I did notice that I have them in my matrix. This is the code I used: gastropod_matrix <- as.matrix(mollusca[,21:24]) – Sara Fritsch Mar 26 '18 at 08:59
  • 1
    You need to collect them as `pos <- rowSums(mollusca[,21:24]) > 0`, and then use that as an index `gastropod_matrix <- mollusca[pos, 21:24]` and the same in `cca( , data = mollusca[pos,])`. – Jari Oksanen Mar 26 '18 at 20:41

0 Answers0