Skip to contents

This function returns the positions of the sequence represented by node in the time series used to build the context tree in which the sequence is represented. This is only possible is those positions were saved during the construction of the context tree. In positions were not saved, a call to this function produces an error.

Usage

positions(node)

# S3 method for ctx_node
positions(node)

# S3 method for ctx_node_cpp
positions(node)

Arguments

node

a ctx_node object as returned by find_sequence()

Value

positions of the sequence represented by node is the original time series as a integer vector

Details

A position of a sequence ctx in the time series x is an index value t such that the sequence ends with x[t]. Thus x[t+1] is after the context. For instance if x=c(0, 0, 1, 1) and ctx=c(0, 1) (in standard state order), then the position of ctx in x is 3.

Examples

dts <- sample(as.factor(c("A", "B", "C")), 100, replace = TRUE)
dts_tree <- ctx_tree(dts, max_depth = 3, min_size = 5)
subseq <- find_sequence(dts_tree, factor(c("B", "A"), levels = c("A", "B", "C")))
if (!is.null(subseq)) {
  positions(subseq)
}
#>  [1] 29 36 38 41 64 77 83 85 91 94 97