简体   繁体   中英

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. 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().

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. 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." 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) .

The adonis function is really intended for multivariate responses and use univariate responses needs care. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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