mark_terminal_state: Mark terminal-NA cells with an explicit state label

View source: R/sequence_terminal.R

mark_terminal_stateR Documentation

Mark terminal-NA cells with an explicit state label

Description

Replaces every cell after each row's last observed state with the label given by state, leaving non-terminal NAs untouched. The result, passed to build_network(), yields a Markov chain in which the marked state is absorbing by construction (P[state, state] = 1).

Usage

mark_terminal_state(data, state = "End", cols = NULL)

Arguments

data

A wide-format matrix or data.frame (rows = actors, cols = time steps) of state labels with NA for missing observations.

state

Character. Label to insert in terminal-NA cells. Default "End".

cols

Optional state-column names; otherwise all columns.

Details

This is the small piece of pre-processing required to turn right-censored sequence data into an absorbing-chain model. The chain on the resulting matrix has one extra state (state) which is structurally absorbing because every cell after the actor's last observed step has been set to state - the chain stays there forever once entered.

Use chain_structure() on the result to compute mean absorption time, absorption probabilities, and per-state classification. Note that markov_stability() is not the right summary for absorbing chains; its stationary distribution will collapse to the absorbing state.

Value

A data.frame of the same shape as data with terminal NAs filled by state.

See Also

actor_endpoints(), chain_structure(), build_network()

Examples

M <- mark_terminal_state(trajectories, state = "Dropout")
net <- build_network(M, method = "relative")
chain_structure(net)


Nestimate documentation built on July 11, 2026, 1:09 a.m.