SURVIVAL.COX.PREDICT OpenBI
A Cox model's prediction for each row: risk, survival to a horizon, median, and survival from now.
Group: Survival analysis. OpenBI’s own: DAX has no function of this name.
Syntax
SURVIVAL.COX.PREDICT ( <table>, <duration>, <event>, <id>, <horizon> [, <entry>], <name>, <covariate> [, <name>, <covariate>] … )
| 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). |
id | Expression evaluated for each row | What names each row in the result, such as the customer's number. |
horizon | Number | The time ahead each row's survival is worked out to: 0 or more. |
entry | Number optional, evaluated for each row | When each row came under observation: it is at risk from just after its entry to the end of its duration. An expression, not a text, given right before the first name. |
name | Text repeatable | A covariate's name, in quotes: the result calls it so. |
covariate | Expression repeatable, evaluated for each row | The covariate's value on each row: a number, or a text for a factor whose levels are each compared with the first. |
Returns
Table. A row for each row of the table. The columns: Key (the id); Linear predictor and Risk; Survival with its Lower and Upper; Median; and Survival from now.
Remarks
- The model is fitted as
SURVIVAL.COXfits it (Efron's ties), on the rows with a duration, an event and every covariate. Then every row of the table is scored, also those without a duration or an event: new customers, say. - Linear predictor and Risk compare the row with a reference row, as R's predict does: numbers at their mean, a factor at its first level (and a column of only 0 and 1 at 0). Risk is exp(Linear predictor): 2 is twice the reference's rate.
- Survival is the row's chance of lasting to the horizon, from time 0, with a 95 % interval; Median is its median time on the model's curve, blank when the curve never gets to a half.
- Survival from now is for a row still without the event (event 0): its chance of lasting the horizon more, given it has lasted its duration. It is blank for a row that has had the event. This is the figure to rank current customers by.
- A row with a blank covariate, or a level the fit never saw, gets blanks.
- A covariate of text is a factor: it gets a term for each level but the first in sorted order, the reference, and is named like
Plan: Plus.
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
Each customer, six months ahead
Basic customers have the reference risk 1, Plus customers about a fifth of it. Of those still here, c05 is the likeliest to go within six months.
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.COX.PREDICT ( Customers, [Months], [Left], [Id], 6, "Plan", [Plan] ),
"Key", [Key],
"Risk", [Risk],
"Survival", [Survival],
"Median", [Median],
"Survival from now", [Survival from now]
)
| Key | Risk | Survival | Median | Survival from now |
|---|---|---|---|---|
| c01 | 1 | 0.516036290280446 | 7 | (blank) |
| c02 | 1 | 0.516036290280446 | 7 | 0.430468207373306 |
| c03 | 1 | 0.516036290280446 | 7 | (blank) |
| c04 | 1 | 0.516036290280446 | 7 | (blank) |
| c05 | 1 | 0.516036290280446 | 7 | 0.0249397228269913 |
| c06 | 0.225756457481025 | 0.861262840508434 | 12 | (blank) |
| c07 | 0.225756457481025 | 0.861262840508434 | 12 | 0.434598208507078 |
| c08 | 0.225756457481025 | 0.861262840508434 | 12 | (blank) |
| c09 | 0.225756457481025 | 0.861262840508434 | 12 | (blank) |
| c10 | 0.225756457481025 | 0.861262840508434 | 12 | 1 |