% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sim-pc-hazard.R
\name{sim_multistate}
\alias{sim_multistate}
\title{Simulation of Illness-Death Model}
\usage{
sim_multistate(
  n,
  cumhaz,
  cumhaz2,
  death.cumhaz,
  death.cumhaz2,
  rr12 = NULL,
  rr21 = NULL,
  rd13 = NULL,
  rd23 = NULL,
  rrc = NULL,
  gap.time = FALSE,
  max.recurrent = 100,
  dependence = 0,
  var.z = 0.5,
  cor.mat = NULL,
  cens = NULL,
  extend = TRUE,
  ...
)
}
\arguments{
\item{n}{Number of IDs.}

\item{cumhaz}{Cumulative hazard from state 1 to 2.}

\item{cumhaz2}{Cumulative hazard from state 2 to 1.}

\item{death.cumhaz}{Cumulative hazard of death from state 1.}

\item{death.cumhaz2}{Cumulative hazard of death from state 2.}

\item{rr12}{Relative risk for 1->2.}

\item{rr21}{Relative risk for 2->1.}

\item{rd13}{Relative risk for death 1->3.}

\item{rd23}{Relative risk for death 2->3.}

\item{rrc}{Relative risk for censoring.}

\item{gap.time}{Gap time indicator. If true simulates gap-times with specified cumulative hazard.}

\item{max.recurrent}{Maximum recurrent events.}

\item{dependence}{Dependence structure (0-3).}

\item{var.z}{Variance of random effects.}

\item{cor.mat}{Correlation matrix.}

\item{cens}{Censoring rate.}

\item{extend}{Extend hazards.}

\item{...}{Additional arguments.}
}
\value{
Data frame with multi-state event history.
}
\description{
Simulates data from a full illness-death model with reversible transitions 
and multiple causes of death. Supports various dependence structures via 
shared frailties.
}
\examples{
########################################
## getting some rates to mimick 
########################################
data(CPH_HPN_CRBSI)
dr <- CPH_HPN_CRBSI$terminal
base1 <- CPH_HPN_CRBSI$crbsi 
base4 <- CPH_HPN_CRBSI$mechanical
dr2 <- scalecumhaz(dr,1.5)
cens <- rbind(c(0,0),c(2000,0.5),c(5110,3))

iddata <- sim_multistate(100,base1,base1,dr,dr2,cens=cens)
dlist(iddata,.~id|id<3,n=0)
 
### estimating rates from simulated data  
c0 <- phreg(Surv(start,stop,status==0)~+1,iddata)
c3 <- phreg(Surv(start,stop,status==3)~+strata(from),iddata)
c1 <- phreg(Surv(start,stop,status==1)~+1,subset(iddata,from==2))
c2 <- phreg(Surv(start,stop,status==2)~+1,subset(iddata,from==1))
###
par(mfrow=c(2,3))
plot(c0)
lines(cens,col=2) 
plot(c3,main="rates 1-> 3 , 2->3")
lines(dr,col=1,lwd=2)
lines(dr2,col=2,lwd=2)
###
plot(c1,main="rate 1->2")
lines(base1,lwd=2)
###
plot(c2,main="rate 2->1")
lines(base1,lwd=2)
 
}
\author{
Thomas Scheike
}
\keyword{simulation}
\keyword{survival}
