Skip to contents

[Experimental]

A wrapper for the vegan::adonis2() function in the case of physeq object.

Usage

adonis_pq(
  physeq,
  formula,
  dist_method = "bray",
  merge_sample_by = NULL,
  na_remove = FALSE,
  correction_for_sample_size = FALSE,
  rarefy_nb_seqs = FALSE,
  verbose = TRUE,
  ...
)

Arguments

physeq

(required): a phyloseq-class object obtained using the phyloseq package.

formula

(required) the right part of a formula for vegan::adonis2(). Variables must be present in the physeq@sam_data slot.

dist_method

(default "bray") the distance used. See phyloseq::distance() for all available distances or run phyloseq::distanceMethodList(). For aitchison and robust.aitchison distance, vegan::vegdist() function is directly used.

merge_sample_by

a vector to determine which samples to merge using the merge_samples2() function. Need to be in physeq@sam_data

na_remove

(logical, default FALSE) If set to TRUE, remove samples with NA in the variables set in formula.

correction_for_sample_size

(logical, default FALSE) If set to TRUE, the sample size (number of sequences by samples) is add to formula in the form y~Library_Size + Biological_Effect following recommendation of Weiss et al. 2017. correction_for_sample_size overcome rarefy_nb_seqs if both are TRUE.

rarefy_nb_seqs

(logical, default FALSE) Rarefy each sample (before merging if merge_sample_by is set) using phyloseq::rarefy_even_depth(). if correction_for_sample_size is TRUE, rarefy_nb_seqs will have no effect.

verbose

(logical, default TRUE) If TRUE, prompt some messages.

...

Other arguments passed on to vegan::adonis2() function.

Value

The function returns an anova.cca result object with a new column for partial R^2. See help of vegan::adonis2() for more information.

Details

This function is mainly a wrapper of the work of others. Please make a reference to vegan::adonis2() if you use this function.

Author

Adrien Taudière

Examples

data(enterotype)
# \donttest{
adonis_pq(enterotype, "SeqTech*Enterotype", na_remove = TRUE)
#> Taxa are now in columns.
#> SeqTech
#> Enterotype
#> 9 were discarded due to NA in variables present in formula.
#> Permutation test for adonis under reduced model
#> Terms added sequentially (first to last)
#> Permutation: free
#> Number of permutations: 999
#> 
#> vegan::adonis2(formula = .formula, data = metadata)
#>                     Df SumOfSqs      R2        F Pr(>F)    
#> SeqTech              2   29.175 0.54055 242.2289  0.001 ***
#> Enterotype           2    8.651 0.16028  71.8250  0.001 ***
#> SeqTech:Enterotype   4    0.368 0.00683   1.5293  0.126    
#> Residual           262   15.778 0.29234                    
#> Total              270   53.972 1.00000                    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
adonis_pq(enterotype, "SeqTech", dist_method = "jaccard")
#> Taxa are now in columns.
#> Permutation test for adonis under reduced model
#> Terms added sequentially (first to last)
#> Permutation: free
#> Number of permutations: 999
#> 
#> vegan::adonis2(formula = .formula, data = metadata)
#>           Df SumOfSqs      R2      F Pr(>F)    
#> SeqTech    2   31.330 0.40211 93.147  0.001 ***
#> Residual 277   46.585 0.59789                  
#> Total    279   77.915 1.00000                  
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
adonis_pq(enterotype, "SeqTech", dist_method = "robust.aitchison")
#> Taxa are now in columns.
#> Permutation test for adonis under reduced model
#> Terms added sequentially (first to last)
#> Permutation: free
#> Number of permutations: 999
#> 
#> vegan::adonis2(formula = .formula, data = metadata)
#>           Df SumOfSqs      R2      F Pr(>F)    
#> SeqTech    2    83943 0.71401 345.79  0.001 ***
#> Residual 277    33622 0.28599                  
#> Total    279   117565 1.00000                  
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
# }