Restricted mean survival time difference over a time period in R using RSMT2

19 views Asked by At

I would like to plot delta of RMST over a time period for two groups. X axis --> Time (year), Y axis --> Delta of RMST(days).

a=rmst2(time, status, arm, tau=10)
> print(a) 

Between-group contrast 
                   Est. lower .95 upper .95     p
RMST (arm=1)-(arm=0) -0.137    -0.939     0.665 0.738
RMST (arm=1)/(arm=0)  0.981     0.878     1.096 0.738
RMTL (arm=1)/(arm=0)  1.050     0.787     1.402 0.738

I would like to plot the above data (including confidence intervals) for all points of time. Is there a function in R to do that or can I somehow make an array or list of the following result object and plot it to achieve the same?

a$unadjusted.result 
1

There are 1 answers

0
Edward On

One way is to hack the survRM2:::plot.rmst2 function so that confidence intervals are passed on to the plot function. In the current version of the survRM2 package (1.0-4) they are not.

To hack the function, type the following at the R prompt:

survRM2:::plot.rmst2

Copy the code into a new R script file and add the following to the function call:

plot_rmst2 <- function (x, xlab = "", ylab = "", col = "red", col.RMST = "pink", 
          col.RMTL = "orange", density = 80, angle = 85, conf.int=TRUE, ...)

On lines 35 and 66, insert the following:

if(conf.int) lines(fit, lty=2, col="red")

Send the function to the R console so that it is available. Then call the function:

plot_rms2t(a)

enter image description here

Data:

library(survRM2)
D <- rmst2.sample.data()
time <- D$time
status <- D$status
arm <- D$arm
tau <- NULL
x <- D[,c(4,6,7)]
a <- rmst2(time, status, arm, tau=10)