I'm trying to run Partial Mantel tests using R vegan package. I'm getting the following error in the output even on a very simple dummy data.
My code:
m1 = matrix(c(0, 1, 2,
1, 0, 3,
2, 3, 0),nrow = 3)
m2 = m1 * 2
m3 = m1 * 3
mtest = mantel.partial(xdis = m1, ydis = m2,zdis = m3)
print(mtest)
The output:
Partial Mantel statistic based on Pearson product-moment correlation
Call:
mantel.partial(xdis = m1, ydis = m2, zdis = m3)
Mantel statistic r: NaN
Significance: NA
Error in quantile.default(x$perm, c(0.9, 0.95, 0.975, 0.99)) :
missing values and NaN's not allowed if 'na.rm' is FALSE
The example matrices are linearly dependent; m2
is a simple linear transformation of m1
so they are perfectly correlated. As is m3
. Once you account for the correlation between one pair of matrices, there is nothing left over to correlate with, hence the weird NaN
s and NA
s and the ultimate error.