seqient: Within sequence entropies

View source: R/seqient.R

seqientR Documentation

Within sequence entropies


Computes normalized or non-normalized within sequence entropies


 seqient(seqdata, norm=TRUE, base=exp(1), with.missing=FALSE, silent=TRUE)



a sequence object as returned by the the seqdef function.


logical: should the entropy be normalized? TRUE by default. (see details)


real positive value: base of the logarithm used in the entropy formula (see details). Default is exp(1), i.e., the natural logarithm is used.


logical: if TRUE, the missing state (gap in sequences) is handled as an additional state when computing the state distribution in the sequence.


logical: should messages about running operations be displayed?


The seqient function returns the Shannon entropy of each sequence in seqdata. The entropy of a sequence is computed using the formula

h(\pi_1,\ldots,\pi_s)=-\sum_{i=1}^{s}\pi_i\log \pi_i

where s is the size of the alphabet and \pi_i the proportion of occurrences of the ith state in the considered sequence. The base of the log is controlled with the base argument. Ba default the natural logarithm, i.e. the logarithm in base e, is used. The entropy can be interpreted as the ‘uncertainty’ of predicting the states in a given sequence. If all states in the sequence are the same, the entropy is equal to 0. For example, the maximum entropy for a sequence of length 12 with an alphabet of 4 states is 1.386294 and is attained when each of the four states appears 3 times.

Normalization can be requested with the norm=TRUE option, in which case the returned value is the entropy divided by the entropy of the alphabet. The latter is an upper bound for the entropy of sequences made from this alphabet. It is exactly the maximal entropy when the sequence length is a multiple of the alphabet size. The value of the normalized entropy is independent of the chosen logarithm base.


a single-column matrix with an entropy value for each sequence in seqdata; the column length is equal to the number of sequences.


Alexis Gabadinho


Gabadinho, A., G. Ritschard, N. S. Müller and M. Studer (2011). Analyzing and Visualizing State Sequences in R with TraMineR. Journal of Statistical Software 40(4), 1-37.

Gabadinho, A., G. Ritschard, M. Studer and N. S. Müller (2009). Mining Sequence Data in R with the TraMineR package: A user's guide. Department of Econometrics and Laboratory of Demography, University of Geneva.

Ritschard, G. (2023), "Measuring the nature of individual sequences", Sociological Methods and Research, 52(4), 2016-2049. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1177/00491241211036156")}.

See Also

seqindic, seqici, seqST, and seqstatd for the entropy of the cross-sectional state distributions by positions in the sequence.


actcal.seq <- seqdef(actcal,13:24)

## Summarize and plots an histogram
## of the within sequence entropy
actcal.ient <- seqient(actcal.seq)

## Examples using with.missing argument
ex1.seq <- seqdef(ex1, 1:13, weights=ex1$weights)

seqient(ex1.seq, with.missing=TRUE)

TraMineR documentation built on May 29, 2024, 5 a.m.