The answer given by @Ron Jensen is incorrect. By simply calling the predict
function without specifying the newdata
argument, you are predicting the survival probability given the radiation.dose
and the observed value of time. You can easily see this because there is no clear relationship in your plot, which has to be the case since you used a cox-regression model.
If you want to plot the survival probability at t as a function of a continuous variable based on a cox-model, you can instead use the contsurvplot
package (https://cran.r-project.org/package=contsurvplot) I created. Using your example, you can do it like this:
library(survival)
library(contsurvplot)
set.seed(42)
days <- rpois(100, 365)
status <- rbinom(100, 1, 0.34)
radiation.dose <- sapply(status,function(x){ifelse(x==0, rnorm(1,80,20), rnorm(1,60,20))})
df <- data.frame(days,status,radiation.dose)
mod <- cox.mod<-coxph(Surv(days, status) ~ radiation.dose, data=df, x=TRUE)
plot_surv_at_t(time="days",
status="status",
variable="radiation.dose",
data=df,
model=cox.mod,
t=365)
By specifying t = 365
, you're telling the plot_surv_at_t
function to use the survival probability at 1 year.
Since there are no other independent variables in this cox model, this is equivalent to using:
vals <- seq(min(df$radiation.dose), max(df$radiation.dose), 1)
newdata <- data.frame(radiation.dose=vals,
days=365,
status=0)
p <- predict(cox.mod, type="surv", newdata=newdata)
plot(vals, p)
If there is no specific reason to use one value of time, I would however recommend to use survival area plots or survival contour plots instead, as described in detail in this preprint: https://arxiv.org/pdf/2208.04644.pdf