test_sequence_group_difference: Test a sequence group difference

View source: R/sequence-inference.R

test_sequence_group_differenceR Documentation

Test a sequence group difference

Description

Aggregates sequence metrics to the declared independent unit and performs a permutation or randomization test. For observational data the p-value tests exchangeability-based association only; it is not a causal estimate.

Usage

test_sequence_group_difference(
  data,
  design,
  metric = c("sequence_length", "transition_count", "state_prevalence",
    "subsequence_presence"),
  target_state = NULL,
  target_subsequence = NULL,
  sequence_id_col = "sequence_id",
  order_col = "sequence_order",
  state_col = "state",
  separator = " > ",
  n_permutations = 999L,
  alternative = c("two.sided", "greater", "less"),
  seed = 1L
)

Arguments

data

Long-format sequence data.

design

A comparison design.

metric

"sequence_length", "transition_count", "state_prevalence", or "subsequence_presence".

target_state

Required for state prevalence.

target_subsequence

Required for subsequence presence, expressed using separator.

sequence_id_col, order_col, state_col

Core sequence columns.

separator

Subsequence label separator.

n_permutations

Number of permutations.

alternative

Alternative hypothesis.

seed

Reproducibility seed.

Value

An object of class gp3_sequence_group_inference.

Examples

data <- data.frame(
  participant_id = rep(paste0("p", 1:8), each = 4L),
  sequence_id = rep(paste0("s", 1:8), each = 4L),
  sequence_order = rep(1:4, times = 8L),
  state = c(rep(c("A", "B", "C", "D"), 4L),
            rep(c("A", "A", "C", "D"), 4L)),
  group = rep(rep(c("control", "treatment"), each = 4L), each = 4L)
)
design <- declare_sequence_comparison_design("group", "participant_id",
                                             design = "randomized")
test_sequence_group_difference(data, design, metric = "state_prevalence",
                               target_state = "A", n_permutations = 99L)

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