MantelCor: Compare matrices via Mantel Correlation

MantelCorR Documentation

Compare matrices via Mantel Correlation

Description

Calculates correlation matrix correlation and significance via Mantel test.

Usage

MantelCor(cor.x, cor.y, ...)

## Default S3 method:
MantelCor(
  cor.x,
  cor.y,
  permutations = 1000,
  ...,
  landmark.dim = NULL,
  withinLandmark = FALSE,
  mod = FALSE
)

## S3 method for class 'list'
MantelCor(
  cor.x,
  cor.y = NULL,
  permutations = 1000,
  repeat.vector = NULL,
  parallel = FALSE,
  ...
)

## S3 method for class 'mcmc_sample'
MantelCor(cor.x, cor.y, ..., parallel = FALSE)

MatrixCor(cor.x, cor.y, ...)

## Default S3 method:
MatrixCor(cor.x, cor.y, ...)

## S3 method for class 'list'
MatrixCor(
  cor.x,
  cor.y = NULL,
  permutations = 1000,
  repeat.vector = NULL,
  parallel = FALSE,
  ...
)

## S3 method for class 'mcmc_sample'
MatrixCor(cor.x, cor.y, ..., parallel = FALSE)

Arguments

cor.x

Single correlation matrix or list of correlation matrices.

If single matrix is supplied, it is compared to cor.y.

If list is supplied and no cor.y is supplied, all matrices are compared.

If cor.y is supplied, all matrices in list are compared to it.

cor.y

First argument is compared to cor.y. Optional if cor.x is a list.

...

additional arguments passed to other methods

permutations

Number of permutations used in significance calculation.

landmark.dim

Used if permutations should be performed maintaining landmark structure in geometric morphometric data. Either 2 for 2d data or 3 for 3d data. Default is NULL for non geometric morphomotric data.

withinLandmark

Logical. If TRUE within-landmark correlations are also used in the calculation of matrix correlation (all lower triangle elements are used). Only used if landmark.dim is passed, default is FALSE.

mod

Set TRUE to use mantel in testing modularity hypothesis. Should only be used in MantelModTest.

repeat.vector

Vector of repeatabilities for correlation correction.

parallel

if TRUE computations are done in parallel. Some foreach back-end must be registered, like doParallel or doMC.

Details

MantelCor computes the Pearson correlation between the elements of the lower triangles (excluding the diagonal) of the two matrices. Its significance comes from a permutation test: the rows and columns of cor.x are permuted together, the correlation with cor.y is recomputed for each permutation, and these correlations form the null distribution. The p-value (reported as Probability) is (sum(null >= observed) + 1)/(permutations + 1), so it is never 0. Values equal to the observed correlation up to floating point error count as equal. If there are fewer than 5040 distinct permutations (7 traits or fewer), or more permutations are requested than exist, all distinct permutations (without the identity) are enumerated instead of sampled; if there are more of them than permutations, a random subset of that size is used, and the number of permutations in the formula above is the number actually used.

If landmark.dim is given, the traits are grouped in landmarks of 2 or 3 consecutive coordinates, and the permutations shuffle whole landmarks (keeping the coordinates of a landmark together); these permutations are always sampled at random. By default (withinLandmark = FALSE) only correlations between traits of different landmarks are used, both for the observed correlation and for the null distribution. With withinLandmark = TRUE all elements of the lower triangle are used, including those between coordinates of the same landmark (the diagonal is always excluded).

If cor.x and cor.y are mcmc_sample objects, the i-th sample of each is compared, and a vector with one value per sample is returned (both are converted to correlations with cov2cor).

Value

If cor.x and cor.y are passed, returns matrix Pearson correlation coefficient and significance via Mantel permutations.

If cor.x is a list of matrices and cor.y is passed, same as above, but for all matrices in cor.x.

If only cor.x is passed, a matrix of MantelCor average values and probabilities of all comparisons. If repeat.vector is passed, comparison matrix is corrected above diagonal and repeatabilities returned in diagonal.

Note

If the significance is not needed, MatrixCor provides the correlation and skips the permutations, so it is much faster.

Author(s)

Diogo Melo, Guilherme Garcia

References

Mantel, N. (1967). The detection of disease clustering and a generalized regression approach. Cancer Research 27(2): 209-220.

See Also

KrzCor,RandomSkewers,RandomSkewers,TestModularity, MantelModTest

Examples

c1 <- RandomMatrix(10, 1, 1, 10)
c2 <- RandomMatrix(10, 1, 1, 10)
c3 <- RandomMatrix(10, 1, 1, 10)
MantelCor(cov2cor(c1), cov2cor(c2))

cov.list <- list(c1, c2, c3)
cor.list <- lapply(list(c1, c2, c3), cov2cor)

MantelCor(cor.list)

# For repeatabilities we can use MatrixCor, which skips the significance calculation
reps <- unlist(lapply(cov.list, MonteCarloRep, 10, MatrixCor, correlation = TRUE))
MantelCor(cor.list, repeat.vector = reps)

c4 <- RandomMatrix(10)
MantelCor(cor.list, c4)

## Not run: 
#Multiple threads can be used with some foreach backend library, like doParallel or doMC
library(doParallel)
registerDoParallel(cores = 2)
MantelCor(cor.list, parallel = TRUE)

## End(Not run)

evolqg documentation built on Nov. 29, 2026, 1:08 a.m.

Related to MantelCor in evolqg...