romainkp / stremr

Streamlined Estimation for Static, Dynamic and Stochastic Treatment Regimes in Longitudinal Data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

option : return_wts = TRUE dose not work for survNPMSM and only return results when used in directIPW

Soudi00 opened this issue · comments

Please see the example from the documentation of the functions bellow:

the return_wts option dose not return value when survNPMSM function is called.

----------------------------------------------------------------------

Simulated Data

----------------------------------------------------------------------

data(OdataNoCENS)
OdataDT <- as.data.table(OdataNoCENS, key=c(ID, t))

define lagged N, first value is always 1 (always monitored at the first time point):

OdataDT[, ("N.tminus1") := shift(get("N"), n = 1L, type = "lag", fill = 1L), by = ID]
OdataDT[, ("TI.tminus1") := shift(get("TI"), n = 1L, type = "lag", fill = 1L), by = ID]

----------------------------------------------------------------------

Define intervention (always treated):

----------------------------------------------------------------------

OdataDT[, ("TI.set1") := 1L]
OdataDT[, ("TI.set0") := 0L]

----------------------------------------------------------------------

Import Data

----------------------------------------------------------------------

OData <- importData(OdataDT, ID = "ID", t = "t", covars = c("highA1c", "lastNat1", "N.tminus1"),
CENS = "C", TRT = "TI", MONITOR = "N", OUTCOME = "Y.tplus1")

----------------------------------------------------------------------

Look at the input data object

----------------------------------------------------------------------

print(OData)

----------------------------------------------------------------------

Access the input data

----------------------------------------------------------------------

get_data(OData)

----------------------------------------------------------------------

Model the Propensity Scores

----------------------------------------------------------------------

gform_CENS <- "C ~ highA1c + lastNat1"
gform_TRT = "TI ~ CVD + highA1c + N.tminus1"
gform_MONITOR <- "N ~ 1"
stratify_CENS <- list(C=c("t < 16", "t == 16"))

----------------------------------------------------------------------

Fit Propensity Scores

----------------------------------------------------------------------

OData <- fitPropensity(OData, gform_CENS = gform_CENS,
gform_TRT = gform_TRT,
gform_MONITOR = gform_MONITOR,
stratify_CENS = stratify_CENS)

----------------------------------------------------------------------

IPW Ajusted KM or Saturated MSM

----------------------------------------------------------------------

require("magrittr")
AKME.St.1 <- getIPWeights(OData, intervened_TRT = "TI.set1") %>%
survNPMSM(OData, return_wts = TRUE) %$%
estimates
AKME.St.1$wts_data

----------------------------------------------------------------------

Bounded IPW

----------------------------------------------------------------------

IPW.St.1 <- getIPWeights(OData, intervened_TRT = "TI.set1") %>%
directIPW(OData, return_wts = TRUE)
IPW.St.1$wts_data

Thanks for opening the issue. This is true, but on the other hand, why do you need it to return the weights? The weights are already returned by the call getIPWeights(OData, intervened_TRT = "TI.set1") , so you could for the time being just save those weights and inspect them. The weights returned by directIPW would be equivalent to those.

Thank you, I'm trying to replicates the weights given by directIPW with a program I wrote myself. I was not able to do that yet. I was wondering if you can point me to the source code that runs this analysis or refer me to a paper that your method is based on.

thank you I was able to replicate the weights.

Thanks, closing the issue for now.