Cluster variance
clustvar.Rd
Computes the variation in community composition (i.e. beta diversity) found within the sites of a set of hard or fuzzy clusters.
Arguments
- x
Community data. Either a site-by-species matrix or a site-by-site matrix of compositional distances between sites (i.e., an object of class
dist
). Alternatively, this can be an object of classvegclust
orvegclass
, and in this case it is unnecessary to providecluster
.- cluster
A vector indicating the hard membership of each object in
x
to a set of groups.- defuzzify
A flag indicating whether fuzzy memberships should be defuzzified (see function
defuzzify
). Only applies to the case where an object of classvegclust
orvegclass
is supplied inx
.- ...
Additional parameters for function
defuzzify
.
Details
This function can be used in two ways:
if
x
is a data matrix (site by species or distances among sites) andcluster
isnull
, the function assumes a single cluster of all points inx
. Whencluster
is provided, the function computes cluster variance for each (hard) group and this computation implies setting the centroid of the group. Cluster variance is defined as the average squared distance to the centroid.If
x
is an object of classvegclust
orvegclass
, the function uses the information contained there (distances to cluster centers, memberships and exponent of fuzziness) in order to compute cluster variances. Cluster centers do not need to be recomputed, and the distances to cluster centers are used directly. For centroid-based cluster models (KM, FCM, NC, HNC and PCM) the variance is defined as the average squared distance to the centroid. For medoid-based cluster models (KMdd, FCMdd, NCdd, HNCdd and PCMdd) the variance is defined as average distance to the medoid. The variance for both mobile and fixed clusters is returned. Additionally, membership matrices may be defuzzified ifdefuzzify=TRUE
.
Examples
## Loads data
data(wetland)
## This equals the chord transformation
## (see also \code{\link{decostand}} in package 'vegan')
wetland.chord = as.data.frame(sweep(as.matrix(wetland), 1,
sqrt(rowSums(as.matrix(wetland)^2)), "/"))
## Create noise clustering with 3 clusters. Perform 10 starts from random seeds
## and keep the best solution
wetland.nc = vegclust(wetland.chord, mobileCenters=3, m = 1.2, dnoise=0.75,
method="NC", nstart=10)
## Gets cluster variance of fuzzy clusters
clustvar(wetland.nc)
#> M1 M2 M3
#> 0.2924091 0.2612891 0.2556575
## Gets cluster variance of fuzzy clusters after defuzzification
clustvar(wetland.nc, defuzzify=TRUE)
#> M1 M2 M3
#> 0.2875054 0.2478222 0.2379082
## Similar to the previous, this gets cluster variance of defuzzified (i.e. hard) clusters
clustvar(wetland.chord, cluster=defuzzify(wetland.nc)$cluster)
#> M1 M2 M3 N
#> 0.2861120 0.2474883 0.2372548 0.7175326
## Gets cluster variance of K-means (i.e. hard) clusters
clustvar(wetland.chord, cluster=kmeans(wetland.chord, centers=3, nstart=10)$cluster)
#> 1 2 3
#> 0.3215797 0.4684155 0.4099091