Skip to contents

This function calibrates propensity scores to improve their accuracy using either Platt scaling (logistic regression) or isotonic regression. It preserves the attributes of causal weight objects when applicable.

Usage

ps_calibrate(
  ps,
  treat,
  method = c("logistic", "isoreg"),
  smooth = TRUE,
  .treated = NULL,
  .untreated = NULL,
  estimand = NULL
)

Arguments

ps

Numeric vector of propensity scores between 0 and 1

treat

A binary vector of treatment assignments

method

Calibration method:

"logistic"

(Default) Logistic calibration (also known as Platt scaling). Assumes a sigmoid relationship between observed and true probabilities. Best when: propensity scores follow a logistic pattern but are systematically biased. Provides smooth, parametric calibration. Faster and more stable with small samples.

"isoreg"

Isotonic regression calibration. Uses a non-parametric monotonic transformation. Best when: the relationship between observed and true probabilities is non-linear or when you want to preserve the rank order without assuming a specific functional form. More flexible but requires larger samples for stable estimates.

smooth

Logical. For method = "logistic", whether to use a smoothed logistic spline model (smooth = TRUE, default) or simple logistic regression (smooth = FALSE). When TRUE, uses mgcv::gam() with spline smoothing. When FALSE, uses stats::glm(). Ignored for method = "isoreg".

.treated

The value representing the treatment group. If not provided, ps_calibrate() will attempt to automatically determine the treatment coding.

.untreated

The value representing the control group. If not provided, ps_calibrate() will attempt to automatically determine the control coding.

estimand

Character indicating the estimand type.

Value

A calibrated propensity score object (psw)

Examples

# Generate example data
ps <- runif(100)
treat <- rbinom(100, 1, ps)

# Logistic calibration with smoothing (default)
calibrated_smooth <- ps_calibrate(ps, treat)
#>  Setting treatment to `1`

# Logistic calibration without smoothing (simple logistic regression)
calibrated_simple <- ps_calibrate(ps, treat, smooth = FALSE)
#>  Setting treatment to `1`

# Isotonic regression
calibrated_iso <- ps_calibrate(ps, treat, method = "isoreg")
#>  Setting treatment to `1`