A possible solution is to grow a regression tree of observed sequence orders. (See also this answer to related question.)
If you have a set of observed event sequences, you can compute pairwise dissimilarities between the sequences using some edit distance measure. Then, using the resulting pairwise dissimilarity matrix, you can grow a regression tree of the sequences. You thus partition the sequences into leaves, each characterized by a proper combination of values of the covariates (predictors). The values of the covariates of a case determine to which leaf of the tree it belongs. However, cases in a leaf do not all have the same order. To predict an order you need to identify a representative order of the leaf such as the medoid or the sequence with the densest neighborhood.
All this can be done in R with the TraMineR and TraMineRextras packages. I illustrate below using the actcal
monthly activity data included in TraMineR.
library(TraMineR)
library(TraMineRextras)
## loading actcal data (one case per line)
data(actcal)
## loading time-stamped event sequences built from the actcal data
## actcal.tse is a vertical file with one event per line
data(actcal.tse)
## creating event sequence object (one sequence per case)
actcal.seqe <- seqecreate(actcal.tse)
## We have 8 different events in this dataset
## assign unit cost for insertion/deletion of each event
idcost <- rep(1, 8)
## computing the dissimilarity matrix
dd <- seqedist(actcal.seqe, idcost=idcost, vparam=.1)
dim(dd)
# [1] 2000 2000
## growing the tree
dtree <- disstree(dd ~ educat00 + civsta00 + age00, data=actcal)
## Plot the tree using parallel coordinate plots for rendering order
gvpath <- "C:/Program Files/Graphviz"
disstreedisplay(dtree, image.data=actcal.seqe, filename="fg-event-seq-tree",
image.fun=seqpcplot, show.tree=TRUE, gvpath=gvpath)
To extract representative orders you can use the dissrep
function. For the above example, where most of the sequences have a single event, medoids are in each leaf a sequence with a single event.
References:
For regression trees from a dissimilarity matrix:
Studer, M., G. Ritschard, A. Gabadinho and N.S. Müller (2011), Discrepancy analysis of state sequences, Sociological Methods and Research, 40(3), pp. 471-510. doi: 10.1177/0049124111415372.
For dissimilarities between event sequences:
Ritschard, G., R. Bürgin and M. Studer (2013), Exploratory Mining of Life Event Histories, in J.J. McArdle and G. Ritschard (eds), Contemporary Issues in Exploratory Data Mining in the Behavioral Sciences, Quantitative Methodology Series , New York: Routledge, pages 221-253. Preprint (pdf).
For representative sequences:
Gabadinho, A. and G. Ritschard (2013), Searching for typical life trajectories applied to childbirth histories, in R. Levy and E. Widmer (eds), Gendered life courses - Between individualization and standardization. A European approach applied to Switzerland, Vienna-Lit. Pages 287-312. Preprint (pdf).
For the parallel coordinate plot:
Bürgin, R. and G. Ritschard (2014), A decorated parallel coordinate plot for categorical longitudinal data, The American Statistician. Vol. 68(2), 98-103, doi: 10.1080/00031305.2014.887591.
traminer
, so that's why. Otherwise other people answering would feel like they need to offer atraminer
-based answer, which is very clearly not the case here $\endgroup$traminer
tag will miss this question that could be relevant for them. $\endgroup$