[R] Perform mantel test on subset of distance matrix

Sarah Goslee sarah.goslee at gmail.com
Thu Jan 18 21:42:14 CET 2018

Hi Andrew,

Yes, you cannot have NA values in your matrices.
Instead, you could incorporate a model matrix.

See Legendre, P. & Fortin, M.J. Vegetatio (1989) 80: 107.
for ideas.


On Sun, Dec 31, 2017 at 12:55 PM, Andrew Marx <andrewjmarx at gmail.com> wrote:
> I'm trying to perform a mantel test that ignores specific pairs in my
> distance matrices. The reasoning is that some geographic distances
> below a certain threshold suffer from spatial autocorrelation, or
> perhaps ecological relationships become less relevant that stochastic
> processes above a certain threshold.
> The problem is that I can't find a way to do it. If I replace values
> in either or both of the distance matrices with NA, mantel.rtest (ade4
> package) gives the following error: Error in if (any(distmat < tol))
> warning("Zero distance(s)") : missing value where TRUE/FALSE needed
> Here's a trivial example that tries to exclude elements of the first
> matrix that equal 11:
> library(ade4)
> a <- matrix(data = 1:36, nrow = 6)
> b <- matrix(data = 1:36, nrow = 6)
> a[a==11] <- NA
> mantel.rtest(as.dist(a), as.dist(b))
> Is there a way to do this, either with this package or another?

Sarah Goslee

More information about the R-help mailing list