SURVIVAL.COX OpenBI
A Cox model: hazard ratios and the proportional hazards test.
Group: Survival analysis. OpenBI’s own: DAX has no function of this name.
Syntax
SURVIVAL.COX ( <table>, <duration>, <event> [, <options>] [, <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). |
options | Text optional | Settings in one text, name=value with commas between: "ties=breslow" for Breslow's handling of tied times (Efron's when left out), "transform=rank" for the scale of the proportional hazards test (km, rank, identity or log; km when left out). |
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 a term. The columns: Variable and Reference; Coefficient, Hazard ratio, Std error, Z and P-value; Lower and Upper; the model's Observations, Events, Concordance, Likelihood ratio and LR p-value; the proportional hazards test's PH p-value with its PH chi-square and PH df, and the PH global p-value; and a Note.
Remarks
- Cox's proportional hazards model, as R's coxph fits it: how each covariate raises or lowers the rate of the event, whatever the shape of the curve. Covariates come in pairs: a name in quotes, then its expression.
- Hazard ratio is exp(Coefficient): 2 means twice the rate of the event at any time, 0.5 half of it, for one unit more of a number or for a factor's level against the reference. Lower and Upper are its 95 % interval; P-value is the Wald test of the coefficient.
- 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. - The model's own figures are repeated on every row: Observations and Events fitted, Concordance (Harrell's C: 0.5 is no better than chance, 1 orders every pair right) and the likelihood ratio test of all the terms.
- The PH columns test whether each covariate's effect holds over time (Grambsch and Therneau, as R's cox.zph; a factor's levels together). A small PH p-value means the hazard ratio is an average of an effect that changes: look at
SURVIVAL.COX.ZPH. - Note explains, in words, a fit that did not settle, a coefficient that runs off to infinity (a level without events), or an effect that changes over time; it is blank otherwise.
- A row is fitted when its duration, its event and every covariate (and the entry, when given) have a value; rows with a blank are left out.
- With an entry, each row is at risk only from its entry to the end of its duration: delayed entry, or a subject split into rows over time so a covariate can change (R's
Surv ( start, stop, event )). - Options and entry may each be left out. Empty text "" as the options means the defaults; a text without = is read as the first covariate's name.
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
Does the plan matter?
Plus customers leave at about a fifth of Basic's rate, but the interval is wide: ten customers say little.
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 ( Customers, [Months], [Left], "Plan", [Plan] ),
"Variable", [Variable],
"Reference", [Reference],
"Hazard ratio", [Hazard ratio],
"Lower", [Lower],
"Upper", [Upper],
"P-value", [P-value],
"Concordance", [Concordance]
)
| Variable | Reference | Hazard ratio | Lower | Upper | P-value | Concordance |
|---|---|---|---|---|---|---|
| Plan: Plus | Basic | 0.225756457481025 | 0.02316518719792 | 2.20011078084264 | 0.200128465691739 | 0.666666666666667 |
Plan and spend together
Each unit of spend lowers the rate by about 14 %; with spend in the model, the plan explains little more.
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 ( Customers, [Months], [Left], "Plan", [Plan], "Spend", [Spend] ),
"Variable", [Variable],
"Hazard ratio", [Hazard ratio],
"Coefficient", [Coefficient],
"Std error", [Std error],
"P-value", [P-value],
"Likelihood ratio", [Likelihood ratio],
"LR p-value", [LR p-value]
)
| Variable | Hazard ratio | Coefficient | Std error | P-value | Likelihood ratio | LR p-value |
|---|---|---|---|---|---|---|
| Plan: Plus | 0.738721455959784 | -0.302834349303015 | 1.2775539121094 | 0.812623955394793 | 8.54343480211948 | 0.0139577914317347 |
| Spend | 0.858942056380116 | -0.152053814010987 | 0.0902456336239632 | 0.0920101204957547 | 8.54343480211948 | 0.0139577914317347 |
The proportional hazards test on another scale
With the times' ranks instead of 1 − Kaplan-Meier, the test is less sure still that anything changes over time.
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 ( Customers, [Months], [Left], "transform=rank", "Plan", [Plan] ),
"Variable", [Variable],
"PH p-value", [PH p-value],
"PH chi-square", [PH chi-square],
"PH df", [PH df]
)
| Variable | PH p-value | PH chi-square | PH df |
|---|---|---|---|
| Plan: Plus | 0.692968573042893 | 0.155890493619604 | 1 |
Related functions
SURVIVAL.COX.PREDICT, SURVIVAL.COX.CURVE, SURVIVAL.COX.ZPH, SURVIVAL.COX.PENALIZED, SURVIVAL.TEST.