This function estimates the density ratio of shifted versus unshifted exposures using a classification approach. It utilizes the sl3 package to train a Super Learner on the intervention indicator and then predicts the density ratios for both the training and validation datasets.

estimate_density_ratio(at, av, delta, var, covars, classifier)

Arguments

at

Data frame containing the training data.

av

Data frame containing the validation data.

delta

Numeric value specifying the shift to be applied to the exposure variable.

var

Character string specifying the name of the exposure variable to be shifted.

covars

Character vector specifying the names of the covariate columns in the data frames.

classifier

An sl3 learner object used for classification.

Value

A list containing two elements: Hn_at and Hn_av, which are data tables of density ratios for the training and validation datasets, respectively. Each data table has two columns: noshift and shift, representing the density ratios for unshifted and shifted exposures.

Examples

# Example usage:
training_data <- data.frame(A = rnorm(100), W1 = rbinom(100, 1, 0.5), W2 = rbinom(100, 1, 0.5))
validation_data <- data.frame(A = rnorm(50), W1 = rbinom(50, 1, 0.5), W2 = rbinom(50, 1, 0.5))
delta <- -0.5
exposure_variable <- "A"
covariates <- c("W1", "W2")
classifier <- sl3::Lrnr_glm$new()
result <- estimate_density_ratio(training_data, validation_data, delta, exposure_variable, covariates, classifier)
training_density_ratios <- result$Hn_at
validation_density_ratios <- result$Hn_av