passage_time: Mean First Passage Times

View source: R/markov.R

passage_timeR Documentation

Mean First Passage Times

Description

Computes the full matrix of mean first passage times (MFPT) for a Markov chain. Element M_{ij} is the expected number of steps to travel from state i to state j for the first time. The diagonal equals the mean recurrence time 1/\pi_i.

Usage

passage_time(x, states = NULL, normalize = TRUE)

## S3 method for class 'net_mpt'
summary(object, ...)

## S3 method for class 'net_mpt'
plot(
  x,
  log_scale = TRUE,
  digits = 1,
  title = "Mean First Passage Times",
  low = "#004d00",
  high = "#ccffcc",
  ...
)

Arguments

x

A netobject, cograph_network, tna object, row-stochastic numeric transition matrix, or a wide sequence data.frame (rows = actors, columns = time-steps; a relative transition network is built automatically).

states

Character vector. Restrict output to these states. NULL (default) keeps all states.

normalize

Logical. If TRUE (default), rows that do not sum to 1 are normalized automatically (with a warning).

object

A net_mpt object (for summary).

...

Ignored.

log_scale

Logical. Apply log transform to the fill scale for better contrast? Default TRUE.

digits

Integer. Decimal places displayed in cells. Default 1.

title

Character. Plot title.

low

Character. Hex colour for the low end (short passage time). Default dark green "#004d00".

high

Character. Hex colour for the high end (long passage time). Default pale green "#ccffcc".

Details

Uses the Kemeny-Snell fundamental matrix formula:

M_{ij} = \frac{Z_{jj} - Z_{ij}}{\pi_j}, \quad Z = (I - P + \Pi)^{-1}

where \Pi_{ij} = \pi_j. Requires an ergodic (irreducible, aperiodic) chain.

Value

An object of class "net_mpt" with:

matrix

Full n \times n MFPT matrix. Row i, column j = expected steps from state i to state j. Diagonal = mean recurrence time 1/\pi_i.

stationary

Named numeric vector: stationary distribution \pi.

return_times

Named numeric vector: 1/\pi_i per state.

states

Character vector of state names.

summary.net_mpt returns a data frame with one row per state and columns state, return_time, stationary, mean_out (mean steps to other states), mean_in (mean steps from other states).

References

Kemeny, J.G. and Snell, J.L. (1976). Finite Markov Chains. Springer-Verlag.

See Also

markov_stability, build_network

Examples

net <- build_network(as.data.frame(trajectories), method = "relative")
pt  <- passage_time(net)
print(pt)

plot(pt)



Nestimate documentation built on April 20, 2026, 5:06 p.m.