pymc-devs / pymc-devs/pymc-examples
Interval indexing in Bayesian Survival Analysis
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 398
- Forks
- 325
- Avg merge
- 9d 15m
- Merged PRs (30d)
- 1
Description
Notebook title: Bayesian Survival Analysis
Notebook url: https://www.pymc.io/projects/examples/en/latest/survival_analysis/survival_analysis.html
Issue description
The baseline hazard is computed over $K$ intervals indexed by $k$, thanks to $\lambda(t) = \lambda_k$ for $t \in [\tau_{k-1},\tau_k]$. This value is saved under the variable base_hazard and is of size $K$: $[\lambda_1, ...., \lambda_K]$. Yet there is another variable interval_bounds that stores $[\tau_0, ..., \tau_K ]$, thus of size $K+1$.
The cumulative baseline hazard, which is $\int_{\tau_0}^t \lambda(t)$ is estimated as (interval_length * hazard).cumsum(axis=-1), thus still a variable of size $K$. At a certain point, the cumulative hazard is plotted depending on the interval_bounds variables. The two objects do not have the same size, and the choice in the notebook was to use interval_bounds[:-1]. So this means that at time $\tau_0$, the variables is equal $(\tau_1-\tau_0)\lambda_1$, yet at time the cumulative baseline hazard equal $\int_{\tau_0}^{\tau_0} \lambda(t) = 0$.
Expected output
Thus I think, interval_bounds[:-1] in plots should be replaced by interval_bounds[1:]
Proposed solution
Let me know if you agree. Then, I can make a PR and check that this issue "only" occurs in plots.
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
Open the Bayesian Survival Analysis notebook from the linked URL and inspect the base_hazard, interval_bounds, and cumulative baseline hazard calculations. Check every plot using interval_bounds[:-1], verify the time alignment against the cumulative hazard, and update the plots so their x-values match the intended intervals.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, python
- Domain
- data, machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100