# vegan包及数据说明

Mantel tests是确定两组距离测度矩阵（而非两组变量矩阵）之间相关性的相关性测试方法，用于判断一个矩阵中的样本距离与另一矩阵中的样本距离是否相关。Mantel tests零假设为响应变量矩阵中对象之间的距离与解释变量矩阵不存在相关，如果结果中p值显著，则拒绝零假设，即存在相关性，随着一个矩阵中样本之间距离的增加（或减少），另一矩阵中对应样本之间的距离也增加（或减少）。

``````install.packages("vegan")#安装包
library(vegan)#加载包
``````

``````data(varespec);varespec
data(varechem);varechem
``````

# 分别计算距离矩阵

``````vegdist(x, method="bray", binary=FALSE, diag=FALSE, upper=FALSE,
na.rm = FALSE, ...)
``````

method= “manhattan”, “euclidean”, “canberra”, “clark”, “bray”, “kulczynski”, “jaccard”, “gower”, “altGower”, “morisita”, “horn”, “mountford”, “raup”, “binomial”, “chao”, “cao”, “mahalanobis”, “chisq”, “chord”, “aitchison”, or “robust.aitchison”.

``````veg.dist <- vegdist(varespec))# Bray-Curtis
env.dist <- vegdist(scale(varechem), "euclid")#首先标准化在进行计算
``````

# 相关性分析

mantel函数进行相关性分析，mantel.partial函数进行偏相关性分析

``````mantel(xdis, ydis, method="pearson", permutations=999, strata = NULL,
na.rm = FALSE, parallel = getOption("mc.cores"))
mantel.partial(xdis, ydis, zdis, method = "pearson", permutations = 999,
strata = NULL, na.rm = FALSE, parallel = getOption("mc.cores"))
``````

``````mantel(veg.dist, env.dist, method="spear")
``````

THE END