install.packages("ade4")
library(ade4)
有个例子给你参考下——
ozone<-read.table("http://www.ats.ucla.edu/stat/r/faq/ozone.csv", sep=",", header=T)
head(ozone, n=10)
Station Av8top Lat Lon
1 60 7.225806 34.13583 -117.9236
2 69 5.899194 34.17611 -118.3153
3 72 4.052885 33.82361 -118.1875
4 74 7.181452 34.19944 -118.5347
5 75 6.076613 34.06694 -117.7514
6 84 3.157258 33.92917 -118.2097
7 85 5.201613 34.01500 -118.0597
8 87 4.717742 34.06722 -118.2264
9 88 6.532258 34.08333 -118.1069
10 89 7.540323 34.38750 -118.5347
station.dists <- dist(cbind(ozone$Lon, ozone$Lat))
ozone.dists <- dist(ozone$Av8top)
as.matrix(station.dists)[1:5, 1:5]
1 2 3 4 5
1 0.0000000 0.3937326 0.4088031 0.6144127 0.1854888
2 0.3937326 0.0000000 0.3749446 0.2206810 0.5743590
3 0.4088031 0.3749446 0.0000000 0.5116772 0.4994034
4 0.6144127 0.2206810 0.5116772 0.0000000 0.7944601
5 0.1854888 0.5743590 0.4994034 0.7944601 0.0000000
as.matrix(ozone.dists)[1:5, 1:5]
1 2 3 4 5
1 0.000000 1.326612 3.172921 0.044354 1.149193
2 1.326612 0.000000 1.846309 1.282258 0.177419
3 3.172921 1.846309 0.000000 3.128567 2.023728
4 0.044354 1.282258 3.128567 0.000000 1.104839
5 1.149193 0.177419 2.023728 1.104839 0.000000
mantel.rtest(station.dists, ozone.dists, nrepet = 9999)
Monte-Carlo test
Observation: 0.1636308
Call: mantel.rtest(m1 = station.dists, m2 = ozone.dists, nrepet = 9999)
Based on 9999 replicates
Simulated p-value: 0.0312