Plotting survival plots after brm

Hello, is there any code available to plot survival curves from a model with brms, based on covariates?

I am not aware of code for this. There is a longstanding issue in brms to implement survival curves though:

I thought the code could be implemented relatively easily and would be a nice improvement for medical statistics. So I wanted to ask if this is correct, particularly the credibility interval for survival rates. I wish someone could help, as we could leave the code written for other users to plot the curves. So, if possible, I would ask for some feedback.
For example, using a multivariable lognormal model with brm, the fitted function could be used to estimate the linear predictor. For example:

   fit<-brm_multiple(SGm | cens(1-Die)  ~ treat+X1+X2+X3, prior=prior, data = imp,family = lognormal(), 

newdata = expand.grid(
      X3=TRUE )) 

    fi <- data.frame(fitted(fit, newdata=newdata, scale="linear",summary = FALSE))
    LETTERS2<-c(LETTERS [1:2])
    colnames(fi) <- LETTERS2
    fi$Effect <- exp( fi$B - fi$A)

After that, survival could be estimated by applying the equation of the lognormal model. My doubt is whether or not for the survival credible interval it would be correct to use the upper and lower limits of the linear predictor credible interval, as follows.

st<-1 - pnorm((log(tt) - median_qi(fi$B)$y) / sigma)
sti<-1 - pnorm((log(tt) - median_qi(fi$B)$ymin) / sigma)
stu<-1 - pnorm((log(tt) - median_qi(fi$B)$ymax) / sigma)
sd<-1 - pnorm((log(tt) - median_qi(fi$A)$y) / sigma)
sdi<-1 - pnorm((log(tt) - median_qi(fi$A)$ymin) / sigma)
sdu<-1 - pnorm((log(tt) - median_qi(fi$A)$ymax) / sigma)

After that it should be trivial plotting the survival curve with something like this. The geom_ribbon function of ggplot2 would paint the confidence band, but I’m not sure if it’s correct. Visually it looks a bit wide to me.

datst<-data.frame(sur=st, sui=sti, suu=stu, tt=tt, reg="Treatment 1")
datsd<-data.frame(sur=sd, sui=sdi, suu=sdu, tt=tt, reg="Treatment 2")
dat1<-dat [dat$reg=="Treatment 1",]
dat2<-dat [dat$reg=="Treatment 2",]
mycolors<-c("steelblue3", "black")

  geom_line(aes(colour=factor(reg),linetype = factor(reg)), size=1.25, 
  show.legend=FALSE) +
  ylab("Survival probability")+
  geom_ribbon(aes(ymin=sui, ymax=suu, fill = factor(reg)), alpha = 0.1)+    
  theme_minimal_grid() +theme(text = element_text(size=18))+
  scale_fill_manual("",values = mycolors)+
  scale_color_manual("",values = mycolors) +
  scale_x_continuous(breaks =seq(0,36,6))

Median OS to add in the text could be:
text<-paste(“Median OS with DPF:”,round(as.numeric(median_qi(exp(fi$B))[1]),1),“months”)
text2<-paste(“Median OS with PF:”,round(as.numeric(median_qi(exp(fi$A))[1]),1),“months”)

I added an eye plot and obtained this:

But not sure if the credible bands are accurate.

I’ve been working through the survival analysis sections of Singer and Willett’s (2003) text with brms here. Chapters 9 and above are the most relevant.