OpenBI Docs Buy

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>] )
ParameterTypeDescription
tableTableThe 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.
durationNumber
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.
eventNumber
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).
groupExpression
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.
entryNumber
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]
    )
TimeAt riskEventsCensoredSurvivalLowerUpper
01000111
210100.90.7320116427439931
39010.90.7320116427439931
48100.78750.5641252315136731
57100.6750.4302825297905231
76100.56250.3164754543639940.999781327862746
85010.56250.3164754543639940.999781327862746
94010.56250.3164754543639940.999781327862746
113100.3750.1399821240415141
122100.18750.03423538833313711
151010.18750.03423538833313711

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]
    )
GroupTimeAt riskEventsSurvivalCumulative hazard
Basic05010
Basic2510.80.2
Basic3400.80.2
Basic5310.5333333333333330.533333333333333
Basic7210.2666666666666671.03333333333333
Basic8100.2666666666666671.03333333333333
Plus05010
Plus4510.80.2
Plus9400.80.2
Plus11310.5333333333333330.533333333333333
Plus12210.2666666666666671.03333333333333
Plus15100.2666666666666671.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]
    )
TimeAt riskEventsSurvivalStd error
2610.8333333333333330.152145154862546
3600.8333333333333330.152145154862546
4610.6944444444444450.17930478454664
5610.5787037037037040.183002179407892
7610.4822530864197530.176093929239058
8500.4822530864197530.176093929239058
9400.4822530864197530.176093929239058
11310.3215020576131690.176093929239058
12210.1607510288065840.14378009114582
15100.1607510288065840.14378009114582

SURVIVAL.SUMMARY, SURVIVAL.AT, SURVIVAL.MEDIAN, SURVIVAL.TEST, SURVIVAL.COX.CURVE.

Last updated · OpenBI Studio 0.3.74