# Simulate right-censored data
n <- 1000
x <- runif(n) # a covariate
time <- rexp(n, exp(1 + x)) # time-to-event
cens <- runif(n,0,2) # censoring event
y <- pmin(time,cens) # observed variable
d <- (time <= cens) # indicator of the event
model <- pchreg(Surv(y,d) ~ x, breaks = 10)
# Simulate right-censored, left-truncated data
n <- 1000
x <- runif(n) # a covariate
time0 <- rexp(n, 10) # time at enrollment
time <- rexp(n, exp(1 + x)) # time-to-event
cens <- runif(n,0,2) # censoring event
# y,d,x are only observed if (y > time0)
y <- pmin(time,cens)
d <- (time <= cens)
u <- (y > time0)
y <- y[u]
d <- d[u]
x <- x[u]
z <- time0[u]
model <- pchreg(Surv(z,y,d) ~ x, breaks = 10)
# Simulate interval-censored data
n <- 1000
x <- runif(n) # a covariate
time <- 10*rexp(n, exp(1 + x)) # time-to-event
time1 <- floor(time)
time2 <- ceiling(time)
# Individuals are observed at discrete times
# I observe (time1,time2) such that time1 <= time <= time2
model <- pchreg(Surv(time1,time2, type = "interval2") ~ x, breaks = 10)
# Try summary(model), predict(model)
# See the documentation of predict.pch for more examples
Run the code above in your browser using DataLab