I am looking for a method to detect sequences within univariate discrete data without specifying the length of the sequence or the exact nature of the sequence beforehand (see e.g. Wikipedia - Sequence Mining)
Here is example data
x <- c(round(rnorm(100)*10),
c(1:5),
c(6,4,6),
round(rnorm(300)*10),
c(1:5),
round(rnorm(70)*10),
c(1:5),
round(rnorm(100)*10),
c(6,4,6),
round(rnorm(200)*10),
c(1:5),
round(rnorm(70)*10),
c(1:5),
c(6,4,6),
round(rnorm(70)*10),
c(1:5),
round(rnorm(100)*10),
c(6,4,6),
round(rnorm(200)*10),
c(1:5),
round(rnorm(70)*10),
c(1:5),
c(6,4,6))
The method should be able to identify the fact that x contains the sequence 1,2,3,4,5 at least eight times and the sequence 6,4,6 at least five times ("at least" because the random normal part can potentially generate the same sequence).
I have found the arules
and arulesSequences
package but I could'nt make them work with univariate data. Are there any other packages that might be more appropriate here ?
I'm aware that only eight or five occurrences for each sequence is not going to be enough to generate statistically significant information, but my question was to ask if there was a good method of doing this, assuming the data repeated several times.
Also note the important part is that the method is done without knowing beforehand that the structure in the data had the sequences 1,2,3,4,5
and 6,4,6
built into it. The aim was to find those sequences from x
and identify where it occurs in the data.
Any help would be greatly appreciated!
P.S This was put up here upon suggestion from a stackoverflow comment...
Update: perhaps due to the computational difficulty due to the number of combinations, the length of sequence can have a maximum of say 5?
combn
of the unique values ofx
2 at a time, 3 at a time, etc. and identify the most frequently occurring ones in the data. By my rough calculations, this could be a bit time-consuming to run given that there would be about half a million 4-number long sequence combinations inx
. The basic logic behind it is not too mind-bending though. $\endgroup$