# NOT RUN {
m_gamma <- emfrail(formula = Surv(time, status) ~ rx + sex + cluster(litter),
data = rats)
# Inverse Gaussian distribution
m_ig <- emfrail(formula = Surv(time, status) ~ rx + sex + cluster(litter),
data = rats,
distribution = emfrail_dist(dist = "pvf"))
# for the PVF distribution with m = 0.75
m_pvf <- emfrail(formula = Surv(time, status) ~ rx + sex + cluster(litter),
data = rats,
distribution = emfrail_dist(dist = "pvf", pvfm = 0.75))
# for the positive stable distribution
m_ps <- emfrail(formula = Surv(time, status) ~ rx + sex + cluster(litter),
data = rats,
distribution = emfrail_dist(dist = "stable"))
# }
# NOT RUN {
# Compare marginal log-likelihoods
models <- list(m_gamma, m_ig, m_pvf, m_ps)
models
logliks <- lapply(models, logLik)
names(logliks) <- lapply(models,
function(x) with(x$distribution,
ifelse(dist == "pvf",
paste(dist, "/", pvfm),
dist))
)
logliks
# }
# NOT RUN {
# Stratified analysis
# }
# NOT RUN {
m_strat <- emfrail(formula = Surv(time, status) ~ rx + strata(sex) + cluster(litter),
data = rats)
# }
# NOT RUN {
# Test for conditional proportional hazards (log-frailty as offset)
# }
# NOT RUN {
m_gamma <- emfrail(formula = Surv(time, status) ~ rx + sex + cluster(litter),
data = rats, control = emfrail_control(zph = TRUE))
par(mfrow = c(1,2))
plot(m_gamma$zph)
# }
# NOT RUN {
# Draw the profile log-likelihood
# }
# NOT RUN {
fr_var <- seq(from = 0.01, to = 1.4, length.out = 20)
# For gamma the variance is 1/theta (see parametrizations)
pll_gamma <- emfrail_pll(formula = Surv(time, status) ~ rx + sex + cluster(litter),
data = rats,
values = 1/fr_var )
plot(fr_var, pll_gamma,
type = "l",
xlab = "Frailty variance",
ylab = "Profile log-likelihood")
# Recurrent events
mod_rec <- emfrail(Surv(start, stop, status) ~ treatment + cluster(id), bladder1)
# The warnings appear from the Surv object, they also appear in coxph.
plot(mod_rec, type = "hist")
# }
# NOT RUN {
# Left truncation
# }
# NOT RUN {
# We simulate some data with truncation times
set.seed(2018)
nclus <- 300
nind <- 5
x <- sample(c(0,1), nind * nclus, TRUE)
u <- rep(rgamma(nclus,1,1), each = 3)
stime <- rexp(nind * nclus, rate = u * exp(0.5 * x))
status <- ifelse(stime > 5, 0, 1)
stime[status == 0] <- 5
# truncate uniform between 0 and 2
ltime <- runif(nind * nclus, min = 0, max = 2)
d <- data.frame(id = rep(1:nclus, each = nind),
x = x,
stime = stime,
u = u,
ltime = ltime,
status = status)
d_left <- d[d$stime > d$ltime,]
mod <- emfrail(Surv(stime, status)~ x + cluster(id), d)
# This model ignores the left truncation, 0.378 frailty variance:
mod_1 <- emfrail(Surv(stime, status)~ x + cluster(id), d_left)
# This model takes left truncation into account,
# but it considers the distribution of the frailty unconditional on the truncation
mod_2 <- emfrail(Surv(ltime, stime, status)~ x + cluster(id), d_left)
# This is identical with:
mod_cox <- coxph(Surv(ltime, stime, status)~ x + frailty(id), data = d_left)
# The correct thing is to consider the distribution of the frailty given the truncation
mod_3 <- emfrail(Surv(ltime, stime, status)~ x + cluster(id), d_left,
distribution = emfrail_dist(left_truncation = TRUE))
summary(mod_1)
summary(mod_2)
summary(mod_3)
# }
Run the code above in your browser using DataLab