threshold: Threshold Intervention

View source: R/interventions.R

thresholdR Documentation

Threshold Intervention

Description

This function implements a threshold intervention (i.e., once treatment bypasses a certain threshold, it remains at that threshold until end of follow-up) for the specified intervention variable in the data table newdf.

Usage

threshold(newdf, pool, intvar, intvals, time_name, t)

Arguments

newdf

Data table containing the simulated data at time t.

pool

Data table containing the simulated data at times before t.

intvar

Character string specifying the name of the variable to be intervened on in each round of the simulation.

intvals

A list of length 2. The first entry is lower bound of the threshold, and the second entry is the upper bound.

time_name

Character string specifying the name of the time variable in pool and newdf.

t

Integer specifying the current time index.

Value

No value is returned. The data table newdf is modified in place.

Examples


## Estimating the effect of threshold interventions on the mean of a binary
## end of follow-up outcome

id <- 'id_num'
time_name <- 'time'
covnames <- c('cov1', 'cov2', 'treat')
outcome_name <- 'outcome'
histories <- c(lagged, cumavg)
histvars <- list(c('treat', 'cov1', 'cov2'), c('cov1', 'cov2'))
covtypes <- c('binary', 'zero-inflated normal', 'normal')
covparams <- list(covmodels = c(cov1 ~ lag1_treat + lag1_cov1 + lag1_cov2 + cov3 +
                                  time,
                                cov2 ~ lag1_treat + cov1 + lag1_cov1 + lag1_cov2 +
                                  cov3 + time,
                                treat ~ lag1_treat + cumavg_cov1 +
                                  cumavg_cov2 + cov3 + time))
ymodel <- outcome ~  treat + cov1 + cov2 + lag1_cov1 + lag1_cov2 + cov3
intervention1.treat <- list(static, rep(0, 7))
intervention2.treat <- list(threshold, 1, Inf)
int_descript <- c('Never treat', 'Threshold - lower bound 1')
nsimul <- 10000
ncores <- 2

gform_bin_eof <- gformula_binary_eof(obs_data = binary_eofdata, id = id,
                                     time_name = time_name,
                                     covnames = covnames,
                                     outcome_name = outcome_name,
                                     covtypes = covtypes,
                                     covparams = covparams,
                                     ymodel = ymodel,
                                     intervention1.treat = intervention1.treat,
                                     intervention2.treat = intervention2.treat,
                                     int_descript = int_descript,
                                     histories = histories, histvars = histvars,
                                     basecovs = c("cov3"), seed = 1234,
                                     parallel = TRUE, nsamples = 5,
                                     nsimul = nsimul, ncores = ncores)
gform_bin_eof



CausalInference/gfoRmula documentation built on Oct. 1, 2024, 8:36 p.m.