Here is the summary of my sequence data generated in the SPELL format. All sequences are supposed to have the same length of 1440, but the summary tells me that they are not the same (see "min/max sequence length:91/1440").

I want to find the rows:

  1. that do not have the 1440 sequence length
  2. that have missing states (*)
  3. that have void elements (%)

Do you have any suggestions?

> summary(diary.seq)  
 [>] sequence object created with TraMineR version 1.8-3  
 [>] 4971 sequences in the data set, 4160 unique  
 [>] min/max sequence length: 91/1440  
 [>] alphabet (state labels):  
     1=Cr (Cr)  
     2=Ec (Ec)  
     3=Eo (Eo)  
     4=Hb (Hb)  
     5=Hc (Hc)  
     6=He (He)  
     7=Hr (Hr)  
     8=Hs (Hs)  
     9=Ir (Ir)  
     10=Lt (Lt)  
     11=Or (Or)  
     12=Pb (Pb)  
 [>] dimensionality of the sequence space: 27360  
 [>] colors: 1= 2= 3= 4= 5= 6= 7= 8= 9= 10= 11= 12= 13= 14= 15= 16= 17= 18= 19= 20=  
 [>] symbol for missing state: *  
 [>] symbol for void element: %  

To select some sequences, you need to create a condition vector. For instance, you can select the sequences with a length lower than 1440 using the seqlength function. Here is an example with the "mvad" data set.

## Loading the library
## Defining sequence properties
mvad.alphabet <- c("employment", "FE", "HE", "joblessness", "school", "training")
mvad.lab <- c("employment", "further education", "higher education", "joblessness", "school", "training")
mvad.shortlab <- c("EM", "FE", "HE", "JL", "SC", "TR")
## The state sequence object.
mvad.seq <- seqdef(mvad, 17:86, alphabet = mvad.alphabet, states = mvad.shortlab, labels = mvad.lab, xtstep = 6)

Now we can compute sequence length and build the vector (here all sequences have the same length of 70, so it does not make a lot of sense...). We used "<=" otherwise no sequences are selected, but in your case, you should use "<".

condition <- seqlength(mvad.seq) <= 70
seqdplot(mvad.seq[condition, ])

To count the number of time a state appears in each sequence you can use the "seqistatd" function. For instance, if we want to select all sequences with the "JL" (joblessness) state, we can use:

state.count <- seqistatd(mvad.seq)
condition <- state.count[, "JL"] > 0
seqdplot(mvad.seq[condition, ])

You can use the same strategy for the "*" missing state. There is no need to count "%" (void), since this will lead exactly for the same result as using "seqlength".


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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