% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sim-pc-hazard.R
\name{sim_cif}
\alias{sim_cif}
\alias{sim_cifs}
\alias{subdist}
\alias{sim_subdist}
\alias{invsubdist}
\title{Simulation of Output from Cumulative Incidence Regression Model}
\usage{
sim_cif(
  cif,
  n,
  data = NULL,
  Z = NULL,
  rr = NULL,
  strata = NULL,
  drawZ = TRUE,
  cens = NULL,
  rrc = NULL,
  entry = NULL,
  Sentry = NULL,
  cumstart = c(0, 0),
  U = NULL,
  pU = NULL,
  type = NULL,
  extend = NULL,
  ...
)
}
\arguments{
\item{cif}{Output from \code{prop.odds.subdist} or \code{ccr} (\code{cmprsk}), 
or call \code{invsubdist} with cumulative and linear predictor.}

\item{n}{Number of simulations.}

\item{data}{Data frame to extract covariates.}

\item{Z}{Design matrix instead of data.}

\item{rr}{Relative risks.}

\item{strata}{Strata vector.}

\item{drawZ}{Logical; randomly sample from Z.}

\item{cens}{Censoring specification.}

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

\item{entry}{Delayed entry time.}

\item{Sentry}{Survival related to delayed entry.}

\item{cumstart}{Start cumulatives at time 0.}

\item{U}{Uniforms for drawing timing.}

\item{pU}{Uniforms for drawing event type.}

\item{type}{Model type: \code{"logistic"}, \code{"cloglog"}, or \code{"rr"}.}

\item{extend}{Extend piecewise constant with constant rate.}

\item{...}{Arguments for \code{sim_subdist}.}
}
\value{
Data frame with simulated event times, status, and covariates.
}
\description{
Simulates data that looks like fit from a fitted cumulative incidence model 
(Fine-Gray or logistic).
}
\examples{
data(bmt)
nsim <- 100

## logit cumulative incidence regression model 
cif <- cifreg(Event(time,cause)~platelet+age,data=bmt,cause=1)
estimate(cif)  
plot(cif,col=1)
simbmt <- sim_cif(cif,nsim,data=bmt)
dtable(simbmt,~cause)
scif <- cifreg(Event(time,cause)~platelet+age,data=simbmt,cause=1)
estimate(scif)
plot(scif,add=TRUE,col=2)

## Fine-Gray cloglog cumulative incidence regression model 
cif <- cifregFG(Event(time,cause)~strata(tcell)+age,data=bmt,cause=1)
estimate(cif)  
plot(cif,col=1)
simbmt <- sim_cif(cif,nsim,data=bmt)
scif <- cifregFG(Event(time,cause)~strata(tcell)+age,data=simbmt,cause=1)
estimate(scif)
plot(scif,add=TRUE,col=2)

################################################################
#  simulating several causes with specific cumulatives 
################################################################
cif1 <-  cifreg(Event(time,cause)~strata(tcell)+age,data=bmt,cause=1)
cif2 <-  cifreg(Event(time,cause)~strata(platelet)+tcell+age,data=bmt,cause=2)
cifss <-  list(cif1,cif2)
simbmt <- sim_cifs(list(cif1,cif2),nsim,data=bmt,extend=0.005)
scif1 <-  cifreg(Event(time,cause)~strata(tcell)+age,data=simbmt,cause=1)
scif2 <-  cifreg(Event(time,cause)~strata(platelet)+tcell+age,data=simbmt,cause=2)
cbind(cif1$coef,scif1$coef)   
## can be off due to restriction F1+F2<= 1    
cbind(cif2$coef,scif2$coef)   
    
par(mfrow=c(1,2))   
## Cause 1 follows the model    
plot(cif1); plot(scif1,add=TRUE,col=1:2,lwd=2)
# Cause 2:second cause is modified with restriction to satisfy F1+F2<= 1, so scaled down     
plot(cif2); plot(scif2,add=TRUE,col=1:2,lwd=2)

}
\seealso{
[simul_cifs()]
}
\author{
Thomas Scheike
}
\keyword{simulation}
\keyword{survival}
