3

I am using TraMineR for a while now and I have a question regarding changing the time granularity of my sequences. At the moment I have my sequences aligned on months, but for several reasons I would like to change this to years. I would like to use the longest spell in each year as the state for that particular year. In other words, if somebody was cohabiting for 4 months and then got married and stayed married for the other 8 months in the year 2000, I would like to code that person as being married in 2000. I was wondering if there is an easy way to do this with TraMineR.

Thanks in advance,

Tom

Tohveli
  • 487
  • 5
  • 18

1 Answers1

4

The seqgranularity function from the TraMineRextras package aggregates each successive subsequence of length tspan into a single state. In its stable version on the CRAN two aggregation methods are proposed: "first" or "last" that replace the sequence over the period with respectively the first and last state in the period.

The option you are looking for, i.e., replace the period with the most frequent state, is currently in test in the development version of TraMineRextras available from R-Forge. The argument is method="mostfreq"

Here is an example where we aggregate monthly data into yearly data:

library(TraMineRextras)
data(mvad)
mvad.seq <- seqdef(mvad, 17:86)
mvad.seq2 <- seqgranularity(mvad.seq, tspan=12, method="mostfreq")
par(mfrow=c(2,1))
seqiplot(mvad.seq, withlegend=F)
seqiplot(mvad.seq2, withlegend=F)
Gilbert
  • 3,570
  • 18
  • 28