I am using the seqgranularity
command in TraMineRExtras
. I read in the help documentation that I can indicate method = "mostfreq"
. What happens if, for example, I move from monthly to yearly data and in the 12 months I have 6 months in a state and 6 months in another state? Which of the two will be used to define the yearly sequences?
Thank you!
Add a comment
|
1 Answer
The most frequent category is identified by applying which.max
on the outcome of seqistatd
, which returns the state frequencies in the order of the alphabet. which.max
returns the index of the first encountered maximum. Therefore, with method="mostfreq"
, seqgranularity
assigns the category that appears first in the alphabet among those that share the maximal frequency.
The example below with two sequences of length 24 shows how the outcome changes with the alphabet order
library(TraMineRextras)
dat <- read.table(text = "
a/6,b/6,c/2,d/10
b/6,a/6,c/10,d/2
")
sdat <- seqformat(dat, from="SPS", to="STS",
SPS.in = list(xfix = "", sdsep = "/"),
stsep=",")
seq1 <- seqdef(sdat, alphabet=c("a","b","c","d"))
## "a" precedes "b" in the alphabet
seqgranularity(seq1, method="mostfreq",tspan=12)
## Sequence
## 1 a-d
## 2 a-c
seq2 <- seqdef(sdat, alphabet=c("d","c","b","a"))
## Here "b" precedes "a" in the alphabet
seqgranularity(seq2, method="mostfreq",tspan=12)
## Sequence
## 1 b-d
## 2 b-c