library(contsurvplot)
library(riskRegression)
library(survival)
library(ggplot2)
library(splines)
# using data from the survival package
data(nafld, package="survival")
# take a random sample to keep example fast
set.seed(42)
nafld1 <- nafld1[sample(nrow(nafld1), 150), ]
# fit cox-model with age
model <- coxph(Surv(futime, status) ~ age, data=nafld1, x=TRUE)
# plot effect of age on the RMST for ages 50 to 80
plot_surv_rmtl(time="futime",
status="status",
variable="age",
data=nafld1,
model=model,
horizon=seq(50, 80, 1),
tau=2500)
# plot RMST for multiple tau values for ages 50 to 80
plot_surv_rmtl(time="futime",
status="status",
variable="age",
data=nafld1,
model=model,
horizon=seq(50, 80, 1),
tau=c(2000, 3000, 5000))
## showing non-linear effects
# fit cox-model with bmi modeled using B-Splines,
# adjusting for age and sex
model2 <- coxph(Surv(futime, status) ~ age + male + bs(bmi, df=3),
data=nafld1, x=TRUE)
# plot effect of bmi on survival
plot_surv_rmtl(time="futime",
status="status",
variable="bmi",
data=nafld1,
model=model2,
tau=c(2000, 3000, 5000))
Run the code above in your browser using DataLab