Learn R Programming

ncf (version 1.1-1)

mantel.test: Mantel Test

Description

A simple function to do a permutation-based Mantel test. The data can either be two distance/similarity matrices or {x, y, z} data.

Usage

mantel.test(M1 = NULL, M2 = NULL, x = NULL, y = NULL, z = NULL,
    resamp = 1000, latlon = FALSE)

Arguments

M1, M2
similarity/distance matrix 1, and similarity/distance matrix 2
x
vector of length n representing the x coordinates (or longitude; see latlon).
y
vector of length n representing the y coordinates (or latitude).
z
matrix of dimension n x p representing p observation at each location.
resamp
the number of resamples for the null distribution.
latlon
if TRUE, coordinates are latitude and longitude.

Value

  • An object of class "Mantel" is returned, consisting of a list with two components:
  • correlationis the value for the Mantel correlation.
  • pthe randomization-based two-sided p-value.

Details

Typical usages are mantel.test(M1, M2, x = NULL, y = NULL, z = NULL, resamp = 1000, latlon = FALSE) mantel.test(x, y, z, M1=NULL, M2=NULL, resamp = 1000, latlon = FALSE) Missing values are are treated through pairwise deletion.

Examples

Run this code
#first generate some sample data
    x <- expand.grid(1:20, 1:5)[,1]
    y <- expand.grid(1:20, 1:5)[,2]
#z data from an exponential random field
    z <- cbind(
        rmvn.spa(x=x, y=y, p=2, method="exp"),
        rmvn.spa(x=x, y=y, p=2, method="exp")
        )

#the Mantel test
    mantel.test(x=x, y=y, z=z[,1], resamp=10)

Run the code above in your browser using DataLab