I created a sequence object from my SPELL-formatted data set. The sequence length of the sequence object is 1440 (i.e., 1-min intervals for a day).

Is there any easy way for TraMineR to convert the sequence length from 1440 to 288 (i.e., 5-min intervals), using the status in the first minute of every time interval to represent an individual's status during that 5-min period?

  • $\begingroup$ The title of the question may be confusing. What about changing it to something like: Modifying the time granularity of a state sequence. $\endgroup$ Nov 15 '12 at 10:54

You can simply select the corresponding columns. In your case, this should be columns 1, 6, 11, ... You can get the column indices using the "seq" function:

column.5min <- seq(from = 1, to = 1440, by=5)

Now you can select the column, for instance using:

myseq5min <- myseq[, column.5min]

Here is an example using the "mvad" data set and selecting the first state of each year.

 ## 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 select the column every year (every twelve monthes)
 mvad.seq.year <- mvad.seq[, seq(from=1, to=70, by=12)]

An alternative solution is to use the seqgranularity function provided by the TraMineRextras package. This function changes the time granularity using different methods, currently either "first" state or "last" state, but other methods such as choosing the most frequent state in the aggregated spell should be implemented in the future.

For the example above, you would just use

mvadg.seq.year <- seqgranularity(mvad.seq, tspan=12, method = "first")

TraMineRextras should be made available on the CRAN in the near future. In the meantime, if you have the latest version of R, you can just install it from R-Forge with

install.packages("TraMineRextras", repos="http://R-Forge.R-project.org")

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.