SURVIVAL.TEST OpenBI
The log-rank test between groups' survival curves.
Group: Survival analysis. OpenBI’s own: DAX has no function of this name.
Syntax
SURVIVAL.TEST ( <table>, <duration>, <event>, <group> )
| 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 evaluated for each row | The groups whose curves are compared, such as plans: two or more different values. |
Returns
Table. A row a group. The columns: Group, Observations and Events; Expected; and the test's Chi-square, Degrees of freedom and P-value, the same on every row.
Remarks
- The log-rank test, as R's survdiff: do the groups' survival curves differ by more than chance?
- Expected is how many events the group would have had if every group shared one curve. A group with more events than expected fares worse.
- Degrees of freedom is the number of groups less one. A small P-value (below 0.05, say) means the curves differ; a large one only that the data can't tell them apart.
- The test weighs every event alike, early or late.
- 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.
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
Basic against Plus
Basic has 3 events where 1.6 were expected, but with ten customers the difference could be chance.
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.TEST ( Customers, [Months], [Left], [Plan] ),
"Group", [Group],
"Observations", [Observations],
"Events", [Events],
"Expected", [Expected],
"P-value", [P-value],
"Chi-square", [Chi-square],
"Degrees of freedom", [Degrees of freedom]
)
| Group | Observations | Events | Expected | P-value | Chi-square | Degrees of freedom |
|---|---|---|---|---|---|---|
| Basic | 5 | 3 | 1.63690476190476 | 0.162291225436996 | 1.95274622975237 | 1 |
| Plus | 5 | 3 | 4.36309523809524 | 0.162291225436996 | 1.95274622975237 | 1 |
Three plans
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 },
{ "Pro", 6, 1 }, { "Pro", 10, 1 }, { "Pro", 13, 0 }
}
)
RETURN
SELECTCOLUMNS (
SURVIVAL.TEST ( Customers, [Months], [Left], [Plan] ),
"Group", [Group],
"Events", [Events],
"Expected", [Expected],
"P-value", [P-value],
"Degrees of freedom", [Degrees of freedom]
)
| Group | Events | Expected | P-value | Degrees of freedom |
|---|---|---|---|---|
| Basic | 3 | 1.42956487956488 | 0.287771059630034 | 2 |
| Plus | 3 | 4.20027195027195 | 0.287771059630034 | 2 |
| Pro | 2 | 2.37016317016317 | 0.287771059630034 | 2 |