Learn R Programming

clue (version 0.2-1)

clustering: Partitions and Hierarchies

Description

Determine whether an R object represents a partition or hierarchy of objects, or coerce to an R object representing such.

Usage

is.cl_partition(x)
is.cl_hard_partition(x)
is.cl_soft_partition(x)
is.cl_hierarchy(x)

as.cl_partition(x) as.cl_hard_partition(x) as.cl_hierarchy(x)

Arguments

x
an R object.

Value

  • For the testing functions, a logical indicating whether the given object represents a clustering of objects of the respective kind.

    For the coercion functions, the object itself if it already represents a clustering of the respective type. Otherwise, an object inheriting from "cl_membership" or "cl_ultrametric" when coercing to partitions or hierarchies, respectively.

Details

Apart from is.cl_soft_partition, the testing functions are generic functions.

The methods provided in package clue handle the partitions and hierarchies obtained from clustering functions in the base R distribution, as well as packages cba, cclust, cluster, e1071, flexclust, flexmix, kernlab, and mclust (and of course, clue itself).

is.cl_soft_partition gives true iff is.cl_partition is true and is.cl_hard_partition is false.

For as.cl_partition and as.cl_hierarchy, the given object is returned if it already represents a partition or hierarchy (i.e., the corresponding test returns true). Otherwise, as.cl_membership or as.cl_ultrametric are called, creating suitable membership or ultrametric objects if possible.

as.cl_hard_partition(x) returns x if this represents a hard partition (i.e., is.cl_hard_partition(x) is true). Otherwise, it returns an object of class "cl_membership" with the memberships of a hard partition with classes either obtained directly from x if this is an atomic vector of raw class ids, or, if x represents a soft partition or is a raw matrix of membership values, as the class ids of the closest hard partition, defined by taking the class ids of the (first) maximal membership values.

Conceptually, (hard) partitions and hierarchies are virtual classes.

Examples

Run this code
data("Cassini")
pcl <- kmeans(Cassini$x, 3)
is.cl_partition(pcl)
is.cl_hard_partition(pcl)
is.cl_soft_partition(pcl)

hcl <- hclust(dist(USArrests))
is.cl_partition(hcl)
is.cl_hierarchy(hcl)

Run the code above in your browser using DataLab