pymc-devs / pymc-devs/pymc-examples
[Proposal] New Notebook: Actuarial Survival Analysis (Left-Truncation & AFT Models)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 398
- Forks
- 325
- Avg merge
- 9d 15m
- Merged PRs (30d)
- 1
Description
Notebook proposal
Why should this notebook be added to pymc-examples?
In Life/Health Insurance pricing, dealing with highly censored and truncated data is the daily reality. While PyMC's pm.Censored elegantly handles right-censoring, users often struggle with Left-Truncation (Immortal Time Bias)—situations where an individual must survive to a certain entry age just to be observed in the dataset.
Left-truncation cannot be handled out-of-the-box by pm.Censored, as it requires conditioning the likelihood on survival up to the entry time (i.e., subtracting $\log S(t_{entry})$). Actuaries and researchers currently have to manually construct complex, numerically sensitive tensor graphs to solve this.
This notebook demonstrates a rigorous, industry-standard solution. It covers:
- Simulation-Based Calibration: Generating actuarial data with ~7.4% left-truncation and ~48% right-censoring.
- Numerically Stable Tensor Math: Implementing closed-form Weibull log-survival and log-hazard functions to avoid catastrophic cancellation.
- Log-Link AFT Architecture: Ensuring strict positivity for the scale parameter to prevent NUTS divergences.
- Custom Likelihood: Injecting the left-truncated tensor graph into the model via
pm.Potential.
Suggested categories:
- Level: Advanced
- Diataxis type: How-to Guide
Related notebooks
This notebook will build upon and complement the existing survival analysis materials, specifically the Weibull Accelerated Failure Time (AFT) example.
I noticed that @ricardoV94 opened issue #747 to refactor the basic Weibull AFT example by replacing pm.Potential with the new pm.Censored API. While pm.Censored is the perfect modern solution for right-censoring, this new proposed notebook serves as the vital "next step" for users: What do you do when you have Left-Truncated data that pm.Censored cannot handle? Therefore, it should be a new notebook rather than an extension, serving as an advanced guide for users who need to drop back down to custom tensor math and pm.Potential for truncated survival data.
References
- Proof-of-Concept Notebook: I have already developed, commented, and tested the full notebook here:
[https://github.com/ZHANGSHUO22/PyMC-Actuarial-Survival-GSoC26] (Note: R-hat is 1.0, showing perfect parameter recovery even with a weakly informative prior) - Discourse Discussion: I have also started a broader discussion on the PyMC Discourse forum regarding my ultimate GSoC 2026 vision (a declarative Formula API for survival models based on this math):
[(https://discourse.pymc.io/t/gsoc-2026-actuarial-survival-models-tackling-left-truncation-declarative-api-vision/17669)]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing Weibull AFT example and the linked proof-of-concept notebook. Add a new advanced how-to notebook covering left-truncation, right-censoring, stable Weibull functions, a log-link AFT model, and a custom pm.Potential likelihood, with the proposed simulation and recovery results demonstrated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, python
- Domain
- documentation, machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100