Omniscope Custom Blocks › Analytics/Survival

Survival Analysis

Estimates survival (or retention) curves from time-to-event data with censoring, by the Kaplan-Meier or Fleming-Harrington method, overall or per group, with 95% confidence limits and the median time per group.

Analytics › Statistics R

Open the demo in Omniscope Download demo.ioz Sample data: subscriptions.csv Source on GitHub

Omniscope custom block · Analytics · Statistics

How long do customers stay, machines run or patients go without an event, counting fairly those who are still going? Kaplan-Meier curves per group, with confidence limits and the median time.

R · survival · comes with R

The problem it solves

A subscription business sells monthly and annual plans and wants to know how long subscribers stay on each. Many are still subscribed, some only joined a few months ago: averaging the lifetimes of those who left, or counting the share who cancelled, understates how long people stay.

Survival analysis counts each subscriber for as long as they have been followed, and only counts a cancellation where one happened. The block gives one curve per plan, the share still subscribed after each month, and the median time to cancelling.

How it works

What goes in

Subscriptions

180 invented subscriptions on two plans, followed for up to 24 months.

Customer Plan Months Cancelled
S-0001 Monthly 12 1
S-0002 Annual 7 0
S-0003 Annual 22 0
S-0004 Monthly 1 1

180 rows in the sample file: 100 monthly and 80 annual; one annual subscription (S-0041) has no Months and is left out.

The options

Option Demo setting What it does
Time Months How long each subscriber was followed.
Event Cancelled 1 = cancelled, 0 = still subscribed (censored).
Group Plan One curve per plan.
Method Kaplan-Meier The standard product-limit estimate.

What comes out

Curve (selected rows)

Plan Time At risk Events Censored Survival Lower 95% Upper 95%
Annual 0 79 0 0 1.000 1.000 1.000
Annual 11 50 3 1 0.940 0.876 1.000
Annual 12 46 16 1 0.613 0.491 0.766
Annual 24 3 1 2 0.409 0.178 0.938
Monthly 0 100 0 0 1.000 1.000 1.000
Monthly 1 100 7 0 0.930 0.881 0.981
Monthly 6 55 4 1 0.574 0.483 0.683
Monthly 12 18 3 0 0.254 0.172 0.374

44 rows in all: one per plan and month with a cancellation or a subscriber's last month, plus month 0. Draw Survival against Time as a step line, coloured by Plan.

Annual subscribers hardly leave until the 12-month renewal, where 16 of the 46 still at risk cancel; monthly subscribers leave steadily from the first month.

Summary

Plan Records Events Censored Median time Median lower 95% Median upper 95%
Annual 79 20 59 24 12
Monthly 100 70 30 8 6 10

The annual median rests on the 3 subscribers followed for the full 24 months, so its upper limit is empty: too few remain to bound it.

Where it pays off

Subscriptions and SaaS: Retention by plan

Compare how long customers stay on each plan, channel or sign-up cohort, counting current customers fairly.

Maintenance: Time to failure

Estimate how long components or machines run before failing, per model or site, with units still running as censored.

HR: Staff retention

Time from hiring to leaving, per department or role, with current staff as censored.

Health and research: Time to event

The classic use: time to relapse, recovery or death per treatment group, from follow-up times and status codes.

Use cases describe typical scenarios and are illustrative; the sample data is invented.

Why do this in Omniscope

How it fits into an Omniscope workflow

Subscriptions (Database) → Field Organiser (Months = DATEDIFF of start and end or today) → Survival Analysis → Report (line chart of Survival by Time, per Plan)

The Curve output feeds a line chart directly; the Summary output feeds a table or KPI view of the median time per group.

Try it

  1. Open the demo project (demo.iox on the demo server, or import demo.ioz from this folder): 180 invented subscriptions on two plans.
  2. The question: how long do subscribers stay on each plan?
  3. Open Survival Analysis: Time Months, Event Cancelled, Group Plan, Method Kaplan-Meier. Run it.
  4. Look at Curve: annual subscribers drop from 0.94 to 0.61 at month 12; monthly ones fall steadily to 0.25 by month 12.
  5. Look at Summary: median 8 months on the monthly plan, 24 on the annual plan.

Running in Omniscope

Omniscope workflow
Omniscope workflow

The demo project's workflow: the sample data, the block, and a Validate data check on its output.

Language and libraries

R. It uses the survival package (LGPL 2 or later), one of R's recommended packages that come with most R installations; install it with install.packages("survival") if it is missing.

Tested

The block is covered by automated tests that run its script against a stand-in for Omniscope's R API: the sample data per plan and overall, values against the previous version of the block, both methods against their formulas, event codings, an empty Group option, missing values and a group with one value, empty input, wrong field types and missing choices, and 100,000 subjects in 50 groups.

Reference

Fields it reads

NameTypeWhat it does
TimeFieldHow long each subject was followed: until the event, or until it was last seen without one (a number of days, weeks, months...).
EventFieldWhether the event happened at the end of Time: 1 = event, 0 = censored (still going). 2 = event, 1 = censored, and true / false, are accepted too.
GroupFieldOptional: a field whose values each get their own curve (a plan, region or cohort). Leave empty for one curve over all records.

Options

NameTypeWhat it does
MethodChoiceHow the curve is estimated. Kaplan-Meier is the standard choice; Fleming-Harrington gives slightly higher values where few subjects remain.

Outputs

OutputWhat it holds
CurveOne record per group and time at which an event or censoring happened, plus time 0: at risk, events, censored, survival and its 95% confidence limits.
SummaryOne record per group: records, events, censored, and the median time with its 95% confidence limits (empty when the curve does not fall to 0.5).