% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fit_chaz.R
\name{fit_chaz}
\alias{fit_chaz}
\title{Fit Cox Model Stratified by Transition and Return Cumulative Hazards}
\usage{
fit_chaz(data, tmat, weights = NULL)
}
\arguments{
\item{data}{A data frame in long multistate format with columns
\code{Tstart}, \code{Tstop}, \code{status}, and \code{trans}.
Typically the output of \code{\link{intervals_to_long}()}.}

\item{tmat}{A K x K transition matrix from \code{trans_mat()}. Used
only to validate that all transition IDs in \code{data} are defined
in \code{tmat}; not used in the fit itself.}

\item{weights}{Optional numeric vector of length \code{nrow(data)}
with observation weights. Pass \code{1 / data$clust.size} for the
inverse-cluster-size-weighted estimator. \code{NULL} (default)
means unweighted.}
}
\value{
A data frame with columns:
\itemize{
  \item \code{time}: jump time of the transition.
  \item \code{Haz}: Breslow estimate of the cumulative transition
    hazard at \code{time}.
  \item \code{trans}: integer transition ID (matches \code{tmat}).
}
Sorted by \code{trans} then \code{time}.
}
\description{
Fits a Cox proportional hazards model stratified by transition type and
returns the Breslow-estimated cumulative transition hazards in long
format.
}
\details{
The model fitted is
\code{coxph(Surv(Tstart, Tstop, status) ~ strata(trans),
method = "breslow")}.
This is the Andersen-Gill counting-process formulation, which handles
multiple intervals per subject -- including non-monotone processes
with recovery -- provided the input data was correctly constructed
(one row per sojourn x candidate transition).
}
\examples{
data(example_msm)
tmat <- trans_mat(list(c(2, 3), c(1, 3), integer(0)),
                  names = c("Healthy", "Ill", "Dead"))

# fit_chaz takes long-format data; intervals_to_long() converts
# the interval format users supply. Most users reach fit_chaz
# indirectly via patp() -- this example shows the manual pipeline.
long <- intervals_to_long(example_msm, tmat)
haz  <- fit_chaz(long, tmat)
head(haz)

}
