Mark terminal-NA cells with an explicit state label
Source:R/sequence_terminal.R
mark_terminal_state.RdReplaces 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).
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.
Examples
M <- mark_terminal_state(trajectories, state = "Dropout")
net <- build_network(M, method = "relative")
chain_structure(net)
#> Chain structure [4 states, 2 communicating classes]
#> irreducible: FALSE aperiodic: TRUE regular: FALSE reversible: NA
#> recurrent classes: 1 transient classes: 1
#> absorbing states: Dropout
#>
#> Use summary(x) for the per-state table, plot(x) for the heatmap.