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

Create interaction.adonis.R #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JFMSilva
Copy link
Contributor

I made this function to do pairwise comparisons when there is a significant interaction between factors in adonis.
I don´t know if this interests to you, but fell free to include in the package.

Case example:
library(vegan)
library (ade4)
library(pairwiseAdonis)

data(aravo)
Com <- aravo$spe # Community composition of vascular plants
Env <- aravo$env # landform and zoogenic disturbance indices are categorical variables with five and three categories, respectively

adonis2(Com ~ Form * ZoogD, data = Env, permutations = 999)

       Df SumOfSqs      R2      F Pr(>F)    

Form 4 3.9948 0.18876 5.3133 0.001 ***
ZoogD 2 2.6683 0.12608 7.0980 0.001 ***
Form:ZoogD 8 3.2228 0.15228 2.1432 0.001 ***
Residual 60 11.2778 0.53288
Total 74 21.1637 1.00000

There is a significant interaction, so we should analyse only the interaction. To do this, we should do a pairwise comparison for the factor of interest within each level of the other factor (i.e., to do pair-wise comparisons among levels of factor A within each level of factor B) and vice versa (Anderson, Gorley & Clarke, 2008).

interaction.adonis(x = Com, Env$Form, Env$ZoogD)

The function returns a list for each factor comprissed of pairwise comparisons within each of its levels, so that we can analyse how the effects of one factor varies between the levels of the other factor.
'x' can be a "data frame" or a "dist" object.

I made this function to do pairwise comparisons when there is a significant  interaction between factors in adonis.
I don´t know if this interests to you, but fell free to include in the package.

Case example:
library(vegan)
library (ade4)
library(pairwiseAdonis)

data(aravo) 
Com <- aravo$spe # Community composition of vascular plants
Env <- aravo$env # landform and zoogenic disturbance indices are categorical variables with five and three categories, respectively

adonis2(Com ~ Form * ZoogD, data = Env, permutations = 999)
           Df SumOfSqs      R2      F Pr(>F)    
Form        4   3.9948 0.18876 5.3133  0.001 ***
ZoogD       2   2.6683 0.12608 7.0980  0.001 ***
Form:ZoogD  8   3.2228 0.15228 2.1432  0.001 ***
Residual   60  11.2778 0.53288                  
Total      74  21.1637 1.00000                  

There is a significant interaction, so we should analyse only the interaction. To do this, we should do a pairwise comparison for the factor of interest within each level of the other factor (i.e., to do pair-wise comparisons among levels of factor A within each level of factor B) and vice versa (Anderson, Gorley & Clarke, 2008).

interaction.adonis(x = Com, Env$Form, Env$ZoogD)

The function returns a list for each factor comprissed of pairwise comparisons within each of its levels, so that we can analyse how the effects of one factor varies between the levels of the other factor.	
'x' can be a "data frame" or a "dist" object.
@pmartinezarbizu
Copy link
Owner

This sound interesting. but will need the documentation

@user3386170
Copy link

Did this get integrated into the package?

I tried copying the function but got: Error in combn(unique(as.character(factors)), 2) : n < m; my data.table had some factor levels that were removed in the subset of the analysis. When I rewrote the factors to limit levels to only those in the subset, the analysis could be run. I suggest adding a line to the function to automatically reduce the number of factor levels.

@Aquaticecology
Copy link

Aquaticecology commented Dec 18, 2023

Hi, I want to use the "pairwiseAdonis" package in Rstudio4.3.2, but this package is not available for this R version. So, can you help me to solve this problem?

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

Successfully merging this pull request may close these issues.

4 participants