We have a large sample (44,933 sequences each of potential length 35) with 9 states. We create a standard dissimilarity matrix:

seq <- seqdef(data, 3:37, right="DEL", left="DEL", gaps="GAP", indel=3, id=data$id, weights=data$weight)

Then create the dissimilarity matrix (We use indel=3 to place greater emphasis on length of the sequences in the clustering.):

om <- seqdist(seq, method="OM", indel=3, sm="TRATE", with.missing = TRUE)

Finally, we cluster the dissimilarity matrix:

seq.ward <- agnes(om, diss=TRUE, method="ward")

If we randomize the order of the rows in the original data:

rand1 <- sample(44933)
data.rand1 <- data[rand1,]

and then recreate the sequences and proceed as above, the cluster results differ.


1 Answer 1


This has nothing to do with the way the dissimilarities are computed by TraMineR. The solution you obtain depend on the way the clustering algorithm (agnes in your case) deals with ties. Actually dissimilarity values are most probably not unique in your matrix, and therefore there will most probably be ties at the different steps of the hierarchical clustering process. The successive chosen splits will rely on some random choice that itself depends on the initial order. Hence, the different final solutions.

Therefore, to reproduce your solution you must

  1. Keep the same row/column order in the dissimilarity matrix.

  2. Set a seed value.

Hope this helps

  • 1
    $\begingroup$ You can use the fonction clusterboot in package fpc to check the stability of your clustering. $\endgroup$ Apr 27, 2016 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.