# \donttest{
# Cox model for the composite event death or transplantation
pbc2.id$status2 <- as.numeric(pbc2.id$status != 'alive')
pbc2$status2 <- as.numeric(pbc2$status != 'alive')
CoxFit <- coxph(Surv(years, status2) ~ sex, data = pbc2.id)
# a linear mixed model for log serum bilirubin
fm1 <- lme(log(serBilir) ~ ns(year, 3) * sex, data = pbc2,
random = list(id = pdDiag(~ ns(year, 3))))
# the joint model
jointFit <- jm(CoxFit, fm1, time_var = "year", save_random_effects = TRUE)
ppcheck(jointFit)
FF <- function (t, betas, bi, data) {
sex <- as.numeric(data$sex == "female")
NS <- ns(t, k = c(0.9911, 3.9863), B = c(0, 14.10579))
X <- cbind(1, NS, sex, NS * sex)
Z <- cbind(1, NS)
eta <- c(X %*% betas[[1]]) + rowSums(Z * bi)
cbind(eta)
}
ppcheck(jointFit, process = "event", Fforms_fun = FF)
# }
Run the code above in your browser using DataLab