# Using simulated data
# Example 1 - censored data ####################################################
n <- 1000
x1 <- runif(n); x2 <- runif(n) # covariates
t <- runif(n, 0, 1 + x1 + x2) # time variable (e.g., time to death)
c <- runif(n,0,5) # censoring variable (e.g., end of follow-up)
y <- pmin(t,c) # observed variable = min(t,c)
d <- (t <= c) # 1 = event (e.g., death), 0 = censored
CDF1 <- pchreg(Surv(y,d) ~ x1 + x2)
model1 <- ctqr(Surv(y,d) ~ x1 + x2, p = 0.5, CDF = CDF1)
model2 <- ctqr(Surv(y,d) ~ x1, p = 0.5, CDF = CDF1)
# model1 is identical to ctqr(Surv(y,d) ~ x1 + x2, p = 0.5)
# model2 is NOT identical to ctqr(Surv(y,d) ~ x1, p = 0.5),
# which would have default CDF = pchreg(Surv(y,d) ~ x1)
# Example 2 - censored and truncated data ######################################
n <- 1000
x1 <- runif(n); x2 <- runif(n) # covariates
t <- runif(n, 0, 1 + x1 + x2) # time variable
c <- runif(n,0,5) # censoring variable
y <- pmin(t,c) # observed variable = min(t,c)
d <- (t <= c) # 1 = event, 0 = censored
z <- rnorm(n) # truncation variable (e.g., time at enrollment)
w <- which(y > z) # data are only observed when y > z
z <- z[w]; y <- y[w]; d <- d[w]; x1 <- x1[w]; x2 <- x2[w]
# implement various CDFs and choose the model with smallest AIC
CDFs <- list(
pchreg(Surv(z,y,d) ~ x1 + x2, breaks = 5),
pchreg(Surv(z,y,d) ~ x1 + x2, breaks = 10),
pchreg(Surv(z,y,d) ~ x1 + x2 + x1:x2, breaks = 5),
pchreg(Surv(z,y,d) ~ x1 + x2 + x1^2 + x2^2, breaks = 10)
)
CDF <- CDFs[[which.min(sapply(CDFs, function(obj) AIC(obj)))]]
summary(ctqr(Surv(z,y,d) ~ x1 + x2, p = 0.5, CDF = CDF))
# Example 3 - interval-censored data ###########################################
# t is only known to be in the interval (t1,t2) ################################
n <- 1000
x1 <- runif(n); x2 <- runif(n) # covariates
t <- runif(n, 0, 10*(1 + x1 + x2)) # time variable
t1 <- floor(t) # lower extreme of the interval
t2 <- ceiling(t) # upper extreme of the interval
model <- ctqr(Surv(t1,t2, type = "interval2") ~ x1 + x2, p = 0.5)
Run the code above in your browser using DataLab