SURVIVAL.COX.CURVE OpenBI
Survival curves adjusted by a Cox model, for each value of one covariate.
Group: Survival analysis. OpenBI’s own: DAX has no function of this name.
Syntax
SURVIVAL.COX.CURVE ( <table>, <duration>, <event>, <by> [, <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). |
by | Text | The covariate whose values each get a curve, by its name in quotes; BLANK () for one curve only, the typical row's. |
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. The columns of SURVIVAL.CURVE: Group (unless by is blank) and Time; At risk, Events and Censored; Survival with its Std error, Lower and Upper; and Cumulative hazard.
Remarks
- The model's survival curves (R's survfit on a coxph fit): one for each level of a factor, for each value of a number with five values or fewer, else for its quartiles. Group holds that value.
- The other covariates are held at a typical row's: a number at its mean, a factor at its most common level.
- At risk, Events and Censored are those of all the rows fitted, the same for every curve; Survival, its interval and Cumulative hazard are the model's for that value.
- Unlike Kaplan-Meier curves split by group, the curves share one model: they never cross, and each uses all the rows.
- 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.
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
The model's curve for each plan
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.CURVE ( Customers, [Months], [Left], "Plan", "Plan", [Plan] ),
"Group", [Group],
"Time", [Time],
"Survival", [Survival],
"Lower", [Lower],
"Upper", [Upper]
)
| Group | Time | Survival | Lower | Upper |
|---|---|---|---|---|
| Basic | 0 | 1 | 1 | 1 |
| Basic | 2 | 0.84945140023655 | 0.612504719400158 | 1 |
| Basic | 3 | 0.84945140023655 | 0.612504719400158 | 1 |
| Basic | 4 | 0.666732267156233 | 0.361217005845757 | 1 |
| Basic | 5 | 0.516036290280446 | 0.222830253904061 | 1 |
| Basic | 7 | 0.365661821510572 | 0.112315085138305 | 1 |
| Basic | 8 | 0.365661821510572 | 0.112315085138305 | 1 |
| Basic | 9 | 0.365661821510572 | 0.112315085138305 | 1 |
| Basic | 11 | 0.0835288048277772 | 0.000557727593822548 | 1 |
| Basic | 12 | 0.00911950447688641 | 2.62788963952969e-07 | 1 |
| Basic | 15 | 0.00911950447688641 | 2.62788963952969e-07 | 1 |
| Plus | 0 | 1 | 1 | 1 |
| Plus | 2 | 0.963834720679708 | 0.872578677694032 | 1 |
| Plus | 3 | 0.963834720679708 | 0.872578677694032 | 1 |
| Plus | 4 | 0.912548400826655 | 0.743560123677325 | 1 |
| Plus | 5 | 0.861262840508434 | 0.630571389993784 | 1 |
| Plus | 7 | 0.796823992761668 | 0.510197924928063 | 1 |
| Plus | 8 | 0.796823992761668 | 0.510197924928063 | 1 |
| Plus | 9 | 0.796823992761668 | 0.510197924928063 | 1 |
| Plus | 11 | 0.570949339830157 | 0.258877028665039 | 1 |
| Plus | 12 | 0.346298279749678 | 0.0982927726044782 | 1 |
| Plus | 15 | 0.346298279749678 | 0.0982927726044782 | 1 |
By spend, at its quartiles
Spend has nine values, so the curves are for its quartiles: 30, 37.5 and 48.75. At a few times only.
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 (
FILTER (
SURVIVAL.COX.CURVE ( Customers, [Months], [Left], "Spend", "Spend", [Spend] ),
[Time] IN { 0, 5, 11 }
),
"Group", [Group],
"Time", [Time],
"Survival", [Survival]
)
| Group | Time | Survival |
|---|---|---|
| 30 | 0 | 1 |
| 30 | 5 | 0.578930364344334 |
| 30 | 11 | 0.137538826551757 |
| 37.5 | 0 | 1 |
| 37.5 | 5 | 0.848007610386557 |
| 37.5 | 11 | 0.549691174868414 |
| 48.75 | 0 | 1 |
| 48.75 | 5 | 0.97305761771041 |
| 48.75 | 11 | 0.905623213253024 |