I'm using R and the library TraMineR to do sequence analysis on social science data. I have computed an optimal matching (OM) distance matrix.

      [,1]     [,2]      [,3]      [,4]
[1,]   0.00000 94.80628 110.00000 107.46826
[2,]  94.80628  0.00000  53.71086  78.02520
[3,] 110.00000 53.71086   0.00000  47.88362
[4,] 107.46826 78.02520  47.88362   0.00000

Here is a dput() of the OM matrix:

structure(c(0, 94.8062777425491, 110, 107.468255963965, 94.8062777425491, 
0, 53.7108606841158, 78.0251951544836, 110, 53.7108606841158, 
0, 47.8836216007405, 107.468255963965, 78.0251951544836, 47.8836216007405, 
0), .Dim = c(4L, 4L))

It is based on this data: https://github.com/aronlindberg/VOSS-Sequencing-Toolkit/blob/master/twitter_exploratory_analysis/cassandra.csv

and I computed it using this code:

# Read and transpose data
twitter_sequences <- read.csv(file = "cassandra.csv", header = TRUE)
twitter_sequences_transposed <- t(twitter_sequences)

# Define the sequence object
twitter.seq <- seqdef(twitter_sequences_transposed, left="DEL", right="DEL", gaps="DEL", missing="")

# Define the substitution matrix
twitter_costs <- seqsubm(twitter.seq, method="TRATE")

# Calculate the OM matrix
twitter.om <- seqdist(twitter.seq, method="OM", indel=1, sm=twitter_costs, with.missing=FALSE)

Now I want to express the similarity between two sequences in %. How can I accomplish this?

  • $\begingroup$ It's possible I just don't understand how you generated the above distance matrix, but what do you mean by "the similarity between two sequences in %"? Your distance matrix is a 4x4, doesn't that mean you have four sequences? $\endgroup$ Aug 28, 2012 at 2:12
  • $\begingroup$ Yes, so I want to be able to measure the similarity in % between any two sequences. There are 12 combinations in total. $\endgroup$
    – histelheim
    Aug 28, 2012 at 2:14
  • $\begingroup$ Could you provide an bit of the data? I think it may make it clearer what you are working with. $\endgroup$ Aug 28, 2012 at 2:22

1 Answer 1


You want dissimilarities as percentages but do not specify of what.

The seqdist function has a norm argument for specifying one of several normalization options. If your are interested in dissimilarities as percentage of the maximum possible dissimilarity given the alphabet and the sequence lengths, you just pass the argument norm="maxdist" to the function.

twitter.om <- seqdist(twitter.seq, method="OM", indel=1, sm=twitter_costs, with.missing=FALSE, norm="maxdist")

Be aware that with this normalization you may lose the triangle inequality in some circumstances.

See seqdist help page (by typing ?seqdist) for other possible normalizations.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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