1

So, I have a set of 893 sequences of varying lengths with max sequence length = 152. There are 10 unique states across all of them. These sequences are split into two groups: Promoted and Not Promoted. Using TramineR, I generated representative sequence for the two groups (Image attached).

However, I am trying to print out the first 5-10 states of the said representative sequence. Is there a way to do that? ![Representative Sequences] (https://i.stack.imgur.com/lKivC.jpg)

The print can be in the form of color labels or in a string format (preferably color labels)

I could not find any argument in the seqrplot that can help me get what I want.

  • Please provide enough code so others can better understand or reproduce the problem. – Minh Feb 20 '23 at 21:21

1 Answers1

1

You cannot subset the displayed columns when using seqrplot unless you want to find representatives of the truncated sequences. However, you can compute and retrieve the representatives of the complete sequences and then plot the truncated representatives. I illustrate below using the biofam data of TraMineR.

library(TraMineR)
## biofam data: sequences in columns 10 to 25
data(biofam)
biofam.lab <- c("Parent", "Left", "Married", "Left+Marr",
                "Child", "Left+Child", "Left+Marr+Child", "Divorced")
biofam.seq <- seqdef(biofam, 10:25, labels=biofam.lab)
## LCS distances
biofam.lcs <- seqdist(biofam.seq, method="LCS")

## Representative set using the neighborhood density criterion
biofam.rep <- seqrep(biofam.seq, diss=biofam.lcs, criterion="density")

plot(biofam.rep[,6:13])

If you have groups, you must compute the representatives separately for each group and then arrange the plots manually using layout for example.

Gilbert
  • 3,570
  • 18
  • 28
  • Thanks, but my variable that stores representative sequence is a list. I tried plotting it and obviously it threw error. Here's my code: `df_seq2_promoted <- df_seq2[df_seq2$X0 == "Promoted",] df_seq2_prom.seq <- seqdef(df_seq2_promoted[3:619], method = 'OM', right="DEL",format = "SPS", cpal = mycolors_1) dist.om1_prom <- seqdist(df_seq2_prom.seq, method = "OM", indel = "auto", sm = "TRATE") rep_seq <- seqrplot(df_seq2_prom.seq, diss = dist.om1_prom, border = NA, criterion = "density")` – Anand Vamsi Feb 24 '23 at 19:17
  • 1
    Your `rep_seq` does not store the representative sequences. To get the representative sequences you must use `seqrep` as in the example given in my response. – Gilbert Feb 25 '23 at 08:40