indiv_stoch_shift_est_Q.Rd
Compute the outcome regression for the observed data, taking into account the shift imposed by the intervention. This function returns the outcome regression for the observed data (at A) and under the counterfactual shift (at A + delta).
indiv_stoch_shift_est_Q(
exposure,
delta,
mu_learner,
covars,
av,
at,
lower_bound = lower_bound,
upper_bound = upper_bound,
outcome_type = "continuous"
)
A character vector representing the exposures to be shifted.
A numeric value indicating the magnitude of the shift to be computed for the exposure 'A'. This is passed to the internal 'shift_additive' function and is currently limited to additive shifts.
An object containing a set of instantiated learners from the 'sl3' package, to be used in fitting an ensemble model.
A character vector of covariates to adjust for.
A dataframe containing the validation data specific to the fold.
A dataframe containing the training data specific to the fold.
A numeric value representing the lower bound for the shifted exposure (optional).
A numeric value representing the upper bound for the shifted exposure (optional).
Variable type of the outcome.
A data.table with two columns, containing estimates of the outcome mechanism at the natural value of the exposure Q(A, W) and an upshift of the exposure Q(A + delta, W).
if (FALSE) {
# Load required libraries
library(InterXshift)
library(sl3)
# Create example data
set.seed(123)
n <- 100
W <- rnorm(n)
A <- rnorm(n, mean = W)
Y <- rnorm(n, mean = A + W)
data <- data.frame(W = W, A = A, Y = Y)
# Split the data into training and validation sets
train_idx <- sample(seq_len(n), size = floor(0.8 * n), replace = FALSE)
at <- data[train_idx, ]
av <- data[-train_idx, ]
# Define learners from the sl3 package
mu_learner <- Lrnr_sl("Lrnr_glm_fast")
covars <- c("W")
# Run the indiv_stoch_shift_est_Q function
results <- indiv_stoch_shift_est_Q(
exposure = "A",
delta = 1,
mu_learner = mu_learner,
covars = covars,
av = av,
at = at
)
}