An online Kaplan–Meier curve and survival analysis: retention, time to purchase and subscription length, counting people who have not had the event yet. The log-rank test, medians, RMST and a step-by-step solution.
Your numbers stay in the browser and are never sent anywhere
The event is a user leaving; time is days since sign-up. Times separated by commas; 12+ means the event has not happened yet. Or two columns from Excel: time and 1/0.
8 observations · events 5 · censored 3
8 observations · events 7 · censored 1
Test
The difference is borderline.
Median time to leaving: “New onboarding” 7 days, “Old onboarding” 15 days; log-rank p = 0.055.
What to do next: Collect more observations, or wait for the censored ones to reach the event.
Share without the event · S(t)
Old onboardingNew onboardingcensoreddashed 50% line: median
Median · Old onboarding
15 days
CI 5…∞
Median · New onboarding
7 days
CI 3…18
No event by 10 days
75% · 33%
Old onboarding · New onboarding
Mean up to τ = 30 (RMST)
17.7 · 9.5
difference −8.2 days
Log-rank
χ² = 3.670
p = 0.055 · df 1
Observations · events
8/5 · 8/7
censored: 3 · 1
Life table
Time
At risk
Events
S(t)
95% CI
5
8
1
0.875
0.387…0.981
8
7
1
0.750
0.315…0.931
12
6
1
0.625
0.229…0.861
15
4
1
0.469
0.120…0.763
22
2
1
0.234
0.013…0.616
Time
At risk
Events
S(t)
95% CI
3
8
1
0.875
0.387…0.981
4
7
1
0.750
0.315…0.931
6
6
1
0.625
0.229…0.861
7
5
1
0.500
0.152…0.775
10
3
1
0.333
0.056…0.658
14
2
1
0.167
0.009…0.508
18
1
1
0.000
—
Log-rank step by step
At each event time we work out how many events group “Old onboarding” would have if the curves matched, then compare that with what actually happened.
t
n A
n B
d A
d B
E A
V
3
8
8
0
1
0.500
0.250
4
8
7
0
1
0.533
0.249
5
8
6
1
0
0.571
0.245
6
7
6
0
1
0.538
0.249
7
7
5
0
1
0.583
0.243
8
7
4
1
0
0.636
0.231
10
6
3
0
1
0.667
0.222
12
6
2
1
0
0.750
0.188
14
4
2
0
1
0.667
0.222
15
4
1
1
0
0.800
0.160
18
3
1
0
1
0.750
0.188
22
2
0
1
0
1.000
0.000
Σ
5
7
7.996
2.446
χ² = (O − E)² / V = (5 − 7.996)² / 2.446 = 3.670
p = P(χ²₁ ≥ 3.670) = 0.055
02
About
Censoring is not missing data
A user who has not left yet is still data: they lasted at least that many days.
The median instead of the mean
The mean time cannot be calculated while some people have not had the event. The median and S(t) can.
Log-rank compares whole curves
It looks at every event time, not at a single point.
03
Check in Python / R
Check in Python / R
from lifelines.statistics import multivariate_logrank_test
time = [5, 8, 12, 12, 15, 20, 22, 30, 3, 4, 6, 7, 9, 10, 14, 18]
event = [1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1]
group = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]
r = multivariate_logrank_test(time, group, event)
r.test_statistic, r.p_value
# 3.67, 0.0554
# When S is exactly 0.5: R takes the midpoint to the next event (8.5), lifelines the next time (10), this page 7
The median here is the first time where S(t) ≤ 0.5. When S is exactly 0.5, other software differs: R takes the midpoint to the next event (8.5), lifelines takes the next time (10), and this page shows 7.
It is a step chart of the share of people who have not had the event yet. Each step is an event time: the share falls by the fraction of people still at risk who reached the event. Censored people create no step but reduce the number at risk, so the curve neither inflates nor understates retention.
The event had not happened by the end of observation: the user has not left, the subscription has not been cancelled. All you know is that the true time exceeds the recorded one. Enter it with a plus sign, for example 12+. Do not drop it: you would lose the people who stayed longest and pull the curve down.
At each event time the log-rank test compares the observed number of events with the number expected if the curves matched. The differences add up to a chi-square statistic. The step-by-step mode shows the whole table. If the curves cross, log-rank loses sensitivity, so check Wilcoxon–Breslow and RMST as well.
Censored people would have to be dropped or counted as events, and both distort the result: the first loses the longest observations, the second understates their time. Instead of a plain mean, use the median or the mean up to a horizon (RMST): the area under the curve up to a chosen day fairly counts everyone.
It is the time by which half of the group has had the event, where the curve first falls to 50%. If the curve never gets that low, the median is not reached. When the value is exactly 0.5, software differs: this page takes the first such time, while R and lifelines give later values.
It is the value of the S(t) curve on that day: enter it in the “Retention on day” field and the calculator shows the share for each group. Unlike simple division, the estimate accounts for people observed for less than that time. So day-30 retention can include users who arrived a week ago.