OpenBI Docs Buy

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>] … )
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).
optionsText
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).
entryNumber
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.
nameText
repeatable
A covariate's name, in quotes: the result calls it so.
covariateExpression
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]
    )
VariableReferenceHazard ratioLowerUpperP-valueConcordance
Plan: PlusBasic0.2257564574810250.023165187197922.200110780842640.2001284656917390.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]
    )
VariableHazard ratioCoefficientStd errorP-valueLikelihood ratioLR p-value
Plan: Plus0.738721455959784-0.3028343493030151.27755391210940.8126239553947938.543434802119480.0139577914317347
Spend0.858942056380116-0.1520538140109870.09024563362396320.09201012049575478.543434802119480.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]
    )
VariablePH p-valuePH chi-squarePH df
Plan: Plus0.6929685730428930.1558904936196041

SURVIVAL.COX.PREDICT, SURVIVAL.COX.CURVE, SURVIVAL.COX.ZPH, SURVIVAL.COX.PENALIZED, SURVIVAL.TEST.

Last updated · OpenBI Studio 0.3.74