Example of Mantel test to compare dissimilatry matrices
A Mantel test measures the correlation between two matrices typically containing measures of distance. A Mantel test is one way of testing for spatial autocorrelation.
Example of R code:
library("vegan")
library("fields")
library("sp")
# Random points
points <- as.matrix(data.frame(longitude=rnorm(20, 3, 2), latitude=rnorm(20, 23, 2)))
caracteristiques <- rnorm(20, 12, 3)
plot(x=points[,"longitude"], y=points[, "latitude"], pch=19, cex=2*caracteristiques/max(caracteristiques))
# matrice des distances euclidiennes de caractéristiques
disC <- rdist(x1=caracteristiques)
# Matrice de distances entre les points basée sur la distance terrestre
disL <- spDists(x=points, longlat = TRUE)
plot(disL, disC)
MT <- mantel(xdis=disC, ydis=disL, method="pearson", permutations=999)
MT
# Generate relationship
caracteristiques <- rnorm(20, points[,"latitude"]*points[,"longitude"], 3)
plot(x=points[,"longitude"], y=points[, "latitude"], pch=19, cex=2*caracteristiques/max(caracteristiques))
# matrice des différences de caractéristiques
disC <- rdist(x1=caracteristiques)
disL <- spDists(x=points, longlat = TRUE)
plot(disL, disC)
MT <- mantel(xdis=disC, ydis=disL, method="pearson", permutations=999)
MT
# With the package ape
library("ape")
MT <- mantel.test(m1=disC, m2=disL, nperm = 999, graph = TRUE)
Example of R code:
library("vegan")
library("fields")
library("sp")
# Random points
points <- as.matrix(data.frame(longitude=rnorm(20, 3, 2), latitude=rnorm(20, 23, 2)))
caracteristiques <- rnorm(20, 12, 3)
plot(x=points[,"longitude"], y=points[, "latitude"], pch=19, cex=2*caracteristiques/max(caracteristiques))
# matrice des distances euclidiennes de caractéristiques
disC <- rdist(x1=caracteristiques)
# Matrice de distances entre les points basée sur la distance terrestre
disL <- spDists(x=points, longlat = TRUE)
plot(disL, disC)
MT <- mantel(xdis=disC, ydis=disL, method="pearson", permutations=999)
MT
# Generate relationship
caracteristiques <- rnorm(20, points[,"latitude"]*points[,"longitude"], 3)
plot(x=points[,"longitude"], y=points[, "latitude"], pch=19, cex=2*caracteristiques/max(caracteristiques))
# matrice des différences de caractéristiques
disC <- rdist(x1=caracteristiques)
disL <- spDists(x=points, longlat = TRUE)
plot(disL, disC)
MT <- mantel(xdis=disC, ydis=disL, method="pearson", permutations=999)
MT
# With the package ape
library("ape")
MT <- mantel.test(m1=disC, m2=disL, nperm = 999, graph = TRUE)
Commentaires
Enregistrer un commentaire