I'm using social sequence analysis, and comparing between different distance methods for my data. I'm wondering if there is a way to view/call the automatic substitution cost matrix that the dynamic hamming distance procedure uses? I have been able to create what I think would be the substitution cost matrices with the seqcost and the seqsubm functions (code below). Both these functions give me the same results - which is to be expected. However, I am wanting to know that what I've generated using this code is what the alogorthim would be using to compute? And, is there a way to view the substitution cost matrix that the procedure uses?

Thanks in advance for your advice!

#Compute the Dynamic Hamming distances. 

dist.dhd <- seqdist(number.seq, method = "DHD", with.miss = FALSE, norm = "none")

##create DHD cost matrix - both functions give same output

dhdcost <- seqcost(number.seq, method = "TRATE", time.varying = TRUE, transition = "both")

couts <- seqsubm(number.seq, method = "TRATE", time.varying = TRUE, transition = "both")
round(couts, 2)

1 Answer 1


The help page of function seqdist states:

When sm = NULL, the substitution-cost matrix is automatically created for "HAM" with a single substitution cost of 1 and for "DHD" with the costs derived from the transition rates at the successive positions, i.e. with sm = "TRATE".

Function seqcost returns both the substitution costs and the indel costs. Function seqsubmis an alias of seqcost that returns only the substitution costs. So we get of course the same substitution costs with these two functions. DHD uses only substitution costs and, therefore, we can use seqsubm.

Function seqdist computes the substitution costs for DHD by calling seqsubm with arguments method='TRATE' and time.varying=TRUE. For transition it uses the default transition='both'. So what you have computed should be what seqdist uses by default when sm=NULL.

In all cases, if you have any doubts, we strongly suggest to compute the costs with seqcost (or seqsubm) and then provide the substitution costs as sm argument (and, when applicable, the indel cost(s) as indel argument) to seqdist.

  • $\begingroup$ Thank you very much Gilbert - this was very helpful. $\endgroup$
    – Siobhan
    Commented Aug 19, 2021 at 0:34

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.