seqMD: Multidomain sequences

View source: R/seqMD.R

seqMDR Documentation

Multidomain sequences

Description

Build multidomain (MD) sequences of combined individual domain states (expanded alphabet), derive multidomain indel and substitution costs from domain costs by means of an additive trick (CAT), and compute OM pairwise distances using CAT costs.

Usage

seqMD(channels,
  method=NULL,
  norm="none",
  indel="auto",
  sm=NULL,
  with.missing=NULL,
  full.matrix=TRUE,
  link="sum",
  cval=2,
  miss.cost=2,
  cweight=NULL,
  what="MDseq",
  ch.sep="+",
  fill.with.miss=TRUE
  )

seqdistmc(channels, what="diss", ch.sep="@@@@TraMineRSep@@@@", ...)

Arguments

channels

A list of domain state sequence stslist objects defined with the seqdef function, each state sequence object corresponding to a domain.

method

String. Default: NULL. Dissimilarity measure between sequences. When what="diss", must be one of "OM" (Optimal Matching), "HAM" (Hamming distance), or "DHD" (Dynamic Hamming distance). Otherwise, ignored. Can also be "LCS" (Longest common subsequence), but see details.

norm

String. Default: "none". The normalization method to use. See seqdist. Ignored if what is not "diss".

indel

Double, vector of doubles, or list with an insertion/deletion cost or a vector of state dependent indel costs for each domain. Can also be "auto" (default), in which case the indel cost of each domain is automatically set in accordance with the sm value of the domain. See indel argument of seqdist.

sm

A list with a substitution-cost matrix for each domain or a list of method names for generating the domain substitution costs (see seqcost). Ignored when method="LCS".

with.missing

Logical, vector of logical, or NULL (default). See seqdist and seqcost.

full.matrix

Logical. If TRUE (default), the full distance matrix between MD sequences is returned. If FALSE, an object of class dist is returned.

link

Character string. One of "sum" or "mean". Method to compute the "link" between domains. Default is to sum substitution and indel costs.

cval

Double. Domain substitution cost for "CONSTANT" matrix, see seqcost.

miss.cost

Double. Cost to substitute missing values at domain level, see seqcost.

cweight

A vector of domain weights. Default is 1 (same weight for each domain).

what

Character string. What output should be returned? One of "MDseq", "cost", "diss". The deprecated value what="sm" is treated as what="cost". MDseq returns the multidomain sequences expressed in terms of the expanded alphabet, "cost" the CAT costs, and "diss" the CAT-based multidomain distances.

ch.sep

Character string. Separator used for building state names of the expanded alphabet.

fill.with.miss

Logical. Should shorter domain sequences be filled with missings to match sequence lengths across domains? Applies only to domains that already have missings.

...

arguments passed to seqMD

Details

The seqMD function builds MD sequences by combining the domain states. When what="cost", it derives multidomain indel and substitution costs from the indel and substitution costs of each domain by means of the cost additive trick (CAT) (Ritschard et al., 2023, Pollock, 2007). When what="diss", it computes multidomain distances using the CAT multidomain costs. The available metrics (see method argument) are optimal matching ("OM"), Hamming distance ("HAM"), and Dynamic Hamming Distance ("DHD"). If method="LCS", distances are obtained with OM using CAT costs derived from domain indel and sm costs of respectively 1 and 2 (i.e. inputted indel and sm are ignored). For other edit distances, extract the combined state sequence object (by setting what="MDseq") and the CAT-multidomain substitution and indel costs (by setting what="cost"). Then use these outcomes as input in a call to seqdist. See seqdist for more information about available distance measures.

Normalization may be useful when dealing with sequences that are not all of the same length. For details on the applied normalization, see seqdist.

Sequences lengths are supposed to match across domains. If fill.with.miss is TRUE and the i-th sequence is shorter in one domain than the longest i-th sequence, it will, when constructing the i-th MD sequence, be filled with missing values to adapt its length to that of the longest sequence. However, this applies only for domain that already have missings, i.e., domains with a corresponding with.missing value set as TRUE.

Value

When what="MDseq", the MD sequences of combined states as a stslist sequence object.
When what="cost", the matrix of CAT-substitution costs with three attributes: indel the CAT-indel cost(s), alphabet the alphabet of the combined state sequences, and cweight the channel weights used.
When what="diss", a matrix of pairwise distances between MD sequences.

Author(s)

Gilbert Ritschard and Matthias Studer

References

Ritschard, G., T.F. Liao, and E. Struffolino (2023). Strategies for multidomain sequence analysis in social research. Sociological Methodology, 53(2), 288-322. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1177/00811750231163833")}.

Pollock, G. (2007) Holistic trajectories: a study of combined employment, housing and family careers by using multiple-sequence analysis. Journal of the Royal Statistical Society: Series A 170, Part 1, 167–183.

See Also

seqcost, seqdef, seqdist, seqplotMD.

Examples

data(biofam)

## Building one channel per type of event left home, married, and child
cases <- 200
bf <- as.matrix(biofam[1:cases, 10:25])
left <- bf==1 | bf==3 | bf==5 | bf==6
married <- bf == 2 | bf== 3 | bf==6
children <-  bf==4 | bf==5 | bf==6

## Building sequence objects
left.seq <- seqdef(left)
marr.seq <- seqdef(married)
child.seq <- seqdef(children)
channels <- list(LeftHome=left.seq, Marr=marr.seq, Child=child.seq)

## CAT multidomain distances based on channel specific cost methods
MDdist <- seqMD(channels, method="OM",
    sm =list("INDELSLOG", "INDELSLOG", "TRATE"), what="diss")

## Providing channel specific substitution costs
smatrix <- list()
smatrix[[1]] <- seqsubm(left.seq, method="TRATE")
smatrix[[2]] <- seqsubm(marr.seq, method="CONSTANT")
smatrix[[3]] <- seqsubm(child.seq, method="CONSTANT")

## Retrieving the MD sequences
MDseq <- seqMD(channels)
alphabet(MDseq)

## Retrieving the CAT multidomain substitution costs
## Using double weight for domain "child"
CATcost <- seqMD(channels,
    sm=smatrix, cweight=c(1,1,2), what="cost")

## OMspell distances between MD sequences
MDdist2 <- seqdist(MDseq, method="OMspell",
    sm = CATcost, indel=attr(CATcost,"indel"))


TraMineR documentation built on May 29, 2024, 5 a.m.