# NOT RUN {
library(cmprsk)
n=100
set.seed(10)
# Generate the data
trt=rbinom(n, 1, 0.5)
error=rnorm(n)
tr=exp(rnorm(n)+error-trt*0.5+0.5)
tp=exp(rnorm(n)+error+trt*0.25)
tr[tp<tr]=Inf
tc=runif(n, 3, 8.5)
t2response=pmin(tr, tc)
delta_response=1*(tr<tc)
t2progression=pmin(tp, tc)
delta_progression=1*(tp<tc)
# Estimate the PBIR in two groups
fit=CRR(t2PROGRESSION=t2progression,
STATUS_PROGRESSION=delta_progression,
t2RESPONSE=t2response,
STATUS_RESPONSE=delta_response,
TRT=trt)
fit
# Plot the estimated PBIR by group
tt1=c(0, fit$result1$time)
CRR1=c(0, fit$result1$CRR)
B1=length(tt1)
tt1=rep(tt1, rep(2, B1))[-1]
CRR1=rep(CRR1, rep(2, B1))[-(2*B1)]
tt0=c(0, fit$result0$time)
CRR0=c(0, fit$result0$CRR)
B0=length(tt0)
tt0=rep(tt0, rep(2, B0))[-1]
CRR0=rep(CRR0, rep(2, B0))[-(2*B0)]
plot(range(c(fit$result1$time, fit$result0$time)),
range(c(fit$result1$CRR, fit$result0$CRR)),
xlab="time", ylab="CRR",
main="black: group 0; red: group 1", type="n")
lines(tt0, CRR0, col=1)
lines(tt1, CRR1, col=2)
# }
Run the code above in your browser using DataLab