negatr implements negative control methods for detecting and correcting unmeasured confounding in epidemiological studies. The package provides a comprehensive framework for:
- Bias Detection: Test for unmeasured confounding using negative control exposures (NCE) and negative control outcomes (NCO)
- Bias Correction: Apply difference-in-differences and calibration methods
- Assumption Validation: Check exclusion restrictions, U-comparability, positivity, and completeness
- DAG Integration: Specify and validate causal structures with dagitty
- Flexible Modeling: Support for GLM, GAM, survival models, and custom fitting functions
# Install from GitHub
# install.packages("remotes")
remotes::install_github("etverse/negatr")library(negatr)
# Load example data
data(nc_example_data)
# Specify negative control analysis
spec <- nc_specify(
data = nc_example_data,
exposure = "exposure",
outcome = "outcome",
nce = "nce_future", # Future exposure as NCE
nco = "nco_prior", # Prior outcome as NCO
confounders = c("age", "sex", "ses")
)
# Fit models
fit <- nc_fit(spec)
# Detect bias
bias_test <- nc_detect_bias(fit)
print(bias_test)
# Correct for bias
corrected <- nc_correct_bias(fit, method = "did")
print(corrected)
# Visualize
plot(fit, type = "effects")
summary(fit)- Specify Analysis: Define exposure, outcome, negative controls,
and confounders with
nc_specify() - Fit Models: Estimate associations with
nc_fit()using flexible model specifications - Detect Bias: Test negative control assumptions with
nc_detect_bias() - Correct Bias: Apply correction methods with
nc_correct_bias() - Validate: Check assumptions with
nc_validate_assumptions()andnc_dag()
Negative Control Exposures (NCE):
- Should NOT causally affect the outcome
- Should share unmeasured confounders with primary exposure
- Examples: future exposure levels, paternal exposures, spatially distant exposures
Negative Control Outcomes (NCO):
- Should NOT be causally affected by the exposure
- Should share unmeasured confounders with primary outcome
- Examples: pre-exposure outcomes, analogous outcomes from different mechanisms
- Difference-in-Differences (DiD): Uses NCO to estimate and subtract bias
- Calibration: Adjusts p-values and confidence intervals using NC test statistics
# GLM with binary outcome
spec <- nc_specify(data, exposure, outcome, nce, nco, confounders)
fit <- nc_fit(spec, family = binomial())
# GAM with smooth terms
library(mgcv)
fit_gam <- nc_fit(
spec,
model_function = mgcv::gam,
formula_primary = outcome ~ s(exposure) + s(age) + sex
)
# Survival analysis
library(survival)
fit_cox <- nc_fit(
spec,
model_function = survival::coxph
)# Create causal DAG
dag <- nc_dag(
exposure = "smoking",
outcome = "lung_cancer",
nce = "future_smoking",
nco = "prior_injury",
confounders = c("age", "ses"),
unmeasured = "genetic_susceptibility"
)
# Visualize
plot(dag)
# Check assumptions
nc_dag_check(dag)Negative control methods detect and correct unmeasured confounding by leveraging variables with known causal relationships:
- Exclusion Restriction: NCE doesn’t cause outcome; exposure doesn’t cause NCO
- U-Comparability: Negative controls share unmeasured confounders with primary variables
- Completeness: NCE and NCO are associated (for double NC designs)
If negative control associations are significant, this indicates either:
- Assumption violation (invalid negative control)
- Unmeasured confounding affecting the primary analysis
With valid negative controls, significant associations provide evidence of bias that can be quantified and corrected.
Lipsitch M, Tchetgen Tchetgen E, Cohen T (2010). “Negative controls: a tool for detecting confounding and bias in observational studies.” Epidemiology, 21(3), 383-388.
Shi X, Miao W, Tchetgen Tchetgen E (2020). “A selective review of negative control methods in epidemiology.” Current Epidemiology Reports, 7, 190-202.
Tchetgen Tchetgen EJ, et al. (2020). “An introduction to proximal causal learning.” arXiv preprint arXiv:2009.10982.
- Documentation:
?nc_specify,?nc_fit,?nc_detect_bias,?nc_correct_bias - Vignettes:
vignette("negatr-methodology"),vignette("negatr-workflow") - Issues: GitHub Issues
MIT License - see LICENSE file for details