Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting coefficients #640

Closed
momsane opened this issue Apr 28, 2024 · 2 comments
Closed

Extracting coefficients #640

momsane opened this issue Apr 28, 2024 · 2 comments

Comments

@momsane
Copy link

momsane commented Apr 28, 2024

Hi,
I saw that it was possible to extract the coefficients of the linear model for each species of the community with the now deprecated function adonis. I couldn't find a way to do so with adonis2. Has the data been removed from the output? If so, what are alternatives methods to estimate which taxa are contributing the most to the observed differences?

Thanks a lot :)

@jarioksa
Copy link
Contributor

jarioksa commented Apr 29, 2024

The coefficients were indeed dropped from adonis2 because those in adonis were not based on the statistical model used in adonis and actually were misleading as they referred to some other statistical method. Certainly they would not tell you which taxa contributed the most to the observed differences. The species coefficients were the same as you would get from linear model (function lm) using species as dependent variables. If you think you need those coefficients, try linear model. The following commands will give you same coefficients:

library(vegan)
data(dune, dune.env)
ado <- adonis(dune ~ Moisture, dune.env) # deprecated
coef(ado)[,1:3]
#               Achimill   Agrostol    Airaprae
# (Intercept)  0.73214286  2.6607143  0.23214286
# Moisture.L  -1.29372504  2.8909165  0.17569106
# Moisture.Q  -0.03571429 -1.1785714 -0.03571429
# Moisture.C   0.68679231  0.5909608  0.43124168

## linear model for these three species
lm(as.matrix(dune[,1:3]) ~ Moisture, dune.env)

# Call:
# lm(formula = as.matrix(dune[, 1:3]) ~ Moisture, data = dune.env)

# Coefficients:
#              Achimill  Agrostol  Airaprae
# (Intercept)   0.73214   2.66071   0.23214
# Moisture.L   -1.29373   2.89092   0.17569
# Moisture.Q   -0.03571  -1.17857  -0.03571
# Moisture.C    0.68679   0.59096   0.43124

## you can also get these manually from rda for centred data: (Intercept) is zero
mod <- rda(dune ~ Moisture, dune.env)
qr.coef(qr(mod), as.matrix(dune[,1:3]))
#               Achimill   Agrostol    Airaprae
# Moisture.L -1.29372504  2.8909165  0.17569106
# Moisture.Q -0.03571429 -1.1785714 -0.03571429
# Moisture.C  0.68679231  0.5909608  0.43124168

This highlights the problem with species coefficients: they were based on Euclidean distances and are correct when Euclidean distances were used in adonis, but most often adonis is based on non-Euclidean distances (dissimilarities) and the species coefficients are not valid for them.

As to site scores: they were wrongly calculated in adonis. The fix is obvious, but as we are about to deprecate and phase out adonis this may not need fixing.

@momsane
Copy link
Author

momsane commented May 15, 2024

Hi, sorry for my late reply. Thank you for the explanation, it makes much more sense now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants