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)
## Computing Hamming distance between sequence
diss <- seqdist(mvad.seq, method="HAM")
## K-Medoids
clust5 <- wcKMedoids(diss, k=5, weights=aggMvad$aggWeights)
## clust5$clustering contains index number of each medoids
## Those medoids are
unique(clust5$clustering)
## Print the medoids sequences
print(mvad.seq[unique(clust5$clustering), ], informat="SPS")
## Some info about the clustering
print(clust5)
## Plot sequences according to clustering solution.
seqdplot(mvad.seq, group=clust5$clustering)
Run the code above in your browser using DataLab