| Title: | Perform Causal Sensitivity Analyses Using Various Statistical Methods |
|---|---|
| Description: | While data from randomized experiments remain the gold standard for causal inference, estimation of causal estimands from observational data is possible through various confounding adjustment methods. However, the challenge of unmeasured confounding remains a concern in causal inference, where failure to account for unmeasured confounders can lead to biased estimates of causal estimands. Sensitivity analysis within the framework of causal inference can help adjust for possible unmeasured confounding. In `causens`, three main methods are implemented: adjustment via sensitivity functions (Brumback, HernĂ¡n, Haneuse, and Robins (2004) <doi:10.1002/sim.1657> and Li, Shen, Wu, and Li (2011) <doi:10.1093/aje/kwr096>), Bayesian parametric modelling and Monte Carlo approaches (McCandless, Lawrence C and Gustafson, Paul (2017) <doi:10.1002/sim.7298>). |
| Authors: | Larry Dong [aut, cre] (ORCID: <https://orcid.org/0000-0001-7775-7798>), Yushu Zou [aut] (ORCID: <https://orcid.org/0009-0004-1133-4724>), Kuan Liu [aut] (ORCID: <https://orcid.org/0000-0002-5017-1276>) |
| Maintainer: | Larry Dong <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.3 |
| Built: | 2026-06-01 11:16:47 UTC |
| Source: | https://github.com/kuan-liu-lab/causens |
This function runs a Bayesian sensitivity analysis for causal inference using JAGS or Stan as a backend. For now, only JAGS is supported.
bayesian_causens( trt_model, outcome_model, U_model, data, beta_uy = ~dunif(-2, 2), alpha_uz = ~dunif(-2, 2), backend = "jags", output_trace = FALSE, ... )bayesian_causens( trt_model, outcome_model, U_model, data, beta_uy = ~dunif(-2, 2), alpha_uz = ~dunif(-2, 2), backend = "jags", output_trace = FALSE, ... )
trt_model |
The treatment model object as a formula. |
outcome_model |
The outcome model object as a formula. |
U_model |
The unmeasured confounder model object as a formula. |
data |
A data frame containing the exposure, outcome, and confounder variables. |
beta_uy |
Prior distribution for the effect of the missing confounder U on the outcome Y. |
alpha_uz |
Prior distribution for the effect of the missing confounder U on the treatment assignment mechanism Z. |
backend |
The backend to use for the sensitivity analysis. Currently only "jags" is supported. |
output_trace |
Whether to output the full trace of the MCMC sampler. |
... |
Additional arguments to be passed to the backend. |
A list of posterior samples for the causal effect of the exposure variable on the outcome, as well as the confounder-adjusted causal effect.
This function performs a Monte Carlo sensitivity analysis for causal effects.
causens_monte_carlo(outcome, exposure, confounders, data, ...)causens_monte_carlo(outcome, exposure, confounders, data, ...)
outcome |
The name of the outcome variable in the data frame. |
exposure |
The name of the exposure variable in the data frame. |
confounders |
The name of the confounders in the data frame. |
data |
A data frame containing the exposure, outcome, and confounder variables. |
... |
Additional arguments to be passed to the function. |
The estimated causal effect.
This function provides an estimate of the Average Treatment Effect (ATE) using Bayesian modelling.
causens_sf( trt_model, outcome, data, bootstrap = FALSE, B = 1000, seed = 123, ... )causens_sf( trt_model, outcome, data, bootstrap = FALSE, B = 1000, seed = 123, ... )
trt_model |
A model formula specifying the treatment model. |
outcome |
The name of the outcome variable. |
data |
A data frame containing the exposure, outcome, and confounder variables. |
bootstrap |
A logical indicating whether to perform bootstrap estimation of the 95% confidence interval. |
B |
If the bootstrap argument is TRUE, the number of bootstrap samples to generate. |
seed |
An integer to set the random seed for reproducibility. |
... |
Additional arguments to be passed to the sensitivity function. |
A point estimate of the corrected ATE.
Creates a JAGS model available as a string, or .txt file, where priors are initialized to be uninformative by default.
create_jags_model(binary_outcome, beta_uy, alpha_uz)create_jags_model(binary_outcome, beta_uy, alpha_uz)
binary_outcome |
Boolean indicating whether the outcome is binary. |
beta_uy |
Prior distribution for the effect of the missing confounder U on the outcome Y. |
alpha_uz |
Prior distribution for the effect of the missing confounder U on the treatment assignment mechanism Z. No inputs are given to this function (for now) since data-related information is provided in jags.model() during model initialization. |
Generate data with a binary unmeasured confounder and binary outcome
gData_U_binary_Y_binary( ymodel = "linear", N = 500, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, seed = 123 )gData_U_binary_Y_binary( ymodel = "linear", N = 500, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, seed = 123 )
ymodel |
A string indicating the functional form of the outcome model. |
N |
The number of observations to be generated. |
alpha_uz |
Unmeasured confounder coefficient in the propensity score model. |
beta_uy |
Unmeasured confounder coefficient in the outcome model. |
treatment_effects |
The treatment effect. |
seed |
The seed for the random number generator. |
A data frame with the simulated dataset with U binary, Y binary.
Generate data with a binary unmeasured confounder and continuous outcome
gData_U_binary_Y_cont( ymodel = "linear", N = 500, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, seed = 123 )gData_U_binary_Y_cont( ymodel = "linear", N = 500, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, seed = 123 )
ymodel |
A string indicating the functional form of the outcome model. |
N |
The number of observations to be generated. |
alpha_uz |
Unmeasured confounder coefficient in the propensity score model. |
beta_uy |
Unmeasured confounder coefficient in the outcome model. |
treatment_effects |
The treatment effect. |
seed |
The seed for the random number generator. |
A data frame with the simulated dataset with U binary, Y continuous.
fulldata <- gData_U_binary_Y_cont( ymodel = "linear", N = 500, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, seed = 123 ) table(fulldata$Z)fulldata <- gData_U_binary_Y_cont( ymodel = "linear", N = 500, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, seed = 123 ) table(fulldata$Z)
Generate data with a continuous unmeasured confounder and a binary outcome
gData_U_cont_Y_binary( ymodel = "linear", N = 500, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, seed = 123 )gData_U_cont_Y_binary( ymodel = "linear", N = 500, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, seed = 123 )
ymodel |
A string indicating the functional form of the outcome model. |
N |
The number of observations to be generated. |
alpha_uz |
Unmeasured confounder coefficient in the propensity score model. |
beta_uy |
Unmeasured confounder coefficient in the outcome model. |
treatment_effects |
The treatment effect. |
seed |
The seed for the random number generator. |
A data frame with the simulated dataset with U continuous, Y binary.
Generate data with a continuous unmeasured confounder and continuous outcome
gData_U_cont_Y_cont( ymodel = "linear", N = 500, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, seed = 123 )gData_U_cont_Y_cont( ymodel = "linear", N = 500, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, seed = 123 )
ymodel |
A string indicating the functional form of the outcome model. |
N |
The number of observations to be generated. |
alpha_uz |
Unmeasured confounder coefficient in the propensity score model. |
beta_uy |
Unmeasured confounder coefficient in the outcome model. |
treatment_effects |
The treatment effect. |
seed |
The seed for the random number generator. |
A data frame with the simulated dataset with U continuous, Y continuous.
This function plots 1) the ATE as a function of the sensitivity function value when it is constant and 2) its associate 95 interval obtained via bootstrapping, if desired. The latter process can be take a few seconds to minutes.
plot_causens( trt_model, data, outcome, c1_upper = 0.5, c1_lower = 0, r = 1, by = 0.01 )plot_causens( trt_model, data, outcome, c1_upper = 0.5, c1_lower = 0, r = 1, by = 0.01 )
trt_model |
The treatment model object as a formula or fitted glm. |
data |
A data frame containing the variables of interest. |
outcome |
The name of the outcome variable. |
c1_upper |
The upper bound for the sensitivity function value. |
c1_lower |
The lower bound for the sensitivity function value. |
r |
The ratio between c1 and c0. |
by |
The increment for the sensitivity function value. |
A plot of the ATE as a function of c1 values.
This helper function takes in a model in its 'formula' format and returns a list comprising of various information, including the fitted model as an R object.
process_model_formula(model, data)process_model_formula(model, data)
model |
The model object as a formula or fitted glm. |
data |
A data frame used for fitting the model. |
A list containing the fitted model, model formula, response variable name, and confounder names.
This function calculates the sensitivity of a treatment effect estimate to unmeasured confounding, as described in Rosenbaum (2002). The sensitivity is defined as the maximum strength of association between the unmeasured confounder and the treatment assignment that would be needed to explain away the observed treatment effect estimate. This function assumes that the treatment assignment is binary and that the outcome is continuous.
sf(z, e, form = "constant", c1 = 0, c0 = 0, s1 = 0, s0 = 0)sf(z, e, form = "constant", c1 = 0, c0 = 0, s1 = 0, s0 = 0)
z |
Treatment assignment (binary: 0 or 1) |
e |
Propensity score value (numeric) |
form |
Form of the sensitivity function (character: "constant" or "linear") |
c1 |
Value of the sensitivity function when z = 1 (numeric) |
c0 |
Value of the sensitivity function when z = 0 (numeric) |
s1 |
Slope of the sensitivity function when z = 1 (numeric) |
s0 |
Slope of the sensitivity function when z = 0 (numeric) |
Sensitivity of treatment effect estimate to unmeasured confounding (numeric)
sf(z, e, form)
Generate data with unmeasured confounder
simulate_data( ymodel = "linear", N = 500, u_type = "binary", y_type = "continuous", seed = 123, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, informative_u = FALSE )simulate_data( ymodel = "linear", N = 500, u_type = "binary", y_type = "continuous", seed = 123, alpha_uz = 0.2, beta_uy = 0.5, treatment_effects = 1, informative_u = FALSE )
ymodel |
A string indicating the functional form of the outcome model. |
N |
The number of observations to be generated. |
u_type |
A string indicating the type of the unmeasured confounder: "binary" or "continuous". |
y_type |
A string indicating the type of the outcome: "binary" or "continuous". |
seed |
The seed for the random number generator. |
alpha_uz |
Unmeasured confounder coefficient in the propensity score model. |
beta_uy |
Unmeasured confounder coefficient in the outcome model. |
treatment_effects |
The treatment effect. |
informative_u |
A boolean indicating whether the unmeasured confounder is driven by covariates. |
A data frame with the simulated dataset.
Summarize the results of a causal sensitivity analysis via Bayesian modelling of an unmeasured confounder.
## S3 method for class 'bayesian_causens' summary(object, ...)## S3 method for class 'bayesian_causens' summary(object, ...)
object |
An object of class |
... |
Additional arguments to be passed to |
A summary of results from a Bayesian causal sensitivity analysis.
Summarize the results of a causal sensitivity analysis via sensitivity function.
## S3 method for class 'causens_sf' summary(object, ...)## S3 method for class 'causens_sf' summary(object, ...)
object |
An object of class |
... |
Additional arguments to be passed to |
A summary of the results of the causal sensitivity analysis.
Summarize the results of a causal sensitivity analysis via the Monte Carlo method.
## S3 method for class 'monte_carlo_causens' summary(object, ...)## S3 method for class 'monte_carlo_causens' summary(object, ...)
object |
An object of class |
... |
Additional arguments to be passed to |
A summary of results from a Monte Carlo causal sensitivity analysis.