Reproducing q2-diversity mantel in R

Continuing the discussion from Retaining mantel test output data:

Hi,

Sorry for the naive questions but I wanted to reproduce the plot in R so I can label the plots but I have some questions:

  1. I read that the mantel test qiime 2 implements is the skbio.stats.distance.mantel function in python, which is similar to vegan::mantel. I tried doing mantel test in R (from the vegan library) on a pair of distance matrices I exported from qiime 2 and the p values I got were off:

WUnifxMetadata1

In qiime 2 (2019.1)
Mantel test results
Method: Spearman
Sample size: 14
Permutations: 999
Alternative hypothesis: two-sided
Spearman rho: -0.0915592
p-value: 0.548

In R:
Call:
mantel(xdis = distmat_wunif, ydis = distmat_metadata1, method = “spearman”, permutations = 999)

**Mantel statistic r: -0.2183 **
**Significance: 0.982** 

Upper quantiles of permutations (null model):
  90%   95% 97.5%   99% 
0.212 0.292 0.365 0.428 
Permutation: free
Number of permutations: 999

WUnifxMetadata2

In qiime 2 (2019.1):
Mantel test results
Method: Spearman
Sample size: 14
Permutations: 999
Alternative hypothesis: two-sided
Spearman rho: 0.531181
p-value: 0.021

In R:
Call:
mantel(xdis = distmat_wunif, ydis = distmat_metadata2, method = “spearman”, permutations = 999)

**Mantel statistic r: -0.2216 **
**Significance: 0.871** 

Upper quantiles of permutations (null model):
  90%   95% 97.5%   99% 
0.304 0.379 0.480 0.551 
Permutation: free
Number of permutations: 999

1b. In my results from qiime 2 I see some metadata measures with weak to moderate correlation (around 0.25-0.5) but whose p value is highly significant (p < 0.025 or less)-- how do I interpret results like these?

  1. I wanted to reproduce the scatter plot produced in qiime 2 in R; do I understand it correctly that the visualization in qiime 2 is just a correlation plot between the values from the two measures (e.g., beta-diversity and numeric metadata)? That means that each point in the plot represents a pairing of distances (betadivdistAB-metadatadistAB, betadivdistAB-metadatadistAC; given samples A, B, C… etc).
  • Can I please ask help how I may be able to do this starting from the two distance matrices? There were some directions in the post I linked but I didn’t really get it.

  • Will it make sense to want to color these data points by a metadata category given that these represent pairs instead of individual samples (I wanted to see if the plots with significant correlation show grouping by metadata category, in which case it would make sense to re-do the mantel test on a subgroup)?

Hi @ange,

You should double-check to make sure your distance matrices have sample IDs in the same order. My guess is the orders may be off, which is why you are getting a significant result with QIIME 2 (it takes care of ordering samples for you) but insignificant with R.

0.25-0.5 seems like a decent if weak correlation. The P value is determined by permutation — so the significant result is indicating that there is a weak but significant association between these two distance matrices.

Yes

You will need to get this from the distance matrices themselves. I cannot really give specific guidance on how you would do this in R.

Right, since these are pairs you can’t really color by metadata. I suppose you could figure out another scheme (e.g., color by a metadata column if both samples have the same metadata value, color another way if the samples do not share the same value)

Good luck!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.