decorana(df) 中的错误:社区矩阵中的所有行总和必须 >0,删除空站点。素食中的 DCA

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

我正在尝试 运行 在 PCA 受到马蹄铁效应影响后在 Vegan 中使用 DCA,但是,我收到以下错误代码:

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

我假设这是因为对数转换导致我有接近无限的值,但即使我将其转换为正值,我仍然收到相同的错误消息。

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)

任何关于我哪里出错或如何克服错误消息的指导将不胜感激。 PCA 不会出现这种情况。

您的示例数据中的某些值是 0log(0) 的计算结果为 -Inf

因此,当您尝试以下代码时,会出现错误:

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

因为任何实数加上 -Inf 都是 -Inf,所以这些行总和是 -Inf

我不熟悉您正在执行的分析,但使代码正常工作的一种方法是将 -Inf 替换为 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))