# How to use cost of matching with substitution-cost matrix in OM TraMiner?

I have a little complicated alphabet. I have for example:

1. A1|B1
2. A1|B2
3. A2|B3


So, dissimilarity between A1|B1 and A2|B3 =1, but dissimilarity between A1|B1 and A1|B2 is 1/2. How can i use this cost of matching/dismatching in TraMiner OM algorithm together or separately from substitution-cost matrix?

• Thank you very much for answer! My sequences look like: 1. "A1|B1,A1|B2" 2. "A1|B1,A2|B3" 3. "A1|B1,A1|B2,A2|B3” If matrix sm will be my substitution cost matrix - I will not use "TRATE" method at all? If my sm dissimilarity matrix 0-absolutly equal to 1- absolutely not equal, so my indel cost must be 1? Also I have another question. I am using agnes(bs.om, diss = TRUE, method = "ward") for hierarchical clustering. What way you use to choose the best clusters? You cut it by height? How do you choose representative for each cluster? Thank you so so much! Alexandra Commented May 25, 2015 at 7:14

The costs in optimal matching are specifically there to account for differences in state (dis)similarities as in your example. Here is an example of how you would define the substitution cost matrix sm

lab <- c("A1|B1","A1|B2","A2|B3")
sm <- matrix(
c(0, .5, 1,
.5, 0,  1,
1,  1, 0),
nrow = 3, ncol = 3, byrow = TRUE,
dimnames = list(lab, lab))


You then pass the matrix to seqdist with the sm=sm argument.

• Thank you very much for answer! My sequences look like: 1. "A1|B1,A1|B2" 2. "A1|B1,A2|B3" 3. "A1|B1,A1|B2,A2|B3” If matrix sm will be my substitution cost matrix - I will not use "TRATE" method at all? If my sm dissimilarity matrix 0-absolutly equal to 1- absolutely not equal, so my indel cost must be 1? Commented May 21, 2015 at 8:28
• Also I have another question. I am using agnes(bs.om, diss = TRUE, method = "ward") for hierarchical clustering. What way you use to choose the best clusters? You cut it by height? How do you choose representative for each cluster? Thank you so so much! Alexandra Commented May 21, 2015 at 8:31