# rchaz: Simulation of Piecewise constant hazard model (Cox). In timereg: Flexible Regression Models for Survival Data

## Description

Simulates data from piecwise constant baseline hazard that can also be of Cox type. Censor data at highest value of the break points.

## Usage

 ```1 2 3 4 5 6 7 8 9``` ```rchaz( cumhazard, rr, n = NULL, entry = NULL, cum.hazard = TRUE, cause = 1, extend = FALSE ) ```

## Arguments

 `cumhazard` cumulative hazard, or piece-constant rates for periods defined by first column of input. `rr` relative risk for simulations, alternatively when rr=1 specify n `n` number of simulation if rr not given `entry` delayed entry time for simuations. `cum.hazard` specifies wheter input is cumulative hazard or rates. `cause` name of cause `extend` to extend piecewise constant with constant rate. Default is average rate over time from cumulative (when TRUE), if numeric then uses given rate.

## Details

For a piecewise linear cumulative hazard the inverse is easy to compute with and delayed entry x we compute

Λ^{-1}(Λ(x) + E/RR)

, where RR are the relative risks and E is exponential with mean 1. This quantity has survival function

P(T > t | T>x) = exp(-RR (Λ(t) - Λ(x)))

.

Thomas Scheike

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43``` ```rates <- c(0,0.01,0.052,0.01,0.04) breaks <- c(0,10, 20, 30, 40) haz <- cbind(breaks,rates) n <- 1000 X <- rbinom(n,1,0.5) beta <- 0.2 rrcox <- exp(X * beta) cumhaz <- cumsum(c(0,diff(breaks)*rates[-1])) cumhaz <- cbind(breaks,cumhaz) pctime <- rchaz(haz,n=1000,cum.hazard=FALSE) par(mfrow=c(1,2)) ss <- aalen(Surv(time,status)~+1,data=pctime,robust=0) plot(ss) lines(cumhaz,col=2,lwd=2) pctimecox <- rchaz(cumhaz,rrcox) pctime <- cbind(pctime,X) ssx <- cox.aalen(Surv(time,status)~+prop(X),data=pctimecox,robust=0) plot(ssx) lines(cumhaz,col=2,lwd=2) ### simulating data with hazard as real data data(TRACE) par(mfrow=c(1,2)) ss <- cox.aalen(Surv(time,status==9)~+prop(vf),data=TRACE,robust=0) par(mfrow=c(1,2)) plot(ss) ### pctime <- rchaz(ss\$cum,n=1000) ### sss <- aalen(Surv(time,status)~+1,data=pctime,robust=0) lines(sss\$cum,col=2,lwd=2) pctime <- rchaz(ss\$cum,rrcox) pctime <- cbind(pctime,X) ### sss <- cox.aalen(Surv(time,status)~+prop(X),data=pctime,robust=0) summary(sss) plot(ss) lines(sss\$cum,col=3,lwd=3) ```

timereg documentation built on Oct. 13, 2021, 5:06 p.m.