I am trying to reproduce the plots made by seqrep using the group= option in TraMineR because I want to have an image file with representative sequences for each group to use in a presentation. It seems that I am missing an important part in my syntax as subsetting the sequence object produces very different results from the on-board group option in TraMineR. As you can see in the pictures below the representative sequences identified by the seqrep differ strongly.
Do you know what part is missing or wrong in my syntax?
library(TraMineR)
library(WeightedCluster)
data(mvad)
mvad.alphabet <- c("employment", "FE", "HE", "joblessness", "school",
"training")
mvad.labels <- c("Employment", "Further Education", "Higher Education",
"Joblessness", "School", "Training")
mvad.scodes <- c("EM", "FE", "HE", "JL", "SC", "TR")
## Define sequence objects
mvad.seq <- seqdef(mvad[, 17:86], alphabet = mvad.alphabet,
states = mvad.scodes, labels = mvad.labels,
weights = mvad$weight, xtstep = 6)
## Defining cost matrices for OM - custom and transition based
subm.trate <- seqsubm(mvad.seq, method="TRATE")
## Computing dissimilarity matrices
mvad.ham <- seqdist(mvad.seq, method="HAM", sm=subm.trate)
## Clustering OM dissimilarities
wardCluster <- hclust(as.dist(mvad.ham), method = "ward",
members = mvad$weight)
clust4 <- cutree(wardCluster, k = 4)
## Plotting representative sequences
seqrplot(mvad.seq, criterion="dist", group=clust4, dist.matrix=mvad.ham,
withlegend=FALSE, border=NA, weighted=TRUE, stats=FALSE)
seqrplot(mvad.seq[clust4==2,], criterion="dist", dist.matrix=mvad.ham,
withlegend=FALSE, border=NA, weighted=TRUE, stats=FALSE)
Four groups of representative sequences: see second group
Second group of representative sequences
