knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
# library(smim)
library(survRM2)
devtools::load_all()

Data Simulation

n <- 1000
t.time <- rexp(n)   # event time
c.time <- runif(n, min = 0.1, max = 5)  # censoring time

time <- pmin(t.time, c.time)

status <- as.numeric(t.time < c.time)

pattern <- ifelse(status == 1, 1, ifelse(time < 0.5, 2, 3))
group <- rep(c(0,1), each = 500)
plot(survfit(Surv(time, status) ~ group), col = 1:2)
table(status, pattern, time < 0.5)

MAR analysis

tau <- 3

survRM2 results

rmst2(time, status, group, tau = tau)

RMST within group

delta   <- c(1,1,1)[pattern]  # the third number control delta adjustment for MNAR 
tmp <- rmst_delta(time, status, x = rep(1, length(time)), group, pattern, delta, tau, n_mi = 5, n_b = 100, seed = 123)
tmp$rmst

RMST between group

diff_rmst <- function(rmst, sd){
  diff <- diff(rmst)
  diff_sd <- sqrt( sum(sd^2) )
  p_val <- 2* (1 - pnorm( abs(diff/diff_sd) ))
  c(diff = diff, sd = diff_sd, p = p_val)
}

rbind( diff_rmst(tmp$rmst[,"rmst"], tmp$rmst[, "sd"]), 
       diff_rmst(tmp$rmst[,"rmst"], tmp$rmst[, "wb_sd"]))


elong0527/smim documentation built on May 5, 2021, 1:03 p.m.