Code Monkey home page Code Monkey logo

pairwiseadonis's Introduction

pairwiseAdonis

version 0.4 includes 2 functions

pairwise.adonis

pairwise.adonis2

pairwise.adonis

This is a wrapper function for multilevel pairwise comparison using adonis2 (~Permanova) from package 'vegan'. The function returns adjusted p-values using p.adjust(). It does not accept interaction between factors neither strata.

pairwise.adonis2

This function accepts strata

NOTE: This is still a developing version -- Please validate your results. I would appreciate feed back.

update 28 April 2020: Function now adapts the permutation matrix for each combination of factors before applying adonis. The p-value when using strata (block) looks correct now. Check syntax in example below.

This function accepts a model formula like in adonis from vegan. You can use interactions between factors and define strata to constrain permutations. For pairwise comparison a list of unique pairwise combination of factors is produced. Then for each pair, following objects are reduced accordingly to include only the subset of cases belonging to the pair:

  • the left hand side of the formula (dissimilarity matrix or community matrix)

  • the right hand side of the formula (factors)

  • the strata if used.

The reduced data are passed to adonis and the summary of the anova table for each pair is saved in a list, together with the anova table of the full model and the original 'parent call'.

update 30.08.21 Both functions now use adonis2 instead of adonis. This will solve some problems when loading DescTools. The functions should now work with Phyloseq objects.

Thanks to @lkoest12 for raising this and @JFMSilva for the solution joey711/phyloseq#1457 (comment)

Here a sample code provided by Andrea Pietruska for phyloseq:

For Jaccard and Bray Curtis:

ps_tr <- microbiome::transform(phyloseq_object, "clr")

ps_dist_matrix <- phyloseq::distance(phyloseq_object, method ="jaccard")

vegan::adonis2(ps_dist_matrix ~ phyloseq::sample_data(ps_tr)$treatment)

pairwise.adonis(ps_dist_matrix, phyloseq::sample_data(ps_tr)$treatment)

For Unifrac:

weighted_unifrac = UniFrac(physeq=phyloseq_object, weighted=T, normalized=T, parallel=T, fast=T)

vegan::adonis2(weighted_unifrac ~ phyloseq::sample_data(ps_tr)$treatment)

pairwise.adonis(weighted_unifrac, phyloseq::sample_data(ps_tr)$treatment)


INSTALLATION

For linux

Note: I have experience myself an Error when installing from github.

Error converted from warning ... (r-lib/remotes#403) To avoid this, load devtools and type first in your R session:

Sys.setenv("R_REMOTES_NO_ERRORS_FROM_WARNINGS"=TRUE)

.... follow below

make sure you have devtools installed and loaded, for windows also install Rtools

In your R session

install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis")

That's it

Or...

For windows

first install Rtools from here https://cran.r-project.org/bin/windows/Rtools/

in R install devtools

install.packages('devtools')

load devtools

library(devtools)

In your R session

install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis")


Usage

library(pairwiseAdonis)
data(iris)
pairwise.adonis(iris[,1:4],iris$Species)

# For strata (blocks), following example of Jari Oksanen in adonis2. 
dat <- expand.grid(rep=gl(2,1), NO3=factor(c(0,10,30)),field=gl(3,1) )
Agropyron <- with(dat, as.numeric(field) + as.numeric(NO3)+2) +rnorm(18)/2
Schizachyrium <- with(dat, as.numeric(field) - as.numeric(NO3)+2) +rnorm(18)/2
Y <- data.frame(Agropyron, Schizachyrium)

pairwise.adonis2(Y ~ NO3/field, data = dat, strata = 'field')

for more examples see also ?pairwise.adonis() ?pairwise.adonis2()


Citation

Martinez Arbizu, P. (2020). pairwiseAdonis: Pairwise multilevel comparison using adonis. R package version 0.4

pairwiseadonis's People

Contributors

cotillau avatar jfmsilva avatar kant avatar pmartinezarbizu avatar smonteux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pairwiseadonis's Issues

PERMANOVA with small sample size?

Hi guys
This is not a technical question but asking for maybe advice or helpful comment.
Could you please let me know what are the lowest sample size that could be considered acceptable? I did the ordination plot and can see the difference/dissimilarity visually between intestine, feed, and water.

The problem is that I have n=2 or n=3 in water/feed that I suspect the PERMANOVA results.
Please comment and tell me what you think.

Use of pairwise.adonis2

Hey, thanks for the code of pairwise adonis. Really appreciate it. I am a bit confused that if I am using or interpreting it right. So basically I have Patient samples at three time points and wanted to perform repeated measure PERMANOVA, such that I can compare each individual with its own microbiome profile at different time points to see whether overall microbiome composition changes between timepoint. This is the code that I am running:
pairwise.adonis2(kaiju_bray_dist.genus_abx~Anti_TP,data=sampledf_abx,strata = 'Patient.number',nperm = 999)
where,
kaiju_bray_dist.genus_abx = bray Curtis distance matrix;
Anti_TP= factor with three level (Baseline, Day 7, Day 30);
sampledf_abx = sample metadata;
Patient.number = patient ID (Patient A, B, C)

Any help/suggestion would be much appreciated.
Thanks,
Achal University of Oslo

Significant p-value with adonis but all p-values >0.05 using pairwise.adonis

Hi ,

This is my first time posting a question here so I hope I am doing this right. I have intensively looked for the answer on diverse R forums and could not find help so I am pretty sure this questions has not been answered yet.

I have a metabarcoding dataset with OTUs reads by treatments and I have been running all my stats in R. I produced a nMDS with clear clusters connected to my treatments as well as adonis and anosim (PERMANOVA) and got significant p-values for both and with r^2~ 80% for adonis when I am testing for 'treatments' as my factors. However, when I run a post hoc PERMANOVA test using the same bray-curtis distance matrix (package vegan) with the function pairwise.Adonis all the pairwise comparisons between my treatments give me p-values > 0.05, regardless of the correction applied to the p-value or the number of permutations used. Here is my code:

_adonis(BC.matrix ~ Treatments, data = meta_data, permutations = 1000)

anosim(BC.matrix, meta_data$Treatments, permutations = 1000)

pairwise.adonis(BC.matrix, meta_data$Treatments)_

Could you help me understand that please?

Thank you in advance for you help. Naomi

Problems installing the package

Hello,

I can't install the package, I get the following error:

Downloading GitHub repo pmartinezarbizu/pairwiseAdonis@HEAD
Error: Failed to install 'pairwiseAdonis' from GitHub:
System command 'Rcmd.exe' failed, exit status: -1, stdout + stderr empty

Do you know what Rcmd.exe means?

I'm working on R 3.6 and have Rtools installed also.

Issue when running pairwise.adonis

Hi,

When running your example
pairwise.adonis(iris[,1:4],iris$Species)

I obtained an error message:
Error in adonis(x[factors %in% c(as.character(co[1, elem]), as.character(co[2, :
l'argument "sim.method" est manquant, avec aucune valeur par défaut

Maybe there is something wrong with R 4.0 ?

Pablo

eval LHS error

Hi,

I'm trying to integrate pairwise.adonis2 in some scripts but it raise an error when I run it with Rscript.

  • pairwise.adonis2 is integrated in a new function test_fun

  • the dissimilarity matrix prealably assigned in the variable ddd here.

With your example issue1.R

suppressMessages(library(pairwiseAdonis))
test_fun <- function() {

data(iris)
res1 = pairwise.adonis(iris[,1:4],iris$Species)
print(res1)

# For strata, extract factors into a new data.frame
ddd<-dist(iris[,1:4])
print(head(ddd))
fac <- data.frame(Species=iris$Species, Season = rep( c('winter','summer'),75))
res222 <- pairwise.adonis2(ddd~Species/Season,data=fac,strata='Season')
print(res222)
}

test_fun()

This works in console but not with Rscript.

tmp$ Rscript issue1.R 
                    pairs Df SumsOfSqs    F.Model        R2 p.value p.adjusted
1    setosa vs versicolor  1 1.1937545  552.51266 0.8493496   0.001      0.003
2     setosa vs virginica  1 2.0713706 1001.54509 0.9108722   0.001      0.003
3 versicolor vs virginica  1 0.2108291   91.82959 0.4837475   0.001      0.003
  sig
1   *
2   *
3   *
[1] 0.5385165 0.5099020 0.6480741 0.1414214 0.6164414 0.5196152
Error in eval(lhs) : objet 'ddd' introuvable
Calls: test_fun -> pairwise.adonis2 -> eval -> eval
Exécution arrêtée

Thanks for your help

Etienne

extract p values from pairwise adonis

Hi @pmartinezarbizu,

I am trying to extract the pairwise p-values from pairwise.adonis2.
I have 153 pairwise comparisons and would like to have basically a column of p-values for each comparison, something on the lines of a dataframe, with a column for the pair being compared, and a column with the respective p value. Is there any way to do that besides having to copy-paste each p value from the console on to an excel file?

Thank you so much.

Different results when inputting bray curtis distance matrix vs community data matrix with method = bray

I am getting different 8but similar) results depending on if my input is a pre calculated bray curtis distance matrix or a feature table with method = "bray". Should that not give the same results and if not why not?

Result from community matrix with method = "bray"

adonis_pairwise_16S.res = pairwise.adonis2(feature_table ~ caste_phase2 * species , data = metadata, method = "bray", nperm = 9999, strata = metadata$genus)
> adonis_pairwise_16S.res$S_vs_LW
                     Df SumOfSqs      R2       F Pr(>F)    
caste_phase2          1   0.7220 0.02977  5.0394  1e-04 ***
species               6  14.3224 0.59056 16.6610  1e-04 ***
caste_phase2:species  6   3.0471 0.12564  3.5446  1e-04 ***
Residual             43   6.1607 0.25403                   
Total                56  24.2522 1.00000                   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Result from pre calculated distance matrix:

adonis_pairwise_16S.res = pairwise.adonis2(distance_matrix ~ caste_phase2 * species , data = metadata, method = "bray", nperm = 9999, strata = metadata$genus)
> adonis_pairwise_16S.res$S_vs_LW
                     Df SumOfSqs      R2        F Pr(>F)    
caste_phase2          1 0.001621 0.01235  13.3694  1e-04 ***
species               6 0.120380 0.91719 165.4819  1e-04 ***
caste_phase2:species  6 0.004035 0.03074   5.5467  1e-04 ***
Residual             43 0.005213 0.03972                    
Total                56 0.131249 1.00000                    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(not)running pairwise.adonis2 with mapply

Hello, Pedro!

I'm having trouble applying pairwise.adonis2 to a list of phyloseq objects with mapply.

My objective is to automate this for long lits & make it available/comprehensible to students. I've been trying to solve this for several hours; you will find below the best example I can provide you. When it runs, I have the error message " Error in [.formula(eval(lhs), rhs.frame[, 1] %in% c(co[1, elem], co[2, :
unused argument (alist()) "

I have no idea of which unused argument it is talking about, but it is not something I placed in the function. I understand your function is under development and you may take time to reply.

As you can see the same formula & data works if apply to individual list components. For now, I can only run pairwise.adonis2 dozens of times, once for each list component.

Any idea of how can this be fixed? thanks!

library(vegan)
library(pairwiseAdonis)
library(phyloseq) # manages microbiome datasets and phyloseq objects
library(metagMisc) #  lets you create lists of split phyloseq objects
data(soilrep)
sample_data(soilrep)

pslist<-phyloseq_sep_variable(soilrep, variable = "clipped") # list of phyloseq objects

listed_bray <-lapply(pslist, function (x) # lhs data
  phyloseq::distance(otu_table(x), method="bray"))

listed_sampledata <-lapply(pslist, function (x) # rhs metadata
  as(phyloseq::sample_data(x),"data.frame"))

# using pairwise.adonis2 on each element of the list works!
pairwise.adonis2(listed_bray[[1]] ~ Treatment*warmed, data = listed_sampledata[[1]])

# using pairwise.adonis2 over lists fails!
mapply(function (x,y) 
  pairwise.adonis2(x ~ Treatment*warmed, data = y),
  listed_bray, listed_sampledata, SIMPLIFY = FALSE)

Not working for interactions between factors?

Hello,

I have a two-factor experimental design. My factors are Community, which has 4 levels, and Nutrient Treatment, which has 3 levels.
Factors: levels
Community: alone, with species 1, with species 2, all 3
Nutrient Treatment: ambient, press, pulse

Adonis indicates I have a significant interaction between my 2 factors, so I am trying to use pairwise.adonis2 to do posthoc tests and find out where the differences are between all of my treatments (4 levels * 3 levels = 12 levels).

Is pairwise.adonis2 working for posthoc tests on significant interactions terms? Or is it only working for main effects and strata?

If it is working for interaction terms, I can't seem to get it to work for assessing comparisons between all treatments. I've tried using the "strata" but it doesn't give me every combination of my treatments. It separates it out for one of my factors, and then gives an ANOVA table for each comparison of levels within that factor. But I don't know which level of the other factor it is for. I'm also not sure how to interpret the full ANOVA table output when comparing between 2 treatments....I was hoping for output like what is produced by pairwise.adonis().

My call is this: pairwise.adonis2(Padina_dist~Community*Nutrient_Treatment,data=Padina_3)

and then I get output like this:

$parent_call
[1] "Padina_dist ~ Nutrient_Treatment * Community , strata = Community"

$Ambient _vs_Press
Blocks: with(mdat1, mdat1[, ststri])
Permutation: free
Number of permutations: 999

Terms added sequentially (first to last)

                         Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)    

Nutrient_Treatment 1 11674.2 11674.2 85.309 0.50023 0.001 ***
Community 3 965.1 321.7 2.351 0.04136 0.001 ***
Nutrient_Treatment:Community 3 1119.0 373.0 2.726 0.04795 0.058 .
Residuals 70 9579.2 136.8 0.41046
Total 77 23337.5 1.00000

Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1

$Ambient _vs_Pulse
Blocks: with(mdat1, mdat1[, ststri])
Permutation: free
Number of permutations: 999

Terms added sequentially (first to last)

                         Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)    

Nutrient_Treatment 1 2691.4 2691.39 11.5005 0.10518 0.001 ***
Community 3 4726.4 1575.48 6.7321 0.18471 0.004 **
Nutrient_Treatment:Community 3 2023.3 674.43 2.8819 0.07907 0.061 .
Residuals 69 16147.6 234.02 0.63104
Total 76 25588.7 1.00000

Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1

$Press _vs_Pulse
Blocks: with(mdat1, mdat1[, ststri])
Permutation: free
Number of permutations: 999

Terms added sequentially (first to last)

                         Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)    

Nutrient_Treatment 1 3160.3 3160.3 13.0858 0.12270 0.001 ***
Community 3 2050.5 683.5 2.8302 0.07962 0.014 *
Nutrient_Treatment:Community 3 3397.8 1132.6 4.6897 0.13192 0.009 **
Residuals 71 17146.8 241.5 0.66576
Total 78 25755.3 1.00000

Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1

attr(,"class")
[1] "pwadstrata" "list"

Any help is appreciated!

Pairwise adonis test with phyloseq object

Hi,

Thanks so much for your contribution to this function. I would like to perform a pairwise adonis test with phyloseq object and a bray distance matrix but I have some problems when I ran the code in R. My phyloseq object is ps.new.revised. My sample data has nonnumeric character and also NA.

For my question
I am not sure what is the x and factor should be for the pairwise.adonis.

  1. When I input x as sampledf(code: (pairwise.adonis(sampledf,sampledf$Type))), I got this error: Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
    contrasts can be applied only to factors with 2 or more levels.
    When I input x as Permanova_bray (code:pairwise.adonis(Permanova_bray,sampledf$Type)), I got this error: Error in x[factors %in% c(co[1, elem], co[2, elem]), ] :
    incorrect number of dimensions .

I cannot solve my bugs so I am reaching out to you. I will be really appreciate if you can help me figure it out. And I can send you my metadata if you need.

Here are my codes:

Calculate bray curtis distance matrix

Permanova_bray <- phyloseq::distance(ps.new.revised, method = "bray")

make a data frame from the sample_data

sampledf <- data.frame(sample_data(ps.new.revised),row.names = 1:39)
View(sampledf)

#Permanova FI vs. FE vs. Cl vs. UV
adonis(Permanova_bray ~Type , data = sampledf) #p=0.001

Pairwise comparasion to identify which two groups have significant difference

pairwise.adonis <- function(x,factors, sim.method = 'bray', p.adjust.m ='bonferroni')
{
library(vegan)
co = combn(unique(factors),2)
pairs = c()
F.Model =c()
R2 = c()
p.value = c()
for(elem in 1:ncol(co)){
ad = adonis(x[factors %in% c(co[1,elem],co[2,elem]),] ~ factors[factors %in% c(co[1,elem],co[2,elem])] , method =sim.method);
pairs = c(pairs,paste(co[1,elem],'vs',co[2,elem]));
F.Model =c(F.Model,ad$aov.tab[1,4]);
R2 = c(R2,ad$aov.tab[1,5]);
p.value = c(p.value,ad$aov.tab[1,6])
}
p.adjusted = p.adjust(p.value,method=p.adjust.m)
pairw.res = data.frame(pairs,F.Model,R2,p.value,p.adjusted)
return(pairw.res)
}
pairwise.adonis(x,x$Type)

strata not working

Hi Pedro - thanks for this package! Making my analysis a lot more straightforward.

I am having an issue with the strata term in pairwise.adonis2.

My data is diatom relative abundance in 3 reaches with replicate habitats (riffle, run, pool) nested in each reach. My data has no NAs.
Using adonis 2 I set up the blocking by reach and used the community matrix dia_hell_perm from vegdist and had success, code here:

perms <- with(Dia_fac_perm, how(nperm = 1000, blocks = reach))
dia_reach_hab <- adonis2(dia_hell_perm ~ reach + habitat+reach*habitat, data=Dia_fac_perm, permutations = perms, method = "bray")
Dia_fac_perm is a dataframe with my factors (site, position, reach, habitat, habitat_site) all specified as.factors

I have no issues when running the basic pairwise.adonis2(dia_hell_perm ~ habitat+habitat*habitat_site, data=Dia_fac_perm), but I get errors when want to specify strata.

When I run: pairwise.adonis2(dia_hell_perm ~ habitat+habitat*habitat_site, data=Dia_fac_perm, strata ='habitat') I get the error:
Error in if (xi > xj) 1L else -1L : missing value where TRUE/FALSE needed
In addition: Warning message:
In Ops.factor(xi, xj) : ‘>’ not meaningful for factors

Could you advise? Not sure what I'm missing here. Thanks!

References for pairwise.adonis?

Hi. I'm using your pairwise.adonis wrapper for an analysis in a paper that is soon to be published - I'd like to know if you know of any other papers that describe, or have used this function, just for good measure? Thanks!

Interactions on pairwise.adonis2

Hi,
I was trying to use the "pairwise.adonis2" on an interaction of two factors F1 and F2. F1 has 2 levels while F2 has 3 levels. I dont get the results of the function as only calculate F1L1 vs F1L2 without giving information about the levels of F2.
In ?pairwise.adonis2 nothing is explained about the interaction.
Am I missing something? strata?

Thank you
Valentina

> pairwise.adonis2(sqrt(data[5:33]) ~ F1* F2, 
+                  data=data[1:3])
$parent_call
[1] "sqrt(data[5:33]) ~ F1* F2 , strata = Null"

$F1L1_vs_F1L2
Permutation: free
Number of permutations: 999

Terms added sequentially (first to last)

                         Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)    
F1                     1   0.15523 0.15523  7.5476 0.07162  0.001 ***
F2                     2   0.70157 0.35078 17.0560 0.32370  0.001 ***
F1:F2                 2   0.19994 0.09997  4.8607 0.09225  0.001 ***
Residuals         54   1.11059 0.02057         0.51243           
Total                59   2.16732                 1.00000           
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

attr(,"class")
[1] "pwadstrata" "list"

`Error in x1[[2]] <- NULL : replacement has length zero`

Hello, when using the pairWiseAdonis

library(vegan)
library(AICcPermanova)
require(pairwiseAdonis)


# Reading in the data  and preparing the data----

otu_mat <- read.csv("data/OTU_table_Exp2_24hrs.csv")
tax_mat <- read.csv("data/Taxa_Exp_1_2_Cleaned.csv")
samples_df <- read.csv("data/Metadata_Exp2_24hrs.csv")

phy <- make_phyloseq(otu_mat, tax_mat, samples_df)
phy <- make_extra_column(phy)
phy <- prune_taxa(taxa_sums(phy) > 4,
                  phy)

#Check sample variables
sample_variables(physeq = phy)

#Calculate relative counts for Phyloseq
Phy1 <- transform_sample_counts(phy, function(x) x / sum(x) )

phyloseq_filtered  <- filter_taxa(Phy1, function(x) mean(x) > 1e-5, TRUE)

phyloseq_genus_level <- phyloseq_filtered %>%
  aggregate_taxa(level = "Genus") %>%
  microbiome::transform(transform = "compositional")

# Doing the analysis ----
asv <- otu_table(phyloseq_genus_level) |> t()

meta_data <- sample_data(phyloseq_genus_level) |> data.frame()

# Check class of variables in your data
skimr::skim(meta_data) 

### Start modeling ----
# This works
full_model <- adonis2(asv ~ meta_data$col_latin_square*meta_data$row_latin_square,
                    by = "margin")
# Permutation test for adonis under reduced model
#Terms added sequentially (first to last)
# Permutation: free
# Number of permutations: 999

# adonis2(formula = asv ~ meta_data$col_latin_square * # meta_data$row_latin_square)
#                                                       Df SumOfSqs      R2      F Pr(>F)    
# meta_data$col_latin_square                             3   3.2112 0.23132 27.818  0.001 ***
# meta_data$row_latin_square                             2   5.1417 0.37038 66.812  0.001 ***
# meta_data$col_latin_square:meta_data$row_latin_square  6   2.4508 0.17655 10.615  0.001 ***
# Residual                                              80   3.0783 0.22175                  
# Total                                                 91  13.8821 1.00000                  
# ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

ps.dist <- phyloseq::distance(phyloseq_genus_level, method="bray")
ps_norm_df <- as(sample_data(phyloseq_genus_level), "data.frame")

pair_perm <- pairwise.adonis2(distmat ~ col_latin_square,
                               data = meta_data,
                               permutations = 999)
pair_perm

pair_perm <- pairwise.adonis2(as.dist(ps.dist), 
                              ps_norm_df$Treatment)
pair_perm

# Error in x1[[2]] <- NULL : replacement has length zero

Using the pairwise adonis2 function, I get the error # Error in x1[[2]] <- NULL : replacement has length zero. As far as I am aware, I followed your documentation. Could you please explain how I can fix this error? Thank you for your time.

problems installing from github in RStudio

Hi Pedro!

Many thanks for this very useful tool!

I tried to install the library through github using devtools:
library(devtools)
install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis")

but I got the following message:

Skipping install of 'pairwiseAdonis' from a github remote, the SHA1 (c8037b7) has not changed since last install.
Use force = TRUE to force installation

I checked and the version that I had installed was version 0.0.1...

In github it should install version 0.2 right?

version 0.0.1 was giving me errors:

Error during wrapup: contrasts can be applied only to factors with 2 or more levels

I copied the R code into a new script and sourced it in my script and now the function works.

Maybe there is a problem in the installation procedure. I am not a developer, therefore I cannot troubleshoot the issue...

Best regards,

João

Pairwise adonis test with phyloseq object and a unifrac distance matrix?

I would like to perform a pairwise adonis test with phyloseq object and a unifrac distance matrix but I don't know how? Does somebody know if this is possible within this function?

Example:
data(GlobalPatterns)
metadata <- as(sample_data(GlobalPatterns), "data.frame")
dist.uf <- phyloseq::distance(GlobalPatterns, method = "unifrac")
ps.adonis <- adonis(dist.uf ~ SampleType, data = metadata, perm=9999)

SampleType 8 3.4957 0.43696 4.2046 0.66427 1e-04 ***

The adonis test showed that SampleType does explain part of the variation, but I want to know which Samples are different from each other.. With betadisper paired test is easy to perform, but I don't know how to do this within the adonis function with a uf distance matrix?

ps.disper <- betadisper(dist.uf, metadata$SampleType)
permutest(ps.disper, pair=TRUE)

Response: Distances
Df Sum Sq Mean Sq F N.Perm Pr(>F)
Groups 8 0.042397 0.0052996 2.9572 999 0.027 *
Residuals 17 0.030466 0.0017921

Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1

Pairwise comparisons:
image

Error when running pairwise.adonis?

Hello!

I am using the pairwise.adonis package to test an interaction between my two independent variables, Treatment (Placebo vs. Probiotic) and Diet (Standard vs. Western). I've encountered an issue when running the pairwise adonis function, such that I get the error: non-numeric argument to binary operator.

My apologies; I realize this is a coding error, not because of the function. However, I am confused about why I do not get this same error when running the adonis2 command.

Any help or suggestions are much appreciated!

My code:

ps = physeq_rare
#Rarefied phyloseq data

weighted_unifrac = phyloseq::distance(ps, method="unifrac", weighted =T)

adonis2(weighted_unifrac ~ phyloseq::sample_data(ps)$Treatment * phyloseq::sample_data(ps)$Diet)

pairwise.adonis(weighted_unifrac, phyloseq::sample_data(ps)$Treatment * phyloseq::sample_data(ps)$Diet)

Pairwise formula

Hello,
I have a question and unfortunately I am not very familiar with R to understand it directly from the code - how formula was implemented for pairwise comparisons?
For example, I have formula that I want to test: "Factor1 + Factor2 + Factor3". Factor3 contains 3 levels. Pairwise comparisons for Factor3 will be performed with "Factor1 + Factor2 + Factor3" as formula or only with "Factor3"?

Best,

Incorrect number of dimensions pairwise adonis on phyloseq object

Hi,

I keep getting this error and I do not understand it
I have a distance matrix from a phyloseq object and a factor that contains managements, the code is:

dist<-phyloseq::distance(ps5, method = "bray") 

vegan::adonis(dist ~ metadata$manage, permutation = 9999, na.rm=TRUE) 

pairwise.adonis(dist, metadata$manage) 

`

The adonis works but the pairwise.adonis comes back with the error:
Error in x[factors %in% c(co[1, elem], co[2, elem]), ] : incorrect number of dimensions

I don't understand - looking at metadata$manage it's just a normal factor

Stratum not working correctly?

Hello,
Thank you for your efforts in making pairwiseAdonis available.
I've been trying to use the 'stratum' argument to pairwise.adonis, but it isn't working as I'd expect.
e.g.

pairwise.adonis(CountData,factors=Treat,stratum=Site)
Only gives me pairwise comparisons of Treat(ment)s

pairwise.adonis(CountData,factors=paste(Treat,Site),stratum=Site)
Returns pairwise comparisons of ALL Treat:Site combinations, not Treat constrained within Site, as I would expect.
Are my expectations wrong or is there something wrong with the script for stratum?
Thank you!

Issues installing from GitHub

I've installed pairwiseAdonis from the GitHub source. These are the last lines of installation:

* installing *source* package ‘pairwiseAdonis’ ...
** R
** preparing package for lazy loading
Warning: package ‘vegan’ was built under R version 3.4.4
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Warning: package ‘vegan’ was built under R version 3.4.4
* DONE (pairwiseAdonis)

When loading the library I get this error :

Error: package or namespace load failed for ‘pairwiseAdonis’ in get(Info[i, 1], envir = env):
 lazy-load database '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/vegan/R/vegan.rdb' is corrupt
In addition: Warning message:
In get(Info[i, 1], envir = env) : internal error -3 in R_decompress1

Running R 3.4.3, on MacOS, and R-studio 1.1.423

Multiple factors in pairwiseAdonis2

Hi Pedro,

I am looking at fecal microbiota data over multiple days. I have Fecal.ID (8 individuals each sampled for multiple days), SampleDay (which day of the series it was sampled; 6 levels = Day 0, Day 1, etc.), and LifeStage (2 levels = adult or juvenile).

I first ran adonis2:
permS8 <- how(nperm = 999)
setBlocks(permS8) <- with(dfS8, Fecal.ID)
adonis2(bray_S8 ~ SampleDay + LifeStage, data = dfS8, permutations = permS8)

And both SampleDay and LifeStage were significant.

I then ran pairwise.adonis2:
pairwise.adonis2(bray_S8 ~ SampleDay + LifeStage, data = dfS8, strata = 'Fecal.ID')

But I am confused about the interpretation of the output. Here is a small selection of the output:
$parent_call
[1] "bray_S8 ~ SampleDay + LifeStage , strata = Fecal.ID , permutations 999"

$Day 0_vs_Day 1
Df SumOfSqs R2 F Pr(>F)
SampleDay 1 0.4172 0.09366 1.5319 0.007812 **
LifeStage 1 0.4967 0.11152 1.8240 0.007812 **
Residual 13 3.5402 0.79482
Total 15 4.4541 1.00000

For the above output with two factors, does this particular part of the output mean that my Bray Curtis distances (bray_S8) in Day 0 vs Day 1 samples are significantly different by SampleDay (p=0.007812) AND also by Lifestage (p=0.007812)? Meaning the Bray Curtis change between Day 0 and Day 1 was influenced by time (SampleDay) and whether the individual was an adult or a juvenile (LifeStage)?

Thank you for any help you can provide.

restricted permutations does not work

Hello,

I am trying to calculate pariwise comparisons across sites, bust using blocks= so not to shuffle permutations between samples not of the same type. I am having this error below, however it seesm the data is well balanced.

Error in check(sn, control = control, quietly = quietly) : 
  Number of observations and length of Block 'strata' do not match.

I made a test datframe and it is giving the same error (below). Is there something I am interpreting or doing worngly?
Thanks much! Gian

test_data <- data.frame(
  Tree = c(rep(1, times=10),rep(2, times=10), rep(3, times=10), rep(4, times=10)),
  Treatment = factor(c(
    rep("A", each=5), rep("B", each=5), rep("A", each=5), rep("B", each=5),
    rep("A", each=5), rep("B", each=5), rep("A", each=5), rep("B", each=5))),
  Moisture = runif(20*2 , min=20, max=50),
  pH = runif(20*2 , min=4, max=9),
  N = runif(20*2 , min=15, max=100)
)
test_data

table(test_data$Treatment, test_data$Tree) 

pairwise.adonis(test_data[,3:5],
                factors = test_data$Tree,
                sim.function = "vegdist",
                sim.method = "jaccard",
                p.adjust.m = "bonferroni",
                reduce = NULL,
                perm = how(blocks = test_data$Treatment, nperm = 999, observed = TRUE))

This is the error

> pairwise.adonis(test_data[,3:5],
+                 factors = test_data$Tree,
+                 sim.function = "vegdist",
+                 sim.method = "jaccard",
+                 p.adjust.m = "bonferroni",
+                 reduce = NULL,
+                 perm = how(blocks = test_data$Treatment, nperm = 999, observed = TRUE))
Error in check(sn, control = control, quietly = quietly) : 
  Number of observations and length of Block 'strata' do not match.

pairwise.adonis from distance matrix issue

Hello Pedro,

I was trying to do pairwise Adonis from the distance matrix and getting the error message “incorrect number of dimensions”.
...
data(iris)
dist_matrix=vegdist(iris[,1:4],method="euclidean")
pairwise.adonis(dist_matrix,factors=iris$Species,
p.adjust.m='holm')
...
Regards,
Nazmul

Error when installing from Jupyter Notebook on MacOS

I'm trying to install the library from a Jupyter Notebook running on MacOS.
I have already installed devtools.
This is the code I am running

library(devtools)
install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis")
library(pairwiseAdonis)

And this is the output:

Error: Failed to install 'pairwiseAdonis' from GitHub:
  (converted from warning) 'lib = "/Library/Frameworks/R.framework/Versions/3.6/Resources/library"' is not writable
Traceback:

1. install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis")
2. pkgbuild::with_build_tools({
 .     ellipsis::check_dots_used()
 .     remotes <- lapply(repo, github_remote, ref = ref, subdir = subdir, 
 .         auth_token = auth_token, host = host)
 .     install_remotes(remotes, auth_token = auth_token, host = host, 
 .         dependencies = dependencies, upgrade = upgrade, force = force, 
 .         quiet = quiet, build = build, build_opts = build_opts, 
 .         build_manual = build_manual, build_vignettes = build_vignettes, 
 .         repos = repos, type = type, ...)
 . }, required = FALSE)
3. install_remotes(remotes, auth_token = auth_token, host = host, 
 .     dependencies = dependencies, upgrade = upgrade, force = force, 
 .     quiet = quiet, build = build, build_opts = build_opts, build_manual = build_manual, 
 .     build_vignettes = build_vignettes, repos = repos, type = type, 
 .     ...)
4. tryCatch(res[[i]] <- install_remote(remotes[[i]], ...), error = function(e) {
 .     stop(remote_install_error(remotes[[i]], e))
 . })
5. tryCatchList(expr, classes, parentenv, handlers)
6. tryCatchOne(expr, names, parentenv, handlers[[1L]])
7. value[[3L]](cond)

installing pairwiseAdonis

having problem installing pairwiseAdonis, I basically use the command

devtools::install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis")

R does something and returns the following

Downloading GitHub repo pmartinezarbizu/pairwiseAdonis@master

checking for file 'C:\Users\jrferreira\AppData\Local\Temp\Rtmp4Apu0C\remotes1fa06709434f\pmartinezarbizu-pairwiseAdonis-af50233\pairwiseAdonis/DESCRIPTION' ...

checking for file 'C:\Users\jrferreira\AppData\Local\Temp\Rtmp4Apu0C\remotes1fa06709434f\pmartinezarbizu-pairwiseAdonis-af50233\pairwiseAdonis/DESCRIPTION' ...

√ checking for file 'C:\Users\jrferreira\AppData\Local\Temp\Rtmp4Apu0C\remotes1fa06709434f\pmartinezarbizu-pairwiseAdonis-af50233\pairwiseAdonis/DESCRIPTION' (1.2s)

  • preparing 'pairwiseAdonis':
    checking DESCRIPTION meta-information ...

    checking DESCRIPTION meta-information ...

√ checking DESCRIPTION meta-information

  • checking for LF line-endings in source and make files and shell scripts

  • checking for empty or unneeded directories

  • building 'pairwiseAdonis_0.0.1.tar.gz'

Error: Failed to install 'pairwiseAdonis' from GitHub:
(converted from warning) package ‘pairwiseAdonis’ is in use and will not be installed

any help is welcomed

Can't install package

Hello people,
I am new to R and I am trying to install the pairwiseAdonis package for a school project. However, I keep getting the following error message:

** using staged installation
** R
** byte-compile and prepare package for lazy loading
Error: package 'vegan' required by 'pairwiseAdonis' could not be found
Execution halted
ERROR: lazy loading failed for package 'pairwiseAdonis'

  • removing 'C:/Users/julie/Documents/R/win-library/3.6/pairwiseAdonis'
    Error: Failed to install 'pairwiseAdonis' from GitHub:

There seems to be an issue with installing 'vegan'. Could you suggest what I can do to solve this?

Thank you!

pairwise.adonis2 strata issue

Hi Pedro,

I've been using your package for a few years and have had success using pairwise.adonis2 with strata.

I'm currently running the following versions:
R 4.1.3
pairwiseAdonis v 0.4

This is the code I'm having issues with:
pairwise.adonis2(brayDist ~ UniqueSampleDay, data = df, strata = 'Series.ID')

Recently when I tried to use it, I keep getting this error:

'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
'nperm' >= set of all permutations: complete enumeration.
Set of permutations < 'minperm'. Generating entire set.
Warning in seq_len(nrow(i)) :
  first element used of 'length.out' argument
Error in seq_len(nrow(i)) : 
  argument must be coercible to non-negative integer

To create my distance matrix I used:
brayDist <- phyloseq::distance(df, "bray")

Here is a link to my df and dist file

This is my traceback if that is helpful:

 1: pairwise.adonis2(brayDist ~ SampleDay, data = df, strata = "Series.I
 2: adonis2(xnew, data = mdat1, permutations = perm, ...)
 3: getPermuteMatrix(permutations, NROW(data), strata = strata)
 4: shuffleSet(N, control = perm)
 5: check(sn, control = control, quietly = quietly)
 6: allPerms(N, control = control, check = FALSE)
 7: cbindAllPerms(out)
 8: do.call(expand.grid, lapply(x, function(i) seq_len(nrow(i))))
 9: lapply(x, function(i) seq_len(nrow(i)))
10: FUN(X[[i]], ...)

Thank you in advance for your help!

Sincerely,
Morgan

missing value where TRUE/FALSE needed

Dear Pedro,

I am getting this error

Error in if (any(lhs < -TOL)) stop("dissimilarities must be non-negative") : 
  missing value where TRUE/FALSE needed

when executing this line of code

pairwise.adonis(x=cont_nest,factors=metadata$Treatment,sim.function='daisy',sim.method='manhattan',p.adjust.m='bonferroni')

Do you have any idea what could be wrong?

Thank you very much in advance.

Kind regards,
Stijn

Does pairwise.adonis2 adjust p-vals?

Hi,

I was reading the man page for your function. I noticed that the first iteration of pairwise.adonis has adjustment of p-value for multiple comparisons. This isn't mentioned in the notes for pairwise.adonis2. The output seems to suggest that it is a raw, uncorrected p-value. I just wanted to double check if that was the case, and we need to follow up with p-value correction?

degrees of freedom

2 months ago
Joana Sabino Pinto
Added an answer
Hello,
I have a related issue with the pairwise.adonis funcion.
The function works perfectly, but the output table does not have degrees of freedom. I can calculate them by hand, but would like to know if there is something in the function I'm missing.
Cheers,
Joana

output is not giving any adjusted/ unadjusted p- values

Initially, I thought this is not working. But, after a while the code actually worked. Here, x = distance matrix and factors = a categorical variable of my dataset. Thanks!

a <- pairwise.adonis(ps_allvend_ctrl_wunifrac, metadata_ps.prop_allvend_ctrl$vendor)
output:

a
pairs F.Model R2 p.value p.adjusted sig
1 A vs B 170.73522 0.9552411 0.008 0.024 .
2 A vs C 164.43186 0.9536049 0.010 0.030 .
3 B vs C 18.19769 0.6946296 0.011 0.033 .

pairwise.adonis2 output: adjusted p vals?

Hi Pedro,

Data overview: I am measuring beta diversity metrics (ex. Bray Curtis) for fecal samples from 6 individuals (Fecal.ID) collected at different time points (SampleDay).

bray_S6 <- phyloseq::distance(S6, "bray")

First I defined my permutation blocks by individual (Fecal.ID) for the PERMANOVA
permS6 <- how(nperm = 999)
setBlocks(permS6) <- with(dfS6, Fecal.ID)
adonis2(bray_S6 ~ SampleDay, data = dfS6, permutations = permS6)

I am using pairwise.adonis2 function to check the pairwise comparisons between day 0 and the other sample days. Ex. Is day 0 different from day 1? Is day 0 different from day 2? Etc.

_pairwise.adonis2(bray_S6 ~ SampleDay, data = dfS6, strata = 'Fecal.ID')_

The output looks like this (only with many more comparisons):

[1] "bray_S6 ~ SampleDay , strata = Fecal.ID"

$Day 0_vs_Day 1
Blocks: with(mdat1, mdat1[, ststri])
Permutation: free
Number of permutations: 63

Terms added sequentially (first to last)

 Df           SumsOfSqs           MeanSqs      F.Model     R2              Pr(>F)  
SampleDay  1      0.4961         0.49610      1.9636     0.16413       0.03125 *
Residuals   10    2.5265          0.25265      0.83587          
Total     11    3.0226      1.00000          
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

.
.
.
etc.

QUESTION: Is this pairwise.adonis2 p-value (0.03125) adjusted? If yes, is there a way to get the unadjusted value?

Extra question: Is there a way to reduce or restrict the pairwise comparisons in pairwise.adonis2 to only the comparisons I'm interested in? Ex. Restrict to only comparing Day 0 to every other day and NOT comparing Day 1 to Day 2, 3, 4, etc? I know this can be done in pairwise.adonis with reduce = "Day 0" but I did not see this function for pairwise.adonis2.

Thank you!

Exporting pairwise adonis results

Hi, is there an easy way to export the results of pairwise.adonis into excel without altering the format? I have tried using data.frame and sapply but neither have worked. Any help would be greatly appreciated!

ph2 <- pairwise.adonis2(benthic_counts.db ~ Site, data = meta)

error installing pairwiseAdonis

Hi there,

I've been trying to install pairwiseAdonis and keep getting the same error:

install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis")
Skipping install of 'pairwiseAdonis' from a github remote, the SHA1 (cb190f7) has not changed since last install.
Use force = TRUE to force installation

When I included the force = TRUE, it seemed to install

install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis", force = TRUE)
Downloading GitHub repo pmartinezarbizu/pairwiseAdonis@HEAD
── R CMD build ────────────────────────────────────────────────────────────────────────────────────
✔ checking for file ‘/tmp/RtmpZSkZk6/remotes1575b7932eb4/pmartinezarbizu-pairwiseAdonis-cb190f7/pairwiseAdonis/DESCRIPTION’ (377ms)
─ preparing ‘pairwiseAdonis’:
✔ checking DESCRIPTION meta-information
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
Omitted ‘LazyData’ from DESCRIPTION
─ building ‘pairwiseAdonis_0.4.1.tar.gz’
Warning: invalid uid value replaced by that for user 'nobody'

Installing package into ‘/home/donnelly.b/R/x86_64-pc-linux-gnu-library/4.3’
(as ‘lib’ is unspecified)

  • installing source package ‘pairwiseAdonis’ ...
    ** using staged installation
    ** R
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded from temporary location
    ** testing if installed package can be loaded from final location
    ** testing if installed package keeps a record of temporary installation path
  • DONE (pairwiseAdonis)

But when I went to run the function, I get this

TSApairwise_results <- pairwiseAdonis(TSARNAasvs_dist_adonis_year)
Error in pairwiseAdonis(TSARNAasvs_dist_adonis_year) :
could not find function "pairwiseAdonis"

Any advice on getting this sorted?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.