as.seqtree {WeightedCluster} | R Documentation |
Convert a hierarchical clustering object to a seqtree object.
Description
Convert a hierarchical clustering object to a seqtree object which can then be displayed using seqtreedisplay
.
Usage
as.seqtree(object, seqdata, diss, weighted=TRUE, ...)
## S3 method for class 'twins'
as.seqtree(object, seqdata, diss, weighted=TRUE, ncluster, ...)
## S3 method for class 'hclust'
as.seqtree(object, seqdata, diss, weighted=TRUE, ncluster, ...)
Arguments
object |
An object to be converted to a |
seqdata |
State sequence object. |
diss |
A dissimilarity matrix or a dist object (see |
weighted |
Logical. If |
ncluster |
Maximum number of cluster. The tree will be builded until this number of cluster. |
... |
Additionnal parameters passed to/from methods. |
Details
By default as.seqtree
try to convert the object to a data.frame
assuming that it contains a list of nested clustering solutions.
Be aware that seqtree
and as.seqtree
only support binary splits.
If object
is an hclust
or twins
objects (i.e. hierarchical clustering output, see hclust
, diana
or agnes
), the function returns a seqtree
object reproducing the agglomerative schedulde.
Value
A seqtree
object.
Examples
data(mvad)
## Aggregating state sequence
aggMvad <- wcAggregateCases(mvad[, 17:86], weights=mvad$weight)
## Creating state sequence object
mvad.seq <- seqdef(mvad[aggMvad$aggIndex, 17:86], weights=aggMvad$aggWeights)
## COmpute distance using Hamming distance
diss <- seqdist(mvad.seq, method="HAM")
## Ward clustering
wardCluster <- hclust(as.dist(diss), method="ward", members=aggMvad$weight)
st <- as.seqtree(wardCluster, seqdata=mvad.seq, diss=diss, weighted=TRUE, ncluster=10)
print(st)
## You typically want to run (You need to install GraphViz before)
## seqtreedisplay(st, type="d", border=NA)