run_sensemakr: Sensitivity Analysis to Unobserved Confounding (sensemakr)

View source: R/sensemakr.R

run_sensemakrR Documentation

Sensitivity Analysis to Unobserved Confounding (sensemakr)

Description

Performs the Cinelli & Hazlett style sensitivity analysis using sensemakr for two linear models:

  • I ~ trans_FC + t_norm + PopDensity + War

  • C ~ trans_FC + t_norm + PopDensity + War

treating trans_FC as the exposure of interest and using PopDensity and War as benchmark covariates.

Usage

run_sensemakr(DT, dir_csv = NULL)

Arguments

DT

A data.frame or data.table containing at least the columns I, C, trans_FC, t_norm, PopDensity, and War.

dir_csv

Character scalar or NULL; directory where the sensitivity summaries ("sensemakr_I_FC.csv", "sensemakr_C_FC.csv") are written. If NULL (default), nothing is written to disk.

Details

This function requires the sensemakr package (listed under Suggests); an informative error is raised at call time if it is not installed. For each outcome (I and C), an OLS model is estimated and passed to sensemakr::sensemakr() with:

  • treatment = "trans_FC"

  • benchmark_covariates = c("PopDensity", "War")

The resulting sensemakr objects are summarized via summary(), converted to data frames, and written to CSV files:

  • "sensemakr_I_FC.csv" for outcome I.

  • "sensemakr_C_FC.csv" for outcome C.

These files are written only when dir_csv is supplied.

Value

A list with components:

  • I: the sensemakr object for the model with outcome I.

  • C: the sensemakr object for the model with outcome C.

Examples


# This example runs only when 'sensemakr' is installed.
if (requireNamespace("sensemakr", quietly = TRUE)) {
  DT <- data.frame(
    I = rpois(30, lambda = 5),
    C = rpois(30, lambda = 3),
    trans_FC = sample(0:1, 30, replace = TRUE),
    t_norm = rnorm(30),
    PopDensity = rnorm(30),
    War = sample(0:1, 30, replace = TRUE)
  )

  res_sense <- run_sensemakr(DT)
  if (!is.null(res_sense$I)) {
    print(summary(res_sense$I))
  }
}



bivarhr documentation built on July 7, 2026, 1:06 a.m.