--- title: "Introduction to cpsurvsim" author: "Camille J Hochheimer" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Introduction to cpsurvsim} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` When using real-life datasets, hazard rates are hardly constant nor do they follow a prescribed distribution. Change-point hazard functions allow researchers to model more complex time-to-event patterns. Functions with more than one change-point allow for additional flexibility. The `cpsurvsim` package allows users to simulate time-to-event data from the exponential (or piecewise constant) hazard function and the Weibull hazard function. Two simulation methods are provided: the inverse CDF method and a memoryless method exploiting the memoryless property of survival data. In survival analysis, the probability that an individual experiences an event at time $t$ is independent of the probability that they experience an event up to that point. The memoryless method of simulation uses that assumption in the sense that the probability an event occurs after a change-point is independent of the probability of an event occuring before the change-point. In this way, data in between change-points are simulated from independent exponential or Weibull hazard distributions with scale parameters $\theta$ corresponding to each time interval. ## Exponential change-point / piecewise constant hazard function For multiple change-points, the exponential change-point hazard function (also known as the piecewise constant hazard function) for $K$ change-points is $\begin{eqnarray} h(t)&=&\begin{cases} \theta_1 & 0\leq t<\tau_1\\ \theta_2 & \tau_1\leq t <\tau_2\\ \vdots & \vdots \\ \theta_{K+1} & t\geq\tau_K \end{cases} \end{eqnarray}$. The CDF method implemented in `exp_cdfsim` draws on the work of Walke^[Rainer Walke. Example for a piecewise constant hazard data simulation in R. Max Planck Institute for Demographic Research, 2010. ], using the relationship between the CDF and cumulative hazard function, $1-F(t) = \exp(−H(t))$, in order to simulate data. Specifically, we generate values ($x$) from the exponential distribution and substitute them into the inverse hazard function $\begin{eqnarray} H^{-1}(x)&=&\begin{cases} \frac{x}{\theta_1} & 0\leq x