Skip to content

Commit

Permalink
Add weight clipping and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescMartiEscofetQC committed Jul 18, 2024
1 parent 95cabbb commit 45554cb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/examples/example_survival.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"from lifelines import KaplanMeierFitter\n",
"\n",
"\n",
"def estimate_ipcw_km(outcome, censored):\n",
"def estimate_ipcw_km(outcome, censored, clip=0.95):\n",
" \"\"\"\n",
" Estimate Inverse Probability of Censoring Weights (IPCW) by nonparametric Kaplan-Meier method\n",
" (which is valid in case of noninformative censoring)\n",
Expand All @@ -164,8 +164,13 @@
" inverse_prob_censoring_weight = pd.Series(\n",
" index=outcome.index, data=inverse_prob_censoring_weight.values\n",
" )\n",
" # We only want to use complete observations, therefore we give a weight of 0 to censored observations\n",
" inverse_prob_censoring_weight[censored.astype(bool)] = 0\n",
"\n",
" # We clip the weights to a percentile to avoid exploding weights\n",
" clip_quantile = inverse_prob_censoring_weight.quantile(clip)\n",
" inverse_prob_censoring_weight = inverse_prob_censoring_weight.clip(0, clip_quantile)\n",
"\n",
" return inverse_prob_censoring_weight\n",
"\n",
"\n",
Expand Down

0 comments on commit 45554cb

Please sign in to comment.