Attaches two columns to the cohort:
Arguments
- data
A long cohort from
simulate_hr_agent().- ps_fit
A propensity model from
fit_propensity(). IfNULL(default) one is fitted internally with the default formula.
Details
ps– the fitted probability of being on the drug this interval, andweight– the (unstabilised) IPT weight,1 / psfor treated person-intervals and1 / (1 - ps)for untreated ones.
The weights build a pseudo-population in which treatment no longer depends on the confounders, so a weighted Cox model estimates the marginal effect without conditioning on the mediator.
Examples
dat <- simulate_hr_agent(n = 2000)
dat_w <- add_iptw(dat)
summary(dat_w$weight)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 1.027 1.342 1.644 1.997 2.222 20.765