clustvar: Cluster variance

View source: R/clustvar.R

clustvarR Documentation

Cluster variance

Description

Computes the variation in community composition (i.e. beta diversity) found within the sites of a set of hard or fuzzy clusters.

Usage

clustvar(x, cluster = NULL, defuzzify=FALSE,...)

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 class vegclust or vegclass, and in this case it is unnecessary to provide cluster.

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 class vegclust or vegclass is supplied in x.

...

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) and cluster is null, the function assumes a single cluster of all points in x. When cluster 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 class vegclust or vegclass, 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 if defuzzify=TRUE.

Value

A double value (for one cluster) or a vector of values, one per each cluster.

Author(s)

Miquel De Cáceres, CREAF

See Also

vegclust, kmeans,defuzzify

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)

## Gets cluster variance of fuzzy clusters after defuzzification
clustvar(wetland.nc, defuzzify=TRUE)

## Similar to the previous, this gets cluster variance of defuzzified (i.e. hard) clusters
clustvar(wetland.chord, cluster=defuzzify(wetland.nc)$cluster)

## Gets cluster variance of K-means (i.e. hard) clusters
clustvar(wetland.chord, cluster=kmeans(wetland.chord, centers=3, nstart=10)$cluster)


emf-creaf/vegclust documentation built on July 27, 2024, 7:32 a.m.