# NOT RUN {
# }
# NOT RUN {
# }
# NOT RUN {
set.seed(1234)
n <- 50 # sample size
x <- runif(n, 0, 1) # time variable of interest
z <- rbinom(n, 1, 1 / 4) # competing event indicator
# truncation variables
u <- runif(n, -.25, .5) # left truncation variable
v <- u + .75 # right truncation variable
# note: (u,v) is independent of (x,z) so both estimation methods are consistent
# truncating the sample:
for (i in 1:n) {
while (u[i] > x[i] | v[i] < x[i]) {
x[i] <- runif(1, 0, 1)
z[i] <- rbinom(1, 1, 1 / 4)
u[i] <- runif(1, -.25, .5)
v[i] <- u[i] + .75
}
}
# note: (u,v) since is independent of (x,z)
# both estimation methods are consistent:
res.i <- DTDAcif(x, u, v, z, method = "indep", boot = TRUE)
res.d <- DTDAcif(x, u, v, z, method = "dep", boot = TRUE)
oldpar <- par(mfrow=c(1,2))
plot(res.i, main = "Indep trunc", intervals = TRUE)
plot(res.d, main = "Cond indep trunc", intervals = TRUE)
summary(res.i)
summary(res.d)
plot(res.i$data$x, res.i$biasf, type = "s") # the observational bias
# the observational bias, event 1
plot(res.d$data$x[res.d$data$z == 1], res.d$biasf$biasf_1, type = "s")
# the observational bias, event 2
lines(res.d$data$x[res.d$data$z == 2], res.d$biasf$biasf_2, type = "s", col = 2)
par(oldpar)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab