vegandevs / vegan

R package for community ecologists: popular ordination methods, ecological null models & diversity analysis
https://vegandevs.github.io/vegan/
GNU General Public License v2.0
449 stars 96 forks source link

Adonis2 - No residual component #550

Closed PeterCx closed 1 year ago

PeterCx commented 1 year ago

Hi there,

I am trying to compute a PERMANOVA using Adonis2 with 110 factors. Essentially I want to find out the R2 for each factor and see how much it contributes to overall variation in microbiota composition.

When I add 50 factors to the model I get the following warning. I understand essentially this means that the factors I have already added to the model explain all variance but this cannot be true. I already know the 4 factors which should explain the most variance but they have not been added to the model yet.

No residual component

         Df SumOfSqs R2 F Pr(>F)
Model    55   10.696  1         
Residual  0    0.000  0         
Total    55   10.696  1

Warning message:
In att$heading[2] <- deparse(match.call(), width.cutoff = 500L) :
  number of items to replace is not a multiple of replacement length

Help greatly appreciated.

Kind regards,

P

jarioksa commented 1 year ago

The predictor variables do not need to good if you have plenty of them. After you run out of degrees of freedom (Residual component has 0 degrees of freedom), you can explain everything completely with any predictor variables. You may try with 55 random variables, and that will give you the same result: Residual 0 d.f. and sum of squares 0.000.

You cannot reach your goal with your approach. If you had more data (more observations than predictor variables), you would get either sequential tests (terms assessed in the order they entered the model) or marginal tests (terms assessed for their unique contribution after all other terms). If you want to get the first-order effects of variables, or their contribution when they are the only variable entered in the model, you can fit corresponding dbrda models and use add1 to test each variable (adonis2 is only a short-cut to a similar dbrda model).

Here an example how to do it with vegan data sets:

library(vegan)
data(mite, mite.env)
d <- vegdist(mite, "hellinger") # use the same dissimilarity as in adonis2; "hellinger" in vegan 2.6-4
m0 <- dbrda(d ~ 1, mite.env) # Null model: no predictor variables
m1 <- dbrda(d ~ ., mite.env) # maximum model with all predictor variables: can have residual zero
add1(m0, m1, test = "permutation", permutations=999)
##           Df    AIC       F Pr(>F)    
## <none>       232.23                   
## SubsDens   1 231.34  2.8655  0.030 *  
## WatrCont   1 212.05 25.3499  0.001 ***
## Substrate  6 232.24  1.9618  0.003 ** 
## Shrub      2 217.92 10.0146  0.001 ***
## Topo       1 221.66 13.3731  0.001 ***
## ---
## Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

If you want to get sums of squares, you need to write the loop yourself and catch the constrained total variance which in model mod is the element mod$CCA$tot.chi or calculate back from F-values or AIC.