Using TraMineR, is it possible to compare two sequence objects to calculate the discrepancy between them? By this I mean not comparing two sequences but two sets of sequences. Is this possible? If so, how do I go about doing it?


1 Answer 1


This is possible as long as your sequence objects share a same alphabet.

You do it by merging the two sequence objects into a pooled object, and then using dissassoc with the indicator of the original set as group argument. To illustrate, I first create two separate objects of female and male from the mvad sequence object:

levels(mvad[,"male"]) <- c("female","male")

mvad.seq <- seqdef(mvad, 17:86)

male.seq <- mvad.seq[mvad$male=="male",]
    female.seq <- mvad.seq[mvad$male=="female",]

and merge the two objects into a single one

pooled.seq <- rbind(male.seq,female.seq)

We create an indicator of the originating set (that should comply with the order of the sequences in pooled.seq)

oset.male <- rep(1,nrow(male.seq))
oset.female <- rep(2,nrow(female.seq))
oset <- c(oset.male, oset.female)

Now, we compute pairwise dissimilarities from the pooled object and get the discrepancy analysis by means of dissassoc

lcs <- seqdist(pooled.seq, method="LCS")
dissassoc(lcs, group=oset)
  • $\begingroup$ Does this require the dimensions of the sequence objects to be the same (i.e. number of sequences and time periods)? rbind() seems to require matrices of the same dimensions. $\endgroup$
    – histelheim
    Commented Nov 21, 2014 at 14:26
  • 1
    $\begingroup$ @histelheim You are right, the two sequence objects should be created from a table with the same number of columns. If you have sequences of unequal length, just add enough missing values in the table to get the right number of columns before passing the table to seqdef. $\endgroup$
    – Gilbert
    Commented Nov 21, 2014 at 16:25
  • $\begingroup$ Is it possible to calculate something like an average distance between the two groups of sequences? At the end of the day I want to get to a point where I can say that the sequence objects are "X % similar". $\endgroup$
    – histelheim
    Commented Dec 1, 2014 at 3:40
  • $\begingroup$ You can compute the mean of the pairwise distances between sequences of one group and those of the other group if you want. However, you have to compare that average dissimilarity with a reference distance? Which reference? The Pseudo F and R2 statistics are the measures you need to assess that two groups are similar or not. If statistically significant, the measures tell you that the two groups differ to some extend, and if not, that the differences can be attributable to chance. $\endgroup$
    – Gilbert
    Commented Dec 1, 2014 at 17:34
  • 1
    $\begingroup$ Take the mean of the subset of pairwise dissimilarities between group 1 and 2: mean.12 <- mean(lcs[oset==1,oset==2]) $\endgroup$
    – Gilbert
    Commented Dec 2, 2014 at 6:59

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.