Search code examples
rvegan

Error in decorana(df) : all row sums must be >0 in the community matrix remove empty sites. DCA in Vegan


I am trying to run a DCA in Vegan after a PCA was subject to the horseshoe effect, however, I get the following error code:

Error in decorana(df) :    all row sums must be >0 in the community matrix. 

I assume this is because I have near infinite values due to the log transformation but even when I convert this to a positive value I still get the same error message.

WapITRAXPCA<-read.csv("WapITRAXPCA.csv",header=TRUE)

log_features <-structure(list(Depth = c(0, 0.1, 0.2, 0.3, 0.4, 0.5), Al = c(101L, 
49L, 136L, 115L, 162L, 148L), Si = c(71L, 45L, 142L, 109L, 126L, 
172L), Cl = c(1589L, 4166L, 5483L, 5322L, 5933L, 7991L), Ca = c(1030L, 
2663L, 3508L, 3317L, 3486L, 4257L), Ti = c(253L, 812L, 798L, 
902L, 1151L, 941L), Mn = c(1025L, 1979L, 2814L, 1582L, 1541L, 
1601L), Fe = c(84177L, 191581L, 297436L, 352490L, 456931L, 466042L
), Cu = c(246L, 331L, 328L, 265L, 336L, 196L), Zn = c(0L, 81L, 
175L, 0L, 73L, 221L), Br = c(12777L, 17939L, 18740L, 16801L, 
16539L, 16456L), Rb = c(626L, 223L, 446L, 539L, 294L, 451L), 
Zr = c(817L, 1034L, 886L, 957L, 1584L, 947L), Inc.co = c(6.049230907, 
5.975282432, 5.736199822, 5.658584418, 5.659008377, 5.597103404
)), row.names = c(NA, 6L), class = "data.frame")


log_features[, -1] <- log(log_features[, -1]) #tell R not to log transform the depth column
log_features[is.na(log_features)] <--99999 #tell R to replace -INF values with a really small value you may need to run this set of code twice for some reason R is funny about it. 

df<-log_features[2:14] #tell R to only plot the element data and not depth

#Run DCA
ord <- decorana(df)

plot(ord)

Any guidance as to where I am going wrong or how to overcome the error message would be appreciated. This doesn't occur with the PCA.


Solution

  • Some of the values in your sample data are 0. log(0) evaluates to -Inf.

    Thus, when you try the following code, you get an error:

    library(vegan)
    decorana(df)
    Error in decorana(df) : 
      all row sums must be >0 in the community matrix: remove empty sites
    

    Since any real number plus -Inf is -Inf, those row sums are -Inf.

    I am not familiar with what analysis you are performing, but one approach that makes the code work is to replace those -Inf with 0:

    df <- as.matrix(df)
    df[is.infinite(df)] <- 0
    decorana(df)
    
    #Call:
    #decorana(veg = df) 
    
    #Detrended correspondence analysis with 26 segments.
    #Rescaling of axes with 4 iterations.
    
    #                   DCA1      DCA2      DCA3      DCA4
    #Eigenvalues     0.01258 0.0014996 0.0009466 7.633e-04
    #Decorana values 0.01858 0.0005794 0.0002038 6.081e-06
    #Axis lengths    0.28996 0.0907576 0.0869835 8.173e-02
    
    plot(decorana(df))
    

    enter image description here