% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/trans_mat.R
\name{trans_mat}
\alias{trans_mat}
\title{Build a Transition Matrix for a Multistate Process}
\usage{
trans_mat(x, names = NULL)
}
\arguments{
\item{x}{A list of length K. Element \code{k} is an integer vector of
states reachable directly from state \code{k}. Use
\code{integer(0)} or \code{NULL} for absorbing states.}

\item{names}{Optional character vector of length K with state names.
If \code{NULL}, states are named \code{"1"}, \code{"2"}, ..., \code{"K"}.}
}
\value{
A K x K integer matrix. Entry \code{[h, j]} is the integer
  transition ID for the direct transition h -> j, or \code{NA} if no
  such transition exists. Transition IDs are assigned in row-major
  order (all transitions out of state 1 first, then state 2, etc.).
  The matrix has \code{dimnames} \code{list(from = names, to = names)}.
}
\description{
Constructs a square transition matrix in the format expected by
\code{\link{patp}} and \code{\link{prodint_AJ}}. It supports cyclic transitions
(e.g., illness-death with recovery).
}
\examples{
# Illness-death without recovery (progressive)
trans_mat(list(c(2, 3), 3, integer(0)),
          names = c("Healthy", "Ill", "Dead"))

# Illness-death WITH recovery (non-monotone)
trans_mat(list(c(2, 3), c(1, 3), integer(0)),
          names = c("Healthy", "Ill", "Dead"))

# Four-state multistate model with recovery from two intermediate states
trans_mat(list(c(2, 3, 4), c(1, 4), c(1, 4), integer(0)))

}
