pymc-devs / pymc-devs/pymc-examples

[Proposal] New Notebook: Actuarial Survival Analysis (Left-Truncation & AFT Models)

Open
#861 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

proposal
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:

  1. Simulation-Based Calibration: Generating actuarial data with ~7.4% left-truncation and ~48% right-censoring.
  2. Numerically Stable Tensor Math: Implementing closed-form Weibull log-survival and log-hazard functions to avoid catastrophic cancellation.
  3. Log-Link AFT Architecture: Ensuring strict positivity for the scale parameter to prevent NUTS divergences.
  4. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.