# Optimal number of clusters as per indicator species analysis
# (IndVal, Dufrene-Legendre; package: labdsv)
IndVal <- numeric(nrow(spe))
ng <- numeric(nrow(spe))
for (k in 2:(nrow(spe) - 1)) {
iva <- indval(spe, cutree(hc, k = k), numitr = 1000)
gr <- factor(iva$maxcls[iva$pval <= 0.05])
ng[k] <- length(levels(gr)) / k
iv <- iva$indcls[iva$pval <= 0.05]
IndVal[k] <- sum(iv)
}
k.best <- which.max(IndVal[ng == 1]) + 1
col3 <- rep(1, nrow(spe))
col3[ng == 1] <- 3
par(mfrow = c(1, 2))
plot(
1:nrow(spe),
IndVal,
type = "h",
main = "IndVal-optimal number of clusters",
xlab = "k (number of clusters)",
ylab = "IndVal sum",
col = col3
)
axis(
1,
k.best,
paste("optimum", k.best, sep = "\n"),
col = "red",
font = 2,
col.axis = "red"
)
points(
which.max(IndVal),
max(IndVal),
pch = 16,
col = "red",
cex = 1.5
)
plot(
1:nrow(spe),
ng,
type = "h",
xlab = "k (number of groups)",
ylab = "Ratio",
main = "Proportion of clusters with significant indicator
species",
col = col3
)
86
4 Cluster Analysis
# (IndVal, Dufrene-Legendre; package: labdsv)
IndVal <- numeric(nrow(spe))
ng <- numeric(nrow(spe))
for (k in 2:(nrow(spe) - 1)) {
iva <- indval(spe, cutree(hc, k = k), numitr = 1000)
gr <- factor(iva$maxcls[iva$pval <= 0.05])
ng[k] <- length(levels(gr)) / k
iv <- iva$indcls[iva$pval <= 0.05]
IndVal[k] <- sum(iv)
}
k.best <- which.max(IndVal[ng == 1]) + 1
col3 <- rep(1, nrow(spe))
col3[ng == 1] <- 3
par(mfrow = c(1, 2))
plot(
1:nrow(spe),
IndVal,
type = "h",
main = "IndVal-optimal number of clusters",
xlab = "k (number of clusters)",
ylab = "IndVal sum",
col = col3
)
axis(
1,
k.best,
paste("optimum", k.best, sep = "\n"),
col = "red",
font = 2,
col.axis = "red"
)
points(
which.max(IndVal),
max(IndVal),
pch = 16,
col = "red",
cex = 1.5
)
plot(
1:nrow(spe),
ng,
type = "h",
xlab = "k (number of groups)",
ylab = "Ratio",
main = "Proportion of clusters with significant indicator
species",
col = col3
)
86
4 Cluster Analysis
