knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
# library(smim) library(survRM2) devtools::load_all()
3: MNAR imputation
Delta
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)
tau <- 3
rmst2(time, status, group, tau = tau)
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
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"]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.