Closed sahirbhatnagar closed 4 years ago
Here's another example using the Stanford Transplant data. The first graph clearly shows the non-proportional hazards.
library(survival)
library(casebase)
#> See example usage at http://sahirbhatnagar.com/casebase/
library(splines)
library(tidyverse)
# Fit several models
fit1 <- fitSmoothHazard(fustat ~ transplant,
data = jasa, time = "futime")
fit2 <- fitSmoothHazard(fustat ~ transplant + futime,
data = jasa, time = "futime")
fit3 <- fitSmoothHazard(fustat ~ transplant + bs(futime),
data = jasa, time = "futime")
fit4 <- fitSmoothHazard(fustat ~ transplant*bs(futime),
data = jasa, time = "futime")
#> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
# Compute AIC
AIC(fit1)
#> [1] 803.5401
AIC(fit2)
#> [1] 763.7171
AIC(fit3)
#> [1] 751.0198
AIC(fit4)
#> [1] 751.7766
# Compute hazards
hazard_data <- expand.grid(transplant = c(0, 1),
futime = seq(0, 1000,
length.out = 100)) %>%
mutate(offset = 0)
hazard_data <- hazard_data %>%
mutate(hazard = predict(fit4, newdata = hazard_data,
type = "link"),
hazard = exp(hazard),
Status = factor(transplant,
labels = c("NoTrans", "Trans")))
hazard_data %>%
ggplot(aes(futime, hazard, colour = Status)) +
geom_line() +
theme_minimal() +
theme(legend.position = 'top') +
ylab('Hazard')
# Compute absolute risk curves
newdata <- data.frame(transplant = c(0, 1))
absrisk <- absoluteRisk(fit4, newdata = newdata,
time = seq(0, 1000, length.out = 100))
colnames(absrisk) <- c("Time", "NoTrans", "Trans")
absrisk %>%
as.data.frame %>%
gather("Status", "Risk", -Time) %>%
ggplot(aes(Time, Risk, colour = Status)) +
geom_line() +
theme_minimal() +
theme(legend.position = 'top') +
expand_limits(y = 1)
Created on 2019-11-24 by the reprex package (v0.3.0)
I just read more carefully the section in Kalbfleisch and Prentice where they describe the Stanford transplant data, and I think it would be a great case study for the paper, for two reasons:
I'll work on this over the next few days and add it to the paper, unless there are any objections (e.g. you already wrote a case-study based on the data above).
As @turgeonmaxime pointed out in a conference call July 29, 2019, we need to sell the non-proportionality aspect of casebase. Here I use the simsurv R package to simulate data under a standard Weibull survival model that incorporates a time-dependent treatment effect. Here I compare to the rstpm2 package:
Created on 2019-07-29 by the reprex package (v0.2.1)