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
). WhenTRUE
, usesmgcv::gam()
with spline smoothing. WhenFALSE
, usesstats::glm()
. Ignored formethod = "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.
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`