romainkp / stremr

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

using stremr without monitoring

marycombs opened this issue · 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

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)

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.

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?

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
> 

Thank you!

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