create_transition_network: Create a transition network from ordered sequences

View source: R/sequence-networks.R

create_transition_networkR Documentation

Create a transition network from ordered sequences

Description

Create a transition network from ordered sequences

Usage

create_transition_network(
  data,
  sequence_id_col = "sequence_id",
  order_col = "sequence_order",
  state_col = "state",
  group_cols = NULL,
  order = 1L,
  include_self = TRUE,
  normalise = c("count", "from", "global"),
  smoothing = 0,
  context_separator = " > "
)

Arguments

data

Long-format sequence data or a prepared result.

sequence_id_col, order_col, state_col

Sequence columns.

group_cols

Optional grouping columns constant within sequence.

order

Markov order. 1 creates ordinary state-to-state edges; larger values create context-to-next-state edges.

include_self

Include first-order self-transitions.

normalise

Edge weight scale: counts, conditional probabilities from each context, or global shares.

smoothing

Non-negative additive smoothing applied to observed edges.

context_separator

Separator used for higher-order contexts.

Value

A data frame of class gp3_transition_network containing context, next state, counts, weights, sequence prevalence, and group columns.

Examples

sequences <- data.frame(
  sequence_id = rep(c("s1", "s2", "s3", "s4"), each = 4L),
  sequence_order = rep(1:4, times = 4L),
  state = c("A", "B", "C", "D", "A", "B", "C", "C",
            "D", "C", "B", "A", "D", "C", "A", "A"),
  group = rep(c("g1", "g2"), each = 8L),
  stringsAsFactors = FALSE
)
create_transition_network(sequences, normalise = "from")


gp3sequences documentation built on Aug. 23, 2026, 5:10 p.m.