Skip to contents

Attaches two columns to the cohort:

Usage

add_iptw(data, ps_fit = NULL)

Arguments

data

A long cohort from simulate_hr_agent().

ps_fit

A propensity model from fit_propensity(). If NULL (default) one is fitted internally with the default formula.

Value

data with added ps and weight columns.

Details

  • ps – the fitted probability of being on the drug this interval, and

  • weight – the (unstabilised) IPT weight, 1 / ps for treated person-intervals and 1 / (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