wilsoncai1992 / MOSS

(Model One-Step Survival): one-step TMLE for survival curve
https://wilsoncai1992.github.io/MOSS/
BSD 3-Clause "New" or "Revised" License
5 stars 6 forks source link

issues related to MOSS_hazard_ate #11

Closed aybolek closed 4 years ago

aybolek commented 4 years ago

Hi Wilson,

I am in Mark’s survival analysis class and it was recommended that we use your R package for our final project. We are experiencing an issue related to the iterate_onestep() function within MOSS_hazard_ate() (moss_ate.R). Specifically, when we call iterate_onestep() we get the error:

library(tidyverse) library(MOSS) library(survival)

data("diabetic")

xenon <- diabetic %>% filter(laser == "xenon")

argon <- diabetic %>% filter(laser == "argon")

xenon vs control

T_tilde <- xenon$time Delta <- xenon$status A <- xenon$trt W <- xenon[, c(3, 4, 6)] t_max <- max(T_tilde) fit <- initial_sl_fit(T_tilde, Delta, A, W, t_max, sl_failure = c("SL.glm", "SL.mean"), sl_censoring = c("SL.glm", "SL.mean"), sl_treatment = c("SL.glm", "SL.mean"))

ate <- MOSS_hazard_ate$new( A, T_tilde, Delta, fit$density_failure_1, fit$density_censor_1, fit$density_failure_0, fit$density_censor_0, fit$g1W )

moss_ate <- ate$iterate_onestep()

moss_ate <- ate$iterate_onestep() Error in max(self$T_tilde) : invalid 'type' (environment) of argument

It seems like T_tilde from MOSS_hazard_ate$new is not a vector, but a function?

Also, for the arguments of MOSS_hazard_ate$new(), should density_failure and density_censor be density_failure_1 and density_censor_1?

Thanks!

wilsoncai1992 commented 4 years ago

Hi @aybolek , I just saw this and have replied you via email.

Here is a repost of the answers

library(tidyverse)
library(MOSS)
library(survival)

data("diabetic")

xenon <- diabetic %>%
  filter(laser == "xenon")

argon <- diabetic %>%
  filter(laser == "argon")

# xenon vs control
T_tilde <- xenon$time
Delta <- xenon$status
A <- xenon$trt
W <- xenon[, c(3, 4, 6)]
t_max <- max(T_tilde)
fit <- initial_sl_fit(T_tilde, Delta, A, W, t_max,
                      sl_failure = c("SL.glm", "SL.mean"),
                      sl_censoring = c("SL.glm", "SL.mean"),
                      sl_treatment = c("SL.glm", "SL.mean"))

# the `density_failure_1` and `density_failure_0` should both go through the `hazard_to_survival` method which populates the `survival` attribute of the object, before being plugged into the `MOSS_hazard_ate`
# I could have added more graceful checks and error messages in the `MOSS_hazard_ate`
# I will add this
fit$density_failure_1$hazard_to_survival()
fit$density_failure_0$hazard_to_survival()
ate <- MOSS_hazard_ate$new(
  # note that I use named arguments here
  # if you would like to use unnamed arguments, the order is slightly different from that of `MOSS_hazard`
  A = A,
  T_tilde = T_tilde,
  Delta = Delta,
  density_failure = fit$density_failure_1,
  density_censor = fit$density_censor_1,
  density_failure_0 = fit$density_failure_0,
  density_censor_0 = fit$density_censor_0,
  fit$g1W
)
moss_ate <- ate$iterate_onestep()
# should work now