stremr: Run all estimators (KM, hazard-IPW, direct-IPW, GCOMP plug-in...

Description Usage Arguments Value See Also Examples

View source: R/stremr.R

Description

Estimate the causal survival curve for a particular stochastic, dynamic or static intervention on the treatment/exposure and monitoring process. Implements the IPW (Inverse Probability-Weighted or Horvitz-Thompson) estimator of the discrete survival hazard function which is mapped into survival function.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
stremr(
  data,
  ID = "Subj_ID",
  t_name = "time_period",
  covars,
  CENS = "C",
  TRT = "A",
  MONITOR = "N",
  OUTCOME = "Y",
  gform_CENS,
  gform_TRT,
  gform_MONITOR,
  stratify_CENS = NULL,
  stratify_TRT = NULL,
  stratify_MONITOR = NULL,
  intervened_TRT = NULL,
  noCENScat = 0L,
  remove_extra_rows = TRUE,
  nfolds = NULL,
  models_CENS = sl3::Lrnr_glm_fast$new(family = quasibinomial()),
  models_TRT = sl3::Lrnr_glm_fast$new(family = quasibinomial()),
  models_MONITOR = sl3::Lrnr_glm_fast$new(family = quasibinomial()),
  fit_method_g = "none",
  models_Q = sl3::Lrnr_glm_fast$new(family = quasibinomial()),
  fit_method_Q = "none",
  Qforms = NULL,
  tvals = NULL,
  stratifyQ_by_rule = TRUE,
  trunc_IPW_MSM = Inf,
  trunc_IPW_TMLE = Inf,
  seed = NULL,
  MSMGLMpkg = c("speedglm", "h2o"),
  tbreaks = NULL,
  start_h2o_cluster = TRUE,
  nthreads = 2,
  verbose = getOption("stremr.verbose")
)

Arguments

data

Input data in long format. Can be a data.frame or a data.table with named columns, containing the time-varying covariates (covars), the right-censoring event indicator(s) (CENS), the exposure variable(s) (TRT), the monitoring process variable(s) (MONITOR) and the survival OUTCOME variable (OUTCOME).

ID

Unique subject identifier column name in data.

t_name

The name of the time/period variable in data.

covars

Vector of names with time varying and baseline covariates in data. This argument does not need to be specified, by default all variables that are not in ID, t, CENS, TRT, MONITOR and OUTCOME will be considered as covariates.

CENS

Column name of the censoring variable(s) in data. Each separate variable specified in CENS can be either binary (0/1 valued integer) or categorical (integer). For binary indicators of CENSoring, the value of 1 indicates the CENSoring or end of follow-up event (this cannot be changed). For categorical CENSoring variables, by default the value of 0 indicates no CENSoring / continuation of follow-up and other values indicate different reasons for CENSoring. Use the argument noCENScat to change the reference (continuation of follow-up) category from default 0 to any other value. (NOTE: Changing noCENScat has zero effect on coding of the binary CENSoring variables, those have to always use 1 to code the CENSoring event). Note that factors are not allowed in CENS.

TRT

A column name in data for the exposure/treatment variable(s).

MONITOR

A column name in data for the indicator(s) of monitoring events.

OUTCOME

A column name in data for the survival OUTCOME variable name, code as 1 for the outcome event.

gform_CENS

Regression formula(s) for estimating the propensity score for the censoring mechanism: P(C(t) | W). See Details.

gform_TRT

Regression formula(s) for propensity score for the exposure/treatment(s): P(A(t) | W). See Details.

gform_MONITOR

Regression formula(s) for estimating the propensity score for the MONITORing process: P(N(t) | W). See Details. (the observed exposure mechanism), When omitted the regression is defined by sA~sW, where sA

stratify_CENS

A named list with one item per variable in CENS. Each list item is a character vector of stratification subsets for the corresponding variable in CENS.

stratify_TRT

A named list with one item per variable in TRT. Each list item is a character vector of stratification subsets for the corresponding variable in TRT.

stratify_MONITOR

A named list with one item per variable in MONITOR. Each list item is a character vector of stratification subsets for the corresponding variable in MONITOR.

intervened_TRT

Column name in data containing the counterfactual probabilities of following a specific treatment regimen.

noCENScat

Same as in importData.

remove_extra_rows

Same as in importData.

nfolds

Number of folds for cross-validation (leave as NULL if no cross-validation is desired).

models_CENS

Same as in fitPropensity.

models_TRT

Same as in fitPropensity.

models_MONITOR

Same as in fitPropensity.

fit_method_g

Same as fit_method in fitPropensity.

models_Q

Same as models in fit_GCOMP.

fit_method_Q

Same as fit_method in fit_GCOMP.

Qforms

Same as in fit_GCOMP.

tvals

Same as in fit_GCOMP.

stratifyQ_by_rule

Same as in fit_GCOMP.

trunc_IPW_MSM

Weight truncation for IPW-based functions.

trunc_IPW_TMLE

Weight trunction for TMLE.

seed

Random generator seed.

MSMGLMpkg

Package to use for MSM GLM fits (see survMSM).

tbreaks

Same as in survMSM.

start_h2o_cluster

Start h2o cluster?

nthreads

Number of threads (CPUs) to use for h2o cluster?

verbose

Set to TRUE to print messages on status and information to the console. Turn this on by default using options(stremr.verbose=TRUE).

Value

...

See Also

stremr-package for the general overview of the package,

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#-------------------------------------------------------------------
# EXAMPLE WITH CATEGORICAL CENSORING (3 levels)
#-------------------------------------------------------------------
require("data.table")
require("magrittr")
data(OdataCatCENS)
OdataDT <- as.data.table(OdataCatCENS, key=c("ID", "t"))
# Indicator that the person has never been treated in the past:
OdataDT[, "barTIm1eq0" := as.integer(c(0, cumsum(TI)[-.N]) %in% 0), by = ID]
# 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]

#-------------------------------------------------------------------
# Regressions for modeling the exposure (TRT)
#-------------------------------------------------------------------
gform_TRT <- "TI ~ CVD + highA1c + N.tminus1"
# Fit a separate model for TRT (stratify) for each of the following subsets:
stratify_TRT <- list(
  TI=c(
       # MODEL TI AT t=0
       "t == 0L",
       # MODEL TRT INITATION WHEN MONITORED
       "(t > 0L) & (N.tminus1 == 1L) & (barTIm1eq0 == 1L)",
       # MODEL TRT INITATION WHEN NOT MONITORED
       "(t > 0L) & (N.tminus1 == 0L) & (barTIm1eq0 == 1L)",
       # MODEL TRT CONTINUATION (BOTH MONITORED AND NOT MONITORED)
       "(t > 0L) & (barTIm1eq0 == 1L)"
      ))

#-------------------------------------------------------------------
# Regressions for modeling the categorical censoring (CENS)
#-------------------------------------------------------------------
gform_CENS <- c("CatC ~ highA1c")
# stratify by time-points (separate model for all t<16 and t=16)
stratify_CENS <- list(CatC=c("t < 16", "t == 16"))

#-------------------------------------------------------------------
# Regressions for modeling the monitoring regimen (MONITOR)
#-------------------------------------------------------------------
# Intercept only model, pooling across all time points t
gform_MONITOR <- "N ~ 1"

#-------------------------------------------------------------------
# Define the counterfactual monitoring regimen of interest
#-------------------------------------------------------------------
# probability of being monitored at each t is 0.1
OdataDT[, "gstar.N" := 0.1]

# Define two dynamic rules: dlow & dhigh
OdataDT <- defineIntervedTRT(OdataDT, theta = c(0,1), ID = "ID", t = "t", I = "highA1c",
                            CENS = "C", TRT = "TI", MONITOR = "N", tsinceNis1 = "lastNat1",
                            new.TRT.names = c("dlow", "dhigh"), return.allcolumns = TRUE)

# # Estimate IPW-based hazard and survival (KM) for a rule "dhigh":
# IPW_KM_res <- stremr(OdataDT, intervened_TRT = "dhigh", intervened_MONITOR = "gstar.N",
#               ID = "ID", t = "t", covars = c("highA1c", "lastNat1"),
#               CENS = "CatC", gform_CENS = gform_CENS, stratify_CENS = stratify_CENS,
#               TRT = "TI", gform_TRT = gform_TRT, stratify_TRT = stratify_TRT,
#               MONITOR = "N", gform_MONITOR = gform_MONITOR, OUTCOME = "Y.tplus1")

# # Survival estimates by time:
# IPW_KM_res$estimates
# # Input data:
# IPW_KM_res$dataDT

osofr/estimtr documentation built on Jan. 25, 2022, 8:05 a.m.