Constructs a k-th order De Bruijn graph from sequential trajectory data and uses a hypergeometric null model to detect paths with anomalous frequencies. Paths occurring more or less often than expected under the null model are flagged as over- or under-represented.
Arguments
- data
A data.frame (rows = trajectories), list of character vectors,
tnaobject, ornetobjectwith sequence data. Fortna/netobject, numeric state IDs are automatically converted to label names.- order
Integer scalar or integer vector. Order(s) of the De Bruijn graph (default
2L). An order ofkdetects anomalies in paths of lengthk. When a vector is supplied, one De Bruijn layer is built per order and the per-order results are stored in$by_order(named by order). The orders are sorted ascending internally, so thecograph_networkslots ($weights,$edges,$adjacency,$xi,$nodes,$meta) always describe the network of the lowest order that produced a layer (a requested order with no edges is dropped from$by_order,$orderand$k), regardless of the order in which the vector is given;$scoresaggregates every built order.- alpha
Numeric. Significance threshold for anomaly classification (default 0.05). Paths with HYPA score < alpha are under-represented; paths with score > 1-alpha are over-represented.
- min_count
Integer. Minimum observed count for a path to be classified as anomalous (default 5). Paths with fewer observations are always classified as
"normal"regardless of their HYPA score, since rare occurrences are unreliable.- p_adjust
Character. Method for multiple testing correction of p-values. Default
"BH"(Benjamini-Hochberg FDR control). Accepts any method fromp.adjust.methodsor"none"to skip correction. Under- and over-representation p-values are adjusted separately (two-sided testing).- k
Deprecated. Former name of
order; if supplied it overridesorderand emits a deprecation message. Useorderinstead.
Value
An object of class c("net_hypa", "cograph_network") with
components:
- scores
Data frame with path, from, to, observed, expected, ratio, p_value, p_under, p_over, p_adjusted_under, p_adjusted_over, anomaly, order columns (one block of rows per requested order). The
pathcolumn shows the full state sequence (e.g., "A -> B -> C");fromis the context (conditioning states);tois the next state;ratiois observed / expected;p_valueis retained as an alias forp_under, the raw lower-tail hypergeometric CDF value;p_overis the inclusive upper-tail probabilityP(X >= observed);p_adjusted_underandp_adjusted_overare the corrected p-values for under- and over-representation tests respectively.- ho_edges
Alias for
scores(all orders, arrow notation).- over
Subset of
scoresclassified as over-represented.- under
Subset of
scoresclassified as under-represented.- adjacency
Weighted adjacency matrix of the lowest-order De Bruijn graph.
- weights
cograph weight matrix of the lowest-order graph.
- xi
Fitted propensity matrix of the lowest-order graph.
- edges
cograph edge data.frame of the lowest-order graph.
- by_order
Named list of per-order result lists.
- order
Integer vector of orders actually built (sorted ascending).
- k
Back-compatibility alias for
order.- alpha
Significance threshold used.
- p_adjust
Multiple testing correction method used.
- n_anomalous
Number of anomalous paths detected (all orders).
- n_over
Number of over-represented paths (all orders).
- n_under
Number of under-represented paths (all orders).
- n_edges
Total number of edges (all orders).
- nodes
data.frame (
id,label,name) of the lowest-order De Bruijn graph nodes (arrow notation).- directed
Logical. Always
TRUE.- meta
cograph meta list of the lowest-order graph.
- node_groups
Always
NULL.
References
LaRock, T., Nanumyan, V., Scholtes, I., Casiraghi, G., Eliassi-Rad, T., & Schweitzer, F. (2020). HYPA: Efficient Detection of Path Anomalies in Time Series Data on Networks. SDM 2020, 460-468.
Examples
seqs <- list(c("A","B","C"), c("B","C","A"), c("A","C","B"), c("A","B","C"))
hyp <- build_hypa(seqs, order = 2)
# \donttest{
trajs <- list(c("A","B","C"), c("A","B","C"), c("A","B","C"),
c("A","B","D"), c("C","B","D"), c("C","B","A"))
h <- build_hypa(trajs, order = 2)
print(h)
#> HYPA: Path Anomaly Detection
#> Order(s): 2
#> Edges: 4
#> Anomalous: 0 (alpha=0.05, p_adjust=BH)
#> Over-repr: 0
#> Under-repr: 0
# }