# NOT RUN {
data("GBSG2", package = "TH.data")
library("survival")
GBSG2$time <- as.numeric(GBSG2$time)
GBSG2$y <- with(GBSG2, Surv(time, cens))
### Cox proportional hazards model
m1 <- Coxph(y ~ horTh, data = GBSG2, support = c(1, 1500))
logLik(m1)
### Aalen additive hazards model with time-varying effects
m2 <- Aareg(y | horTh ~ 1, data = GBSG2, support = c(1, 1500))
logLik(m2)
### compare the hazard functions
nd <- data.frame(horTh = unique(GBSG2$horTh))
col <- 1:2
lty <- 1:2
plot(as.mlt(m1), newdata = nd, type = "hazard",
col = col, lty = lty[1], xlab = "time")
plot(as.mlt(m2), newdata = nd, type = "hazard",
col = col, lty = 2, add = TRUE)
legend("topright", col = rep(col, each = 2),
lty = rep(1:2), bty = "n",
legend = paste(rep(paste("horTh:",
levels(nd$horTh)), each = 2),
rep(c("Cox", "Aalen"), 2)))
# }
Run the code above in your browser using DataLab