Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

seqgranularity

Changing sequence time granularity by aggregating positions


Description

Changes time granularity of a state sequence object by aggregating successive positions into groups of a user-defined time length.

Usage

seqgranularity(seqdata, tspan = 3, method = "last")

Arguments

seqdata

A state sequence object.

tspan

Integer. Number of successive positions grouped together.

method

Character string. Aggregating method. One of "first", "first.valid", "last" (default), "last.valid", \ or "mostfreq".

Details

Successive positions are aggregated by group of tspan states. The aggregated state is, depending of the method chosen, either the first ("first"), the first valid ("first.valid"), the last ("last"), the last valid ("last.valid"), or the most frequent ("mostfreq") state of the tspan long spell. The same applies to the last spell, even when it is shorter than tspan.

Methods ("first") and ("last") differ from ("first.valid") and ("last.valid") only when sequences contain missing values and/or have different lengths.

When there are (void or non void) missings, method "mostfreq" replaces each interval with the most frequent valid state on the interval or the missing state when there are no valid state.

End missings are set as void when there are voids in seqdata and as the nr attribute otherwise.

Value

A stslist object: The compacted state sequence object.

Author(s)

Matthias Studer and Gilbert Ritschard

See Also

Examples

data(mvad)
mvad <- mvad[1:100,]
mvad.seq <- seqdef(mvad[,17:86], xtstep=12)
mvadg.seq <- seqgranularity(mvad.seq, tspan=6, method="first")
par(mfrow=c(2,1))
seqdplot(mvad.seq, with.legend=FALSE, border=NA)
seqdplot(mvadg.seq, with.legend=FALSE)

TraMineRextras

TraMineR Extension

v0.6.1
GPL (>= 2)
Authors
Gilbert Ritschard [aut, cre, ths, cph] (<https://orcid.org/0000-0001-7776-0903>), Matthias Studer [aut] (<https://orcid.org/0000-0002-6269-1412>), Reto Buergin [aut], Tim Liao [ctb], Alexis Gabadinho [ctb], Pierre-Alexandre Fonta [ctb], Nicolas Muller [ctb], Patrick Rousset [ctb]
Initial release
2021-01-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.