# Need to develop a cross-dissimilarity example
data(graze)
### EXAMPLE 1: Square matrices
# take two subsets of sites with different dominant grass abundances
# use cut-offs that produce equal numbers of sites
dom1 <- subset(graze, POPR > 50 & DAGL < 20) # 8 sites
dom2 <- subset(graze, POPR < 50 & DAGL > 20) # 8 sites
# first two columns are site info
dom.xd <- xdistance(dom1[, -c(1,2)], dom2[, -c(1,2)], "bray")
# environmental and spatial distances; preserve rownames
forest.xd <- xdistance(dom1[, "forestpct", drop=FALSE],
dom2[, "forestpct", drop=FALSE])
sitelocation.xd <- xdistance(dom1[, "sitelocation", drop=FALSE],
dom2[, "sitelocation", drop=FALSE])
# permutes rows and columns of full nonsymmetric matrix
xmantel(dom.xd ~ forest.xd)
xmantel(dom.xd ~ forest.xd + sitelocation.xd)
plot(xmgram(dom.xd, sitelocation.xd))
### EXAMPLE 2: Non-square matrices
# take two subsets of sites with different dominant grass abundances
# this produces a non-square matrix
dom1 <- subset(graze, POPR > 45 & DAGL < 20) # 13 sites
dom2 <- subset(graze, POPR < 45 & DAGL > 20) # 8 sites
# first two columns are site info
dom.xd <- xdistance(dom1[, -c(1,2)], dom2[, -c(1,2)], "bray")
# environmental and spatial distances; preserve rownames
forest.xd <- xdistance(dom1[, "forestpct", drop=FALSE],
dom2[, "forestpct", drop=FALSE])
sitelocation.xd <- xdistance(dom1[, "sitelocation", drop=FALSE],
dom2[, "sitelocation", drop=FALSE])
# permutes rows and columns of full nonsymmetric matrix
xmantel(dom.xd ~ forest.xd, dims=c(13, 8))
xmantel(dom.xd ~ forest.xd + sitelocation.xd, dims=c(13, 8))
plot(xmgram(dom.xd, sitelocation.xd))
Run the code above in your browser using DataLab