# \donttest{
tamiasEPM <- addPhylo(tamiasEPM, tamiasTree)
tamiasEPM <- addTraits(tamiasEPM, tamiasTraits)
# An example using a multivariate dataset
## For each focal cell + neighbors, calculate the morphological standard deviation
## per grid cell and return the standard deviation.
f <- function(cellList) {
vec <- numeric(length(cellList))
for (i in 1:length(cellList)) {
vec[[i]] <- max(dist(dat[cellList[[i]], ]))
}
return(sd(vec, na.rm = TRUE))
}
xx <- customBetaDiv(tamiasEPM, fun = f, radius = 70000, minTaxCount = 2, metricName = 'maxdist')
# An example using only the phylogeny.
## Calculate standard deviation of phylogenetic diversity across cell neighborhood.
f <- function(cellList) {
vec <- numeric(length(cellList))
for (i in 1:length(cellList)) {
vec[[i]] <- faithPD(phylo, cellList[[i]])
}
return(sd(vec, na.rm = TRUE))
}
xx <- customBetaDiv(tamiasEPM, fun = f, radius = 70000, minTaxCount = 1, metricName = 'faithPD')
# an example that involves both morphological and phylogenetic data
## nonsensical, but for illustrative purposes:
## ratio of Faith's phylogenetic diversity to morphological range
## the standard deviation of this measure across grid cells
## in a neighborhood.
f <- function(cellList) {
vec <- numeric(length(cellList))
for (i in 1:length(cellList)) {
vec[[i]] <- faithPD(phylo, cellList[[i]]) /
max(dist(dat[cellList[[i]], ]))
}
return(sd(vec, na.rm = TRUE))
}
xx <- customBetaDiv(tamiasEPM, fun = f, radius = 70000, minTaxCount = 2,
metricName = 'ratio_PD_maxdist')
# from a focal coordinate to all other sites
## Here, the function has 2 inputs.
## Example: calculate the per grid cell mean and take the distance.
f <- function(focalCell, otherCell) {
x1 <- colMeans(dat[focalCell, ])
x2 <- colMeans(dat[otherCell, ])
return(as.matrix(dist(rbind(x1, x2)))[1,2])
}
xx <- customBetaDiv(tamiasEPM, fun = f, radius = 70000, minTaxCount = 1,
focalCoord = c(-1413764, 573610.8), metricName = 'meandist')
# Example involving a set of trees
tamiasEPM <- addPhylo(tamiasEPM, tamiasTreeSet, replace = TRUE)
## Calculate standard deviation of phylogenetic diversity across cell
## neighborhood.
f <- function(cellList) {
vec <- numeric(length(cellList))
for (i in 1:length(cellList)) {
vec[[i]] <- faithPD(phylo, cellList[[i]])
}
return(sd(vec, na.rm = TRUE))
}
# This time, a list of sf objects will be returned, one for each input tree.
xx <- customBetaDiv(tamiasEPM, fun = f, radius = 70000, minTaxCount = 1,
metricName = 'faithPD')
# also works with square grid cells
tamiasEPM2 <- createEPMgrid(tamiasPolyList, resolution = 50000,
cellType = 'square', method = 'centroid')
tamiasEPM2 <- addPhylo(tamiasEPM2, tamiasTree)
tamiasEPM2 <- addTraits(tamiasEPM2, tamiasTraits)
f <- function(cellList) {
vec <- numeric(length(cellList))
for (i in 1:length(cellList)) {
vec[[i]] <- faithPD(phylo, cellList[[i]]) /
max(dist(dat[cellList[[i]], ]))
}
return(sd(vec, na.rm = TRUE))
}
xx <- customBetaDiv(tamiasEPM2, fun = f, radius = 70000, minTaxCount = 2,
metricName = 'ratio_PD_maxdist')
# }
Run the code above in your browser using DataLab