Estimate the conditional exposure response function using nearest neighbor Gaussian process
Source:R/estimate_cerf_nngp.R
estimate_cerf_nngp.Rd
Estimates the conditional exposure response function (cerf) using the nearest neighbor (nn) Gaussian Process (gp). The function tune the best match (the lowest covariate balance) for the provided set of hyperparameters.
Usage
estimate_cerf_nngp(
data,
w,
gps_m,
params,
outcome_col,
treatment_col,
covariates_col,
kernel_fn = function(x) exp(-x^2),
nthread = 1
)
Arguments
- data
A data.frame of observation data.
- w
A vector of exposure level to compute CERF (please also see the notes).
- gps_m
An S3 gps object including: gps: A data.frame of GPS vectors. - Column 1: GPS - Column 2: Prediction of exposure for covariate of each data sample (e_gps_pred). - Column 3: Standard deviation of e_gps (e_gps_std) used_params: - dnorm_log: TRUE or FLASE
- params
A list of parameters that is required to run the process. These parameters include:
alpha: A scaling factor for the GPS value.
beta: A scaling factor for the exposure value.
g_sigma: A scaling factor for kernel function (gamma/sigma).
tune_app: A tuning approach. Available approaches:
all: try all combinations of hyperparameters.
n_neighbor: Number of nearest neighbors on one side.
block_size: Number of samples included in a computation block. Mainly used to balance the speed and memory requirement. Larger
block_size
is faster, but requires more memory. alpha, beta, and g_sigma can be a vector of parameters.
- outcome_col
An outcome column name in
data
.- treatment_col
A treatment column name in
data
.- covariates_col
Covariates columns name in
data
.- kernel_fn
A kernel function. A default value is a Gaussian Kernel.
- nthread
An integer value that represents the number of threads to be used by internal packages.
Value
A cerf_nngp object that includes the following values:
w, the vector of exposure levels.
pst_mean, the computed mean for the w vector.
pst_sd, the computed credible interval for the w vector.
Note
Please note that w
is a vector representing a grid of exposure levels at
which the CERF is to be estimated. This grid can include both observed and
hypothetical values of the exposure variable. The purpose of defining this
grid is to provide a structured set of points across the exposure spectrum
for estimating the CERF. This approach is essential in nonparametric models
like Gaussian Processes (GPs), where the CERF is evaluated at specific points
to understand the relationship between the exposure and outcome variables
across a continuum. It facilitates a comprehensive analysis by allowing
practitioners to examine the effect of varying exposure levels, including
those not directly observed in the dataset.
Examples
# \donttest{
set.seed(19)
data <- generate_synthetic_data(sample_size = 120, gps_spec = 3)
# Estimate GPS function
gps_m <- estimate_gps(cov_mt = data[,-(1:2)],
w_all = data$treat,
sl_lib = c("SL.xgboost"),
dnorm_log = FALSE)
# exposure values
w.all <- seq(0,20,2)
cerf_nngp_obj <- estimate_cerf_nngp(data,
w.all,
gps_m,
params = list(alpha = c(0.1),
beta = 0.2,
g_sigma = 1,
tune_app = "all",
n_neighbor = 20,
block_size = 1e4),
outcome_col = "Y",
treatment_col = "treat",
covariates_col = paste0("cf", seq(1,6)),
nthread = 1)
# }