Stochastic intervention (user-supplied sampling function)

Description

Creates a stochastic intervention where the counterfactual treatment for each individual is drawn from a user-supplied distribution that may depend on the individual’s covariates. Each call to sampler should return an independent draw.

Only supported under estimator = “gcomp” (point and longitudinal). The g-formula evaluates \(E[Y^g]\) via Monte Carlo integration: for each of n_mc draws, the sampler assigns counterfactual treatments, the outcome model predicts, and the predictions are averaged across draws.

Usage

stochastic(sampler, n_mc = 100L)

Arguments

sampler A function with signature function(data, treatment) that returns a vector of treatment values of length nrow(data). data is the full counterfactual data.table (same as dynamic()); treatment is the observed treatment vector. Each call must return an independent random draw from the stochastic policy.
n_mc Positive integer. Number of Monte Carlo draws for the g-formula integration. Default 100. Larger values reduce MC noise at the cost of computation time. For sandwich variance, n_mc should be large enough that MC noise is negligible relative to the estimation error (100–500 is typical).

Value

A causatr_intervention object.

References

Diaz I, van der Laan MJ (2012). Population intervention causal effects based on stochastic interventions. Biometrics 68:541–549.

See Also

static(), shift(), scale_by(), threshold(), dynamic(), ipsi(), contrast()

Examples

library("causatr")

# Binary treatment: covariate-dependent randomisation
stochastic(\(data, trt) rbinom(nrow(data), 1, plogis(0.5 + 0.3 * data$L)))

# Continuous treatment: additive random shift
stochastic(\(data, trt) trt + rnorm(length(trt), mean = 0.5, sd = 0.25))