as.hclust.cvxclust {CCMMR} | R Documentation |
Conversion of a cvxclust
object into an hclust
object
Description
Converts the output of convex_clustering or convex_clusterpath into a hclust object. Note that a step in the clusterpath from one value for lambda to the next may cause the number of clusters to decrease by more than one. It is a hard requirement that the clusterpath ends in a single cluster, as standard dendrogram plotting methods fail if this is not the case.
Usage
## S3 method for class 'cvxclust'
as.hclust(x, ...)
Arguments
x |
A |
... |
Unused. |
Value
A hclust
object.
See Also
Examples
# Demonstration of converting a clusterpath into a dendrogram, first generate
# data
set.seed(6)
X = matrix(rnorm(14), ncol = 2)
y = rep(1, nrow(X))
# Get sparse distances in dictionary of keys format with k = 3
W = sparse_weights(X, 3, 4.0)
# Sequence for lambda
lambdas = seq(0, 45, 0.02)
# Compute results
res = convex_clusterpath(X, W, lambdas)
# Generate hclust object
hcl = as.hclust(res)
hcl$height = sqrt(hcl$height)
# Plot clusterpath and dendrogram
oldpar = par(mfrow=c(1, 2))
plot(res, y, label = c(1:7))
plot(hcl, ylab = expression(sqrt(lambda)), xlab = NA, sub = NA, main = NA,
hang = -1)
par(oldpar)
[Package CCMMR version 0.2 Index]