## Example 1. A simmulated community matrix with a known structure of increasing
## beta diversity by turnover
# n is the total sample sites
# LocS is the number of spp per site
# MaxS is the total number of spp in the matrix
# All samples will contain LocS species. The first sample will contain presences
# for the first LocS species. The subsequent samples will contain LocS presences
# spread over a increasing set of species. The assignment of presences for the
# second sample to the last sample is done randomly. The last sample will
# contain LocS presences assigned randomly to the MaxS species. Thus, for a
# window size of 3 (ws=3) and a dataset of 10 samples, beta diversity for the
# samples 1-3 will be much lower than for samples 8-10.
SimComm <- function(n = 19, MaxS = 24, LocS = 8){
s <- seq (LocS, MaxS, length.out = n)
mat <- matrix(0, n, MaxS, dimnames =
list(paste("site", 1:n, sep = "_"),
paste("sp", 1:MaxS, sep = "_")))
for(i in 1:n){
mat[i, sample(1:s[i], LocS)] <- 1
}
mat <- mat[, colSums(mat)!=0]
return(mat)
}
mat <- SimComm(n = 19, MaxS = 24, LocS = 8)
#Creating an environmental gradient:
grad <- 1:nrow(mat)
b.resu <- betaRegDisp(y = mat, x = grad, xy.coord = NULL, ws = 3,
method.1 = "jaccard",
method.2 = "ruzicka",
method.3 = "ruzicka",
independent.data = FALSE, illust.plot = FALSE)
##Ploting all the output of the object for the simmulated community
op <- par(no.readonly = TRUE)
par(mfrow = c(5, 2), oma = c(1, 0, 1, 0.1), mar = c(1.5, 3, .1, .1), cex = 1, las = 0)
for(i in 1:ncol(b.resu)){
plot(b.resu[, 1], b.resu[, i], ylab = colnames(b.resu)[i], cex.lab = .9,
cex.axis = 0.9, tcl = -0.2, mgp = c(1.5, .2, 0), pch = 15, col = "grey")
}
mtext("Environmental gradient", cex = 1.3, 1, -0.1, outer = TRUE)
par(op)
# \donttest{
##Example 2
data(varespec)
data(varechem)
grad <- varechem[, "Baresoil"]
resu <- betaRegDisp(y = varespec, x = grad, ws = 3, method.1 = "jaccard",
method.2 = "ruzicka", method.3 = "ruzicka",
independent.data = FALSE, illust.plot = FALSE)
#Plotting all the outputs of the function:
op <- par(no.readonly = TRUE)
par(mfrow = c(5, 2), oma = c(1, 0, 1, 0.1), mar = c(1.5, 3, .1, .1), cex = 1, las = 0)
for(i in 1:ncol(resu)){
plot(resu[, 1], resu[, i], ylab = colnames(resu)[i], cex.lab = .9,
cex.axis = 0.9, tcl = -0.2, mgp = c(1.5, .2, 0), pch = 15, col = "grey")
}
mtext("Environmental gradient", cex = 1.3, 1, 0, outer = TRUE)
par(op)
# }
Run the code above in your browser using DataLab