Skip to contents

Count observed transitions in sequence data

Usage

summarize_transitions(
  data,
  id = "id",
  period = "period",
  state = "state",
  normalize = TRUE
)

Arguments

data

Long-form sequence data.

id, period, state

Column names.

normalize

Return row-conditional transition proportions. When FALSE, the probability column is kept but filled with NA.

Value

A tidy base data.frame with one row per observed from/to pair and columns from, to, count, and probability. Pairs never observed are absent rather than zero, so probability sums to one within each from state when normalize is TRUE.

Examples

data <- simulate_markov(
  n = 40,
  transition = matrix(c(0.7, 0.3, 0.4, 0.6), nrow = 2, byrow = TRUE),
  chain_length = 20, states = c("A", "B"), seed = 1
)
summarize_transitions(data, normalize = TRUE)
#>   from to count probability
#> 1    A  A   325   0.7049892
#> 2    A  B   136   0.2950108
#> 3    B  A   119   0.3979933
#> 4    B  B   180   0.6020067