% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sim-pc-hazard.R
\name{rchaz}
\alias{rchaz}
\alias{sim_rchaz}
\alias{lin_approx}
\title{Simulation of Piecewise Constant Hazard Model (Cox)}
\usage{
rchaz(cumhazard, rr, n = NULL, entry = NULL, cause = 1, extend = FALSE)
}
\arguments{
\item{cumhazard}{Cumulative hazard matrix (columns: time, cumulative hazard), or 
piece-constant rates for periods defined by the first column of input.}

\item{rr}{Relative risk vector for simulations, or alternatively when \code{rr=1} 
specify \code{n}.}

\item{n}{Number of simulations if \code{rr} not given.}

\item{entry}{Delayed entry time for simulations (optional).}

\item{cause}{Name/code of the event cause (default 1).}

\item{extend}{To extend piecewise constant with constant rate beyond the last break point. 
Default is \code{FALSE}. If \code{TRUE}, extends with average rate over time from 
cumulative. If numeric, uses the given rate.}
}
\value{
A data frame containing:
  \item{entry}{Entry times.}
  \item{time}{Event/censoring times.}
  \item{status}{Event status (1=event, 0=censored).}
  \item{rr}{Relative risks used.}
  
  Attributes include:
  \item{cumhaz}{The cumulative hazard used.}
  \item{extend.rate}{The extension rate if used.}
}
\description{
Simulates data from a piecewise constant baseline hazard that can also be of Cox type. 
Censors data at the highest value of the break points.
}
\details{
For a piecewise linear cumulative hazard, the inverse is easy to compute. With delayed 
entry \eqn{x}, we compute:
\deqn{\Lambda^{-1}(\Lambda(x) + E/RR)}
where \eqn{RR} are the relative risks and \eqn{E} is exponential with mean 1.
This quantity has survival function:
\deqn{P(T > t | T>x) = \exp(-RR (\Lambda(t) - \Lambda(x)))}
}
\examples{
chaz <-  c(0,1,1.5,2,2.1)
breaks <- c(0,10,   20,  30,   40)
cumhaz <- cbind(breaks,chaz)
n <- 10
X <- rbinom(n,1,0.5)
beta <- 0.2
rrcox <- exp(X * beta)

pctime <- rchaz(cumhaz,n=10)
pctimecox <- rchaz(cumhaz,rrcox,entry=runif(n))
}
\author{
Thomas Scheike
}
\keyword{simulation}
\keyword{survival}
