# NOT RUN {
library(survival)
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
fit1=PBIR1(t2PROGRESSION=t2progression[trt==1],
STATUS_PROGRESSION=delta_progression[trt==1],
t2RESPONSE=t2response[trt==1],
STATUS_RESPONSE=delta_response[trt==1])
fit0=PBIR1(t2PROGRESSION=t2progression[trt==0],
STATUS_PROGRESSION=delta_progression[trt==0],
t2RESPONSE=t2response[trt==0],
STATUS_RESPONSE=delta_response[trt==0])
# Plot the estimated PBIR by group
tt1=c(0, fit1$time)
PBIR1=c(0, fit1$PBIR)
B1=length(tt1)
tt1=rep(tt1, rep(2, B1))[-1]
PBIR1=rep(PBIR1, rep(2, B1))[-(2*B1)]
tt0=c(0, fit0$time)
PBIR0=c(0, fit0$PBIR)
B0=length(tt0)
tt0=rep(tt0, rep(2, B0))[-1]
PBIR0=rep(PBIR0, rep(2, B0))[-(2*B0)]
plot(range(c(fit1$time, fit0$time)), range(c(fit1$PBIR, fit0$PBIR)),
xlab="time", ylab="PBIR",
main="black: group 0; red: group 1", type="n")
lines(tt0, PBIR0, col=1)
lines(tt1, PBIR1, col=2)
# }
Run the code above in your browser using DataLab