1

How do you use the time varying substitution cost (time.varying = T) created with the seqcost function in TraMineR? It does not seem to work.

library(TraMineR)
data(biofam)

biofam.seq <- seqdef(biofam[501:600,10:25])

lifcost <- seqcost(biofam.seq, method="INDELSLOG", time.varying = T)
lifcost

biofam.om <- seqdist(biofam.seq, method="OM", indel=lifcost$indel, sm=lifcost$sm)

I get the message

Error: 'indel' has an unknown value

1 Answer 1

1

Your computation of time-varying costs is correct. However, OM does not support time-varying costs. The only distance that can use time-varying costs is DHD (dynamic Hamming distance). Distance using indels allow for time warp when aligning sequences and this brings arbitrariness because we would not get the same cost for substituting two states after an insert in one sequence than after a delete in the other sequence.

Here is how you can use time-varying costs:

biofam.dhd <- seqdist(biofam.seq, method="DHD", sm=lifcost$sm)
biofam.dhd[1:6,1:6]

#            803      2294      1191      1598     1701       438
# 803   0.000000  6.450131 11.857460  4.716811 12.91787  5.968021
# 2294  6.450131  0.000000 10.342118  8.589405 10.54495  2.979339
# 1191 11.857460 10.342118  0.000000  7.140649 11.99618  9.860008
# 1598  4.716811  8.589405  7.140649  0.000000 11.24853  8.107295
# 1701 12.917866 10.544954 11.996184 11.248525  0.00000 10.062844
# 438   5.968021  2.979339  9.860008  8.107295 10.06284  0.000000

Alternatively, you get the same results with

biofam.dhd <- seqdist(biofam.seq, method="DHD", sm="INDELSLOG")

Note that although indel is not used, you cannot assign to it the value lifcost$indel returned by seqcost because it is a matrix, which is not a supported indel type.

2
  • Thank you for this. I am just wondering why is the seqcost function allows to compute for time-varying indel cost if we cannot use them. Is there any other way to use these time-varying cost? Is it possible to replace the DHD cost with the cost I calculated using the indelslog for instance?
    – giac
    Commented Mar 25, 2023 at 12:23
  • Thank you Gilbert this is useful.
    – giac
    Commented Mar 26, 2023 at 13:57

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