简体   繁体   English

素食主义者的阿多尼斯功能不起作用

[英]adonis function from vegan doesn't work

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. 数据集似乎一切正常,因为aov(data = dset,adiv〜N + P + K)可以正常工作。 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(). 正如我已经提到的,当我尝试aov()或lm()时,一切都很好。

This is guessing since there is nothing reproducible in your question. 这是猜测,因为您的问题没有可重复的内容。 However, I can trigger similar error if I use univariate responses: adonis is intended for multivariate responses, and may not work with univariate responses. 但是,如果我使用单变量响应,则可能会触发类似的错误: adonis用于多变量响应,可能不适用于单变量响应。 The adonis help page can be read with ?adonis , and it says that the left-hand-side of the formula should be "either a dissimilarity object (inheriting from class "dist" ) or data frame or a matrix." 可以使用?adonis来读取adonis帮助页面,该页面显示公式的左侧应该是“相异对象(继承自类"dist" )或数据框或矩阵。 Following this helps when I try (but I really cannot reproduce your example): you could try with lhs of as.matrix(Nitrososphaearaceae) or dist(Nitrososphaeraceae) . 当我尝试(但我确实无法重现您的示例)时,遵循此方法将有所as.matrix(Nitrososphaearaceae) :您可以尝试使用as.matrix(Nitrososphaearaceae)dist(Nitrososphaeraceae) lhs。

The adonis function is really intended for multivariate responses and use univariate responses needs care. adonis函数实际上是针对多变量响应的,使用单变量响应需要注意。 You should also carefully consider the type of dissimilarity (or distance) you use with such models. 您还应该仔细考虑与此类模型一起使用的相异类型(或距离)。 For instance, the two alternatives above will give different results because they use different dissimilarity measures. 例如,上面的两个选择将给出不同的结果,因为它们使用了不同的差异度量。 I am not at all sure that it makes much sense to use distance-based methods like adonis with univariate responses. 我完全不确定使用具有单变量响应的基于距离的方法(如adonis有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM