stremr icon indicating copy to clipboard operation
stremr copied to clipboard

using stremr without monitoring

Open marycombs opened this issue 6 years ago • 7 comments

Is it possible to use stremr without a monitoring variable? There does not seem to be a default for MONITOR in defineIntervedTRT(), so do I have to construct a pseudo monitoring variable for the function to work?

Thanks

marycombs avatar Apr 15 '18 20:04 marycombs

Certainly, everything should work fine without monitoring variable. Just never use any propensity scores for monitoring and don't define the monitoring variable name when loading the data (i.e., leave it as the default)

osofr avatar Apr 16 '18 02:04 osofr

I believe I have done as you describe -- can you help identify what is wrong with my minimal working example below? It breaks at the defineIntervedTRT() step.

require(stremr)
require(data.table)

# EXAMPLE WITH CENSORING
data(OdataCatCENS)
test_dat <- as.data.table(OdataCatCENS, key=c(ID, t))
test_dat <- test_dat[ , !c( "CatC" , "N" , "lastNat1") ]

# Regressions for modeling the exposure (TRT)
gform_TRT <- "TI ~ CVD + highA1c"
     
# Regressions for modeling censoring (CENS)
gform_CENS <- c("C ~ highA1c")

# Define dynamic rule: dhigh
test_dat <- defineIntervedTRT(test_dat, theta = c(1), ID = "ID", t = "t",
 I = "highA1c", CENS = "C", TRT = "TI", new.TRT.names = c( "dhigh" ), 
 return.allcolumns = TRUE)
     
# Estimate IPW-based hazard and survival (KM) for a rule "dhigh":
IPW_KM_res <- stremr(test_dat , intervened_TRT = "dhigh",
  ID = "ID", t = "t", covars = c("highA1c"),
  CENS = "C", gform_CENS = gform_CENS,
  TRT = "TI", gform_TRT = gform_TRT, OUTCOME = "Y.tplus1")
     
# Survival estimates by time:
IPW_KM_res$IPW_estimates
# Input data:
IPW_KM_res$dataDT

Edit: Changed a reference to MONITOR and lastNat1 in the stremr call. This is downstream of the defineIntervedTRT call though, so does not alter where the code first breaks.

marycombs avatar Apr 16 '18 03:04 marycombs

Sure, happy to help, would you mind copy pastying the entire log, including all errors?

Also, why are you testing the example with categorical censoring, any specific reason for that?

osofr avatar Apr 16 '18 03:04 osofr

I want to use a dynamic treatment rule, and the example I found in stremr documentation with DTR has categorical censoring -- you'll notice, however, that I am not using CatC, I am using C for censoring which is binary.

Also, I have altered the code in my original post to include libraries and exclude a errant reference to MONITOR (that was downstream of the defineIntervedTRT call, so I do not think affected where the code is breaking).

R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> require(stremr)
R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> 
> require(stremr)
Loading required package: stremr
stremr
Version: 0.4

stremr IS IN EARLY DEVELOPMENT STAGE.
Please be to sure to check for frequent updates and report bugs at: http://github.com/osofr/stremr
To install the latest development version of stremr, please type this in your terminal:
  devtools::install_github('osofr/stremr')

> require(data.table)
Loading required package: data.table
data.table 1.10.4.2
  The fastest way to learn (by data.table authors): https://www.datacamp.com/courses/data-analysis-the-data-table-way
  Documentation: ?data.table, example(data.table) and browseVignettes("data.table")
  Release notes, videos and slides: http://r-datatable.com
Warning message:
package 'data.table' was built under R version 3.4.2 
> 
> # EXAMPLE WITH CENSORING
> data(OdataCatCENS)
> test_dat <- as.data.table(OdataCatCENS, key=c(ID, t))
> test_dat <- test_dat[ , !c( "CatC" , "N" , "lastNat1") ]
> 
> # Regressions for modeling the exposure (TRT)
> gform_TRT <- "TI ~ CVD + highA1c"
>      
> # Regressions for modeling censoring (CENS)
> gform_CENS <- c("C ~ highA1c")
> 
> # Define dynamic rule: dhigh
> test_dat <- defineIntervedTRT(test_dat, theta = c(1), ID = "ID", t = "t",
+  I = "highA1c", CENS = "C", TRT = "TI", new.TRT.names = c( "dhigh" ), 
+  return.allcolumns = TRUE)
Error in names(data) %in% varname : 
  argument "MONITOR" is missing, with no default
>      
> # Estimate IPW-based hazard and survival (KM) for a rule "dhigh":
> IPW_KM_res <- stremr(test_dat , intervened_TRT = "dhigh",
+   ID = "ID", t = "t", covars = c("highA1c"),
+   CENS = "C", gform_CENS = gform_CENS,
+   TRT = "TI", gform_TRT = gform_TRT, OUTCOME = "Y.tplus1")
Error in CheckVarNameExists(OData$dat.sVar, Nnode) : 
  variable name N not found in data input
>      
> # Survival estimates by time:
> IPW_KM_res$IPW_estimates
Error: object 'IPW_KM_res' not found
> # Input data:
> IPW_KM_res$dataDT
Error: object 'IPW_KM_res' not found
> 

marycombs avatar Apr 16 '18 03:04 marycombs

Thanks for reporting,

Indeed this seems like a bug. My suggestion would be to take the code defineIntervention function and rewrite it to your own dynamic rule needs. Here is the link to the source code for the function: https://github.com/osofr/stremr/blob/e6cd51cea0531883cd195ed61f6f72b93b45528b/R/helper_routines.R#L380

Basically the monitoring variable is hardcoded into that function because we based it on our particular use case. You could easily comment that dependency out though. In general I would recommend writing your own functions for dynamic rule definitions (or any counterfactual intervention), because each rule is so different and no single function can accommodate them all. Perhaps you could use this function as a starting point.

Another point is that I would highly advice against using stremr function for getting all estimators at once. This will never provide you with the level of flexibility that individual estimator functions can provide, so I would just call each estimator function separately.

osofr avatar Apr 16 '18 16:04 osofr

Thank you!

marycombs avatar Apr 16 '18 20:04 marycombs

FYI noticed I had an older version of stremr -- the bug does not appear in the newer version. Thanks for your help, Oleg!

marycombs avatar Apr 19 '18 23:04 marycombs