library(contsurvplot)
library(riskRegression)
library(survival)
library(splines)
library(ggplot2)
library(plotly)
# using data from the survival package
data(nafld, package="survival")
# take a random sample to keep example fast
set.seed(41)
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 survival for ages 50 to 80
plot_surv_3Dsurface(time="futime",
status="status",
variable="age",
data=nafld1,
model=model,
horizon=seq(50, 80, 0.5),
interactive=FALSE)
# plot effect of age on survival using an interactive plot for ages 50 to 80
plot_surv_3Dsurface(time="futime",
status="status",
variable="age",
data=nafld1,
model=model,
horizon=seq(50, 80, 0.5),
interactive=TRUE)
## showing non-linear effects
# fit cox-model with bmi modeled using B-Splines,
# adjusting for age
model2 <- coxph(Surv(futime, status) ~ age + bs(bmi, df=3),
data=nafld1, x=TRUE)
# plot effect of bmi on survival using normal plot
plot_surv_3Dsurface(time="futime",
status="status",
variable="bmi",
data=nafld1,
model=model2,
interactive=FALSE)
# plot effect of bmi on survival using interactive plot
plot_surv_3Dsurface(time="futime",
status="status",
variable="bmi",
data=nafld1,
model=model2,
interactive=TRUE)
Run the code above in your browser using DataLab