create_consensus_sequence: Create an aligned-position consensus sequence

View source: R/sequence-consensus-groups.R

create_consensus_sequenceR Documentation

Create an aligned-position consensus sequence

Description

Computes a descriptive consensus state at each observed sequence position. The function does not treat the consensus as a behavioural norm and does not infer psychological or causal meaning.

Usage

create_consensus_sequence(
  data,
  sequence_id_col = "sequence_id",
  order_col = "sequence_order",
  state_col = "state",
  group_cols = NULL,
  weight_col = NULL,
  missing_state_policy = c("exclude", "state", "error"),
  missing_state_label = "<MISSING>",
  tie_method = c("first", "last", "missing", "all"),
  state_levels = NULL,
  min_support = 1L
)

Arguments

data

A long-format data frame, a prepared gp3sequences result, or a data frame containing canonical columns.

sequence_id_col, order_col, state_col

Column names defining sequences.

group_cols

Optional columns defining independent consensus groups.

weight_col

Optional non-negative row-weight column.

missing_state_policy

One of "exclude", "state", or "error".

missing_state_label

Label used when missing states are retained.

tie_method

Deterministic tie policy: "first", "last", "missing", or "all".

state_levels

Optional preferred state ordering used for ties.

min_support

Minimum number of contributing sequences at a position.

Value

A data frame of class gp3_consensus_sequence containing group columns, sequence position, consensus state, support counts and weights, agreement proportion, tie count, tied states, and total group sequences.

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_consensus_sequence(sequences, group_cols = "group")


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