0

I've got a problem fighting one error. Here is the line I try to execute:

library(vegan)
adonis(data = dset, adiv ~ N+P+K)

It returns a failure message:

Error in rowSums(x, na.rm = TRUE) : 
  'x' must be an array of at least two dimensions

Everything seems to be alright with the dataset, because aov(data = dset, adiv ~ N+P+K) works just fine. I know that such errors appear when some functions drop data frame dimensions, but I don't know how to fix it in this case.

Edit. Adding a piece of my dataset.

treatment   N   P   K   M   adiv
N   1   0   0   0   0.2059
P   0   1   0   0   0.20856
K   0   0   1   0   0.22935
O   0   0   0   0   0.10729
NP  1   1   0   0   0.30674
NK  1   0   1   0   0.30509
PK  0   1   1   0   0.30606
NPK+    1   1   1   1   0.50389
NPK 1   1   1   0   0.40731
manure  0   0   0   1   0.2085

Before I try to execute adonis I convert treatment values into factors with:

dataset$N <- as.factor(dat$N)
dataset$P <- as.factor(dat$P)
dataset$K <- as.factor(dat$K)
dataset$M <- as.factor(dat$M)

Then I just try to execute the function and get the error. As I've already mentioned, everything works just fine when I try aov() or lm().

4

1 回答 1

4

这是猜测,因为您的问题没有任何可重现的内容。但是,如果我使用单变量响应,我可能会触发类似的错误:adonis 适用于多变量响应,并且可能不适用于单变量响应。可以使用adonis阅读帮助页面?adonis,它说公式的左侧应该是“相异对象(从类继承"dist")或数据框或矩阵”。当我尝试时,遵循这会有所帮助(但我真的无法重现您的示例):您可以尝试使用 lhs of as.matrix(Nitrososphaearaceae)or dist(Nitrososphaeraceae)

adonis 功能确实适用于多变量响应,并且使用单变量响应需要小心。您还应该仔细考虑与此类模型一起使用的相异性(或距离)类型。例如,上面的两个备选方案将给出不同的结果,因为它们使用不同的差异度量。我完全不确定使用基于距离的方法(例如adonis 单变量响应)是否有意义。

于 2015-02-18T11:34:43.290 回答