xdistance {ecodist} | R Documentation |

Pairwise dissimilarity calculation between rows of one dataset and rows of another, for instance across different sampling periods for the same set of sites.

```
xdistance(x, y, method = "euclidean")
```

`x` |
A site by species or other matrix or data frame. |

`y` |
A a second site by species dataset, which must have at least the same columns. |

`method` |
This function calls |

This function will calculate rowwise dissimilarities between any pair of matrices or data frames with the same number of columns. Note that the cross-dissimilarity functions are for research purposes, and are not well-tested.

A non-symmetric and possibly not square matrix of dissimilarities of class `xdist`

, where `result <- xdistance(x, y)`

produces a matrix with `result[a, b]`

containing the dissimilarity between `x[a, ]`

and `y[b, ]`

.

Sarah Goslee

```
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))
```

[Package *ecodist* version 2.0.9 Index]