- Introduced by
- Needleman & Wunsch (algorithm); Andrew Abbott (sociological use)
- Year
- 1970 (algorithm); 1980s (sociology)
- Type
- Edit-distance dissimilarity between categorical sequences
- Family
- Sequence dissimilarity measurement
What does it do?
Optimal matching analysis measures how dissimilar two categorical sequences are by computing the minimum total cost of editing one sequence into the other through substitutions and insertions/deletions (indels).
Originating in computer science and molecular biology, it was introduced to sociology by Andrew Abbott, and it supplies the pairwise distances on which sequence analysis of careers, family histories and other life-course trajectories is built.
The intuition behind the method
Take two life paths recorded as strings of states and ask how much editing is needed to turn one into the other: swap a state for another, or insert and delete states to shift timing. Two nearly identical careers need few cheap edits and come out close; two very different ones need many costly edits and come out far apart. Although many possible edit paths exist, dynamic programming finds the cheapest one without checking each path separately, so every pair of sequences receives one distance value.
History
The alignment idea follows from the Levenshtein edit distance (1965) and the Needleman–Wunsch dynamic-programming algorithm (1970), both developed for comparing sequences in other fields. Andrew Abbott adapted optimal matching to sociology in the 1980s to compare careers and historical sequences, and his 2000 review with Angela Tsay surveyed the studies that had applied it. Later work by Matthias Studer and Gilbert Ritschard compared optimal matching with alternative dissimilarity measures and examined how each responds to sequencing, timing and duration.
When to use it
Choose optimal matching when you need a dissimilarity between categorical sequences that respects both which states occur and when they occur, usually as the distance step before clustering trajectories into a typology. It suits life-course, career and other ordered categorical trajectories of comparable length. It does not explain anything by itself: it yields distances, and the resulting typology depends on the cost scheme. Avoid it when only state identity matters at fixed positions (a simpler position-by-position mismatch count may suffice), when sequences are very long or very numerous so that pairwise computation becomes costly, or when substitution and indel costs cannot be justified substantively. Report sensitivity to the cost choices where possible.
Limitations and considerations
- The substitution and indel costs are partly a matter of judgement, and they strongly shape the distances and the resulting typologies.
- Standard costs weight timing, sequencing and duration in ways that may differ from the analyst's intent; Studer and Ritschard's comparison finds that no single dissimilarity index is universally optimal and that the choice depends on which aspect is of interest.
- Each pair's computation grows with the product of the two sequence lengths, and the number of pairs grows with the square of the sample size, which limits scalability.
- As a distance it is descriptive: it does not model a generating process and does not directly support statistical inference.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Gives a dissimilarity that accounts for both the identity of states and their timing, through substitution and indel operations.
- Scores each pair by dynamic programming, so the cheapest alignment is found without enumerating all edit paths.
- The cost scheme can be set by theory or derived from transition rates, letting the distance follow the research question.
- Produces the pairwise dissimilarity matrix that clustering of trajectories into types requires.
Applications
- Computing distances between career and employment trajectories for life-course typologies, the area that the Abbott–Tsay review identifies as most promising.
- Comparing family-formation and partnership histories.
- Measuring similarity of residential and migration sequences.
- Aligning and comparing daily time-use or activity sequences.
- Comparing historical or organizational process sequences in comparative-historical research.
How it works
How it works
Three elementary operations transform one sequence into another: substituting one state for another, and inserting or deleting a state (an indel). Substitutions change which state occupies a position, while indels shift later positions and so register differences in the timing and duration of states.
Formula
\text{operations: substitute } a\to b\ (\text{cost } s_{ab}),\ \text{insert/delete}\ (\text{cost } \gamma)Each operation has a cost. Substitution costs s_ab form a symmetric matrix with zero on the diagonal, and a single indel cost γ sets the penalty for shifting timing. The relative size of the indel and substitution costs determines whether the distance is driven more by the order and timing of states or by which state occupies each position. This is the main specification choice, and it is debated.
Formula
s_{ab} = s_{ba} \ge 0,\quad s_{aa}=0,\quad \gamma > 0The optimal matching distance between two sequences is the minimum total cost over all edit paths that transform one into the other. Its value is fixed by the cost scheme and the two sequences. The stated cost conditions (non-negative substitution costs, zero for identical states, positive indel cost) do not by themselves guarantee that the distance is a metric; that property depends on further conditions on the costs, which should be checked for the chosen scheme if the downstream method assumes a metric. Distances are expressed in units of the chosen cost scheme and also depend on sequence lengths. They are therefore comparable only within the same scheme. If values are compared across samples or sequence lengths, report how they were normalized.
Formula
d_{\mathrm{OM}}(x,y) = \min_{\text{edit paths}}\ \sum (\text{operation costs})The minimum is computed by the Needleman–Wunsch dynamic-programming recursion. A cost matrix is initialised with C(0,0) = 0, C(i,0) = i·γ and C(0,j) = j·γ, and then filled cell by cell, each cell taking the cheapest of three options: an indel in one sequence, an indel in the other, or a substitution (zero-cost when the states match). The cell C(m,n) for sequences of lengths m and n holds the optimal distance, and computation time grows with the product of the two sequence lengths.
Formula
C_{0,0}=0,\ C_{i,0}=i\gamma,\ C_{0,j}=j\gamma;\quad C_{i,j} = \min\bigl(C_{i-1,j}+\gamma,\ C_{i,j-1}+\gamma,\ C_{i-1,j-1}+s_{x_i y_j}\bigr),\quad d_{\mathrm{OM}}(x,y)=C_{m,n}Instead of setting costs by hand, substitution costs can be derived from the data, for example from observed transition rates between states, so that states that often replace each other are cheap to substitute. A commonly used rate-based form is s_ab = 2 − p(a|b) − p(b|a) for a ≠ b, with s_aa = 0 for identical states. Comparative work shows that different cost derivations stress different features (timing, sequencing, duration), so the scheme should follow the substantive question.
Formula
s_{ab} = 2 - p(a\mid b) - p(b\mid a)\ \text{for } a\neq b,\quad s_{aa}=0Common pitfalls
- Using default or arbitrary costs and presenting the resulting typology as objective and free of assumptions.
- Setting the indel cost very low or very high without noticing that this shifts emphasis between timing and state identity.
- Comparing sequences observed over different calendar periods or with different origins without first putting them on a common time window or origin. Indels handle shifts in the order and timing of states within sequences, but they do not correct for differing observation windows, and such offsets inflate the distances.
- Reporting a single cost scheme without sensitivity analyses across alternatives, which leaves the robustness of the typology unchecked.
Frequently asked questions
How do I set substitution and indel costs?
Costs can be set as constant (all substitutions equal), derived from observed transition rates so that frequently interchanged states are cheap to substitute, or grounded in theory about state proximity. The indel-to-substitution ratio controls whether the distance emphasizes timing or state identity. Best practice is to justify the choice substantively and report sensitivity analyses across alternative schemes.
What is the difference between optimal matching and Hamming distance?
Hamming distance only compares states position by position and counts mismatches; it captures differences in state identity but ignores timing shifts. Optimal matching adds insertion/deletion operations, so it can align sequences that are similar but offset in time, capturing differences in timing and duration as well as identity. Optimal matching is more flexible but requires choosing the indel cost.
Is optimal matching the same as sequence analysis?
No. Optimal matching is one method for the distance step. Sequence analysis is the full workflow of representing sequences, computing pairwise distances (by optimal matching or another measure), clustering them into types, and describing those types. Optimal matching supplies the input distances; it is not itself the typology-building analysis.
Related methods
Sources
Abbott, A., & Tsay, A. (2000). Sequence analysis and optimal matching methods in sociology: review and prospect. Sociological Methods & Research, 29(1), 3–33.
Open DOI referenceStuder, M., & Ritschard, G. (2016). What matters in differences between life trajectories: a comparative review of sequence dissimilarity measures. Journal of the Royal Statistical Society: Series A, 179(2), 481–511.
Open DOI reference