Open JUNGYO opened 4 years ago
I currently don't have the weighted-KM supported within zepid (but it looks like I should move up on my list). You can do it using the underlying weight estimation and inputting it into lifelines' KaplanMeierFitter
.
This all assumes that treatment A
is assigned as baseline (and it not a time-varying treatment). The outcome indicator is Y
with confounder L
and time of event T
.
For the zepid side:
from zepid.causal import IPTW
ipw = IPTW(data, exposure="A", outcome="Y")
ipw.treatment_model("L + L_sq") # estimating IPTW
data['iptw'] = ipw.iptw # extracting IPTW
On the lifelines side:
from lifelines import KaplanMeierFitter
kmf = KaplanMeierFitter(label="ip_weighted_km")
kmf.fit(data['T'], data['Y'], weights=data['iptw'])
For confidence intervals you would need to use a bootstrapping procedure. I haven't thought about how a IPW-log-rank test would work, so I will let others weigh in
Combined with Zepid package, I want to plot IPTW adjusted KM curve and calculate adjusted log-rank test. Does anyone have examples of this?