SURVIVAL.CURVE OpenBI
Kaplan-Meier survival curves, with censoring and delayed entry.
Group: Survival analysis. OpenBI’s own: DAX has no function of this name.
Syntax
SURVIVAL.CURVE ( <table>, <duration>, <event> [, <group>] [, <entry>] )
| Parameter | Type | Description |
|---|---|---|
table | Table | The rows to follow, one a subject such as a customer, a policy or a machine: a table of the model or a table expression, as the filters leave it. |
duration | Number evaluated for each row | How long each row was followed: until its event, or until we stopped seeing it. In any unit (days, months, years), the same for every row. |
event | Number evaluated for each row | 1 or TRUE when the row's duration ended in the event (the customer left); 0 or FALSE when it did not, so all we know is that it lasted at least that long (censored). |
group | Expression optional, evaluated for each row | Splits the rows into groups, such as plans or regions, each with its own result. Left out, all the rows are one group. |
entry | Number optional, evaluated for each row | When each row came under observation, on the same clock as duration (delayed entry): a row counts as at risk only after it. Left out, every row is followed from 0. |
Returns
Table. A row a time at which something happened, per group. The columns: Group (when grouped) and Time; At risk, Events and Censored; Survival with its Std error, Lower and Upper; and Cumulative hazard.
Remarks
- Survival is the Kaplan-Meier estimate: the share still without the event just after that time. A first row at time 0, survival 1, starts each curve (not with an entry).
- At risk counts the rows still followed at that time, Events those that had the event then, Censored those last seen then.
- Std error is Greenwood's. Lower and Upper are a 95 % interval on the log scale, as R's survfit draws it by default; where survival reaches 0 they are blank.
- Cumulative hazard is the Nelson-Aalen estimate: the events at each time over those at risk, added up.
- Rows with a blank duration or a blank event are left out. An event other than 0, 1, TRUE or FALSE is an error.
- The groups come in sorted order; rows whose group is blank are left out.
- With an entry but no group, leave the group empty:
SURVIVAL.CURVE ( T, [Duration], [Event], , [Entry] ). An entry at or after its row's duration is an error.
Compared with DAX
An OpenBI function: DAX has none like it, so a measure or query that uses it works in OpenBI only, not in Power BI or Analysis Services.
Examples
Ten customers
Six left; four were still customers when we last saw them. Half are gone by month 11.
EVALUATE
VAR Customers =
DATATABLE (
"Plan", STRING, "Months", INTEGER, "Left", INTEGER,
{
{ "Basic", 2, 1 }, { "Basic", 3, 0 }, { "Basic", 5, 1 }, { "Basic", 7, 1 }, { "Basic", 8, 0 },
{ "Plus", 4, 1 }, { "Plus", 9, 0 }, { "Plus", 11, 1 }, { "Plus", 12, 1 }, { "Plus", 15, 0 }
}
)
RETURN
SELECTCOLUMNS (
SURVIVAL.CURVE ( Customers, [Months], [Left] ),
"Time", [Time],
"At risk", [At risk],
"Events", [Events],
"Censored", [Censored],
"Survival", [Survival],
"Lower", [Lower],
"Upper", [Upper]
)
| Time | At risk | Events | Censored | Survival | Lower | Upper |
|---|---|---|---|---|---|---|
| 0 | 10 | 0 | 0 | 1 | 1 | 1 |
| 2 | 10 | 1 | 0 | 0.9 | 0.732011642743993 | 1 |
| 3 | 9 | 0 | 1 | 0.9 | 0.732011642743993 | 1 |
| 4 | 8 | 1 | 0 | 0.7875 | 0.564125231513673 | 1 |
| 5 | 7 | 1 | 0 | 0.675 | 0.430282529790523 | 1 |
| 7 | 6 | 1 | 0 | 0.5625 | 0.316475454363994 | 0.999781327862746 |
| 8 | 5 | 0 | 1 | 0.5625 | 0.316475454363994 | 0.999781327862746 |
| 9 | 4 | 0 | 1 | 0.5625 | 0.316475454363994 | 0.999781327862746 |
| 11 | 3 | 1 | 0 | 0.375 | 0.139982124041514 | 1 |
| 12 | 2 | 1 | 0 | 0.1875 | 0.0342353883331371 | 1 |
| 15 | 1 | 0 | 1 | 0.1875 | 0.0342353883331371 | 1 |
A curve for each plan
EVALUATE
VAR Customers =
DATATABLE (
"Plan", STRING, "Months", INTEGER, "Left", INTEGER,
{
{ "Basic", 2, 1 }, { "Basic", 3, 0 }, { "Basic", 5, 1 }, { "Basic", 7, 1 }, { "Basic", 8, 0 },
{ "Plus", 4, 1 }, { "Plus", 9, 0 }, { "Plus", 11, 1 }, { "Plus", 12, 1 }, { "Plus", 15, 0 }
}
)
RETURN
SELECTCOLUMNS (
SURVIVAL.CURVE ( Customers, [Months], [Left], [Plan] ),
"Group", [Group],
"Time", [Time],
"At risk", [At risk],
"Events", [Events],
"Survival", [Survival],
"Cumulative hazard", [Cumulative hazard]
)
| Group | Time | At risk | Events | Survival | Cumulative hazard |
|---|---|---|---|---|---|
| Basic | 0 | 5 | 0 | 1 | 0 |
| Basic | 2 | 5 | 1 | 0.8 | 0.2 |
| Basic | 3 | 4 | 0 | 0.8 | 0.2 |
| Basic | 5 | 3 | 1 | 0.533333333333333 | 0.533333333333333 |
| Basic | 7 | 2 | 1 | 0.266666666666667 | 1.03333333333333 |
| Basic | 8 | 1 | 0 | 0.266666666666667 | 1.03333333333333 |
| Plus | 0 | 5 | 0 | 1 | 0 |
| Plus | 4 | 5 | 1 | 0.8 | 0.2 |
| Plus | 9 | 4 | 0 | 0.8 | 0.2 |
| Plus | 11 | 3 | 1 | 0.533333333333333 | 0.533333333333333 |
| Plus | 12 | 2 | 1 | 0.266666666666667 | 1.03333333333333 |
| Plus | 15 | 1 | 0 | 0.266666666666667 | 1.03333333333333 |
Customers who joined the panel late
A customer who joined in month 3 was not at risk before: fewer are at risk early on.
EVALUATE
VAR Customers =
DATATABLE (
"Id", STRING, "Plan", STRING, "Joined", INTEGER, "Months", INTEGER, "Left", INTEGER, "Spend", INTEGER,
{
{ "c01", "Basic", 0, 2, 1, 20 }, { "c02", "Basic", 1, 3, 0, 35 }, { "c03", "Basic", 0, 5, 1, 25 },
{ "c04", "Basic", 3, 7, 1, 30 }, { "c05", "Basic", 0, 8, 0, 50 }, { "c06", "Plus", 2, 4, 1, 40 },
{ "c07", "Plus", 0, 9, 0, 45 }, { "c08", "Plus", 4, 11, 1, 30 }, { "c09", "Plus", 0, 12, 1, 55 },
{ "c10", "Plus", 6, 15, 0, 60 }
}
)
RETURN
SELECTCOLUMNS (
SURVIVAL.CURVE ( Customers, [Months], [Left], , [Joined] ),
"Time", [Time],
"At risk", [At risk],
"Events", [Events],
"Survival", [Survival],
"Std error", [Std error]
)
| Time | At risk | Events | Survival | Std error |
|---|---|---|---|---|
| 2 | 6 | 1 | 0.833333333333333 | 0.152145154862546 |
| 3 | 6 | 0 | 0.833333333333333 | 0.152145154862546 |
| 4 | 6 | 1 | 0.694444444444445 | 0.17930478454664 |
| 5 | 6 | 1 | 0.578703703703704 | 0.183002179407892 |
| 7 | 6 | 1 | 0.482253086419753 | 0.176093929239058 |
| 8 | 5 | 0 | 0.482253086419753 | 0.176093929239058 |
| 9 | 4 | 0 | 0.482253086419753 | 0.176093929239058 |
| 11 | 3 | 1 | 0.321502057613169 | 0.176093929239058 |
| 12 | 2 | 1 | 0.160751028806584 | 0.14378009114582 |
| 15 | 1 | 0 | 0.160751028806584 | 0.14378009114582 |
Related functions
SURVIVAL.SUMMARY, SURVIVAL.AT, SURVIVAL.MEDIAN, SURVIVAL.TEST, SURVIVAL.COX.CURVE.