Re-computes IPTW weights across a range of winsorisation thresholds and reports how the weight distribution and effective sample size (ESS) change as trimming increases. This helps identify a trimming threshold that adequately controls extreme weights without an unacceptable loss of effective sample size.
Arguments
- x
A
ps_weightobject (returned byps_weight()) or aps_matchobject or a plain data frame that contains a propensity score column and a binary treatment column.- trim_seq
Numeric vector of trimming values to evaluate. Each value is the lower tail quantile; weights outside the (
trim,1 - trim) range are winsorised.0means no trimming. Defaultseq(0, 0.10, by = 0.01).- estimand
One of
"ATE","ATT", or"ATC"– the causal estimand used to compute IPTW weights. Taken fromx$meta$estimandwhenxis aps_weightobject; defaults to"ATE"otherwise.- stabilise
Logical. Whether to stabilise weights. Taken from
x$meta$stabilisedwhen available; defaults toTRUE. As inps_weight(), stabilisation applies to the ATE only.- score_col
Name of the propensity score column. Taken from
x$meta$score_colwhenxis aps_dataobject. Default"prob_t". The score of aps_match()object built withscale = "logit"is a logit, and is back-transformed withstats::plogis()before use.- treatment_col
Name of the binary treatment column. Taken from
x$meta$treatment_colwhenxis aps_dataobject. Default"tavr".- treated_level
The value of
treatment_colthat is treated. Read from the metadata of aps_dataobject when it records one.NULL(default) requires a 0/1 or logical column and takes 1 orTRUE.
Value
An object of class c("sa_trim_sweep", "ps_data"):
$dataThe input data frame (
x$datafor aps_dataobject), unchanged.$metascore_col,treatment_col,treated_level,scale,estimand,stabilised(whether stabilisation was applied, soFALSEfor the ATT and ATC),trim_seq(sorted),n_totalandn_used, the patients with a non-missing treatment and score.$tables$sweepData frame with one row per trim value and columns
trim(the winsorisation threshold),ess_controlandess_treated(effective sample sizes),max_weight(maximum weight after trimming),sd_weight(standard deviation of the weights after trimming) andpct_trimmed(percentage of patients whose weight was winsorised).$modelsAn empty list.
Details
For a ps_data input, a supplied estimand, stabilise,
score_col, treatment_col or treated_level must agree with the
object's metadata; a conflict aborts. Arguments not supplied are read
from the metadata, then take their defaults.
Examples
dta <- sample_ps_data(n = 400, seed = 3)
w_obj <- ps_weight(dta, estimand = "ATE")
sweep <- sa_trim_sweep(w_obj)
head(sweep$tables$sweep)
#> trim ess_control ess_treated max_weight sd_weight pct_trimmed
#> 1 0.00 303.1 305.0 4.4440 0.5578 0
#> 2 0.01 312.6 312.7 3.1193 0.5209 2
#> 3 0.02 316.2 315.5 2.8898 0.5068 4
#> 4 0.03 320.7 318.9 2.7022 0.4895 6
#> 5 0.04 328.8 325.9 2.4054 0.4558 8
#> 6 0.05 339.1 334.9 2.0931 0.4126 10
# Directly from a data frame
sweep2 <- sa_trim_sweep(dta, score_col = "prob_t", treatment_col = "tavr",
estimand = "ATE")