# NOT RUN {
library(survival)
n=100
set.seed(10)
# Generate the data
TRT=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 difference in PBIR
# the analysis is truncated at time 8, which is slightly smaller than the largest follow-up time
fit=PBIR2(t2PROGRESSION=t2progression,
STATUS_PROGRESSION=delta_progression,
t2RESPONSE=t2response,
STATUS_RESPONSE=delta_response,
TRT=trt)
# Plot the estimated differnece in PBIR
tt=fit$time
diff=fit$diff
low=fit$ci.low
up=fit$ci.up
tt=c(0, tt)
diff=c(0, diff)
low=c(0, low)
up=c(0, up)
B=length(tt)
tt=rep(tt, rep(2, B))[-1]
diff=rep(diff, rep(2, B))[-(2*B)]
low=rep(low, rep(2, B))[-(2*B)]
up=rep(up, rep(2, B))[-(2*B)]
plot(range(c(fit$time, 0)), range(c(low, up)),
xlab="time", ylab="difference in PBIR",
lwd=2, type="n")
lines(tt, diff, lwd=2, col=3)
lines(tt, low, col=2)
lines(tt, up, col=2)
lines(range(fit$time), rep(0, 2), col=4, lty=4)
# }
Run the code above in your browser using DataLab