Learn R Programming

WeightedCluster (version 1.8-0)

as.seqtree: 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 twins
as.seqtree(object, seqdata, diss, weighted=TRUE, ncluster, ...)
# S3 method for hclust
as.seqtree(object, seqdata, diss, weighted=TRUE, ncluster, ...)

Value

A seqtree object.

Arguments

object

An object to be converted to a seqtree.

seqdata

State sequence object.

diss

A dissimilarity matrix or a dist object (see dist)

weighted

Logical. If TRUE, weights of the seqdata object are taken to build the tree.

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.

Examples

Run this code
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)

Run the code above in your browser using DataLab