Member-only story
Survival Analysis for Data Scientists
Part 2 of 6: Hazards, the Nelson-Aalen Estimator and the Log-Rank Test. How to read churn month by month, why a hazard ratio can drift when no customer changes, and how to read a retention A/B test before most customers have left. Python code provided.
Diogo Ribeiro is a mathematician, researcher and lecturer at the Faculdade de Media Artes e Design, Universidade Técnica do Porto.
Part 1 estimated one retention curve from a customer table in which half the customers had not churned yet. Most decisions involve two curves. A product team changes the onboarding flow and wants to know whether new customers stay longer; a pricing team offers a discount and wants to know whether it buys loyalty or only delays cancellations. The evidence comes from an experiment, and the experiment has to be read long before every customer in it has left.
This part adds three ideas. The first is the hazard, the churn rate among customers who are still there, with two ways to estimate it: the Nelson-Aalen estimator of the cumulative hazard and the churn rate per customer-month. The second is the log-rank test, which compares two groups using every customer for as long as they were observed. The third is a warning about the most common summary of such a comparison, the hazard ratio, which can change over time even when nothing about any customer does. The…



![[1993] Before the tap: the strange old world when bank cards made an impression](https://miro.medium.com/v2/resize:fit:1358/format:webp/1*GYMcJdV1NyIUi6gPizqttg.jpeg)




