OpenBI Docs Buy

SURVIVAL.COX.PATH OpenBI

A penalized Cox model's coefficients along the penalty's path.

Group: Survival analysis. OpenBI’s own: DAX has no function of this name.

Syntax

SURVIVAL.COX.PATH ( <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: alpha (1 when left out), nlambda (100) and ratio.
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 lambda and term, the largest lambda first. The columns: Lambda, Log lambda, Variable, Coefficient and Deviance ratio.

Remarks

  • The fit is the elastic net for Cox's model, as R's glmnet computes it (Efron's handling of ties): alpha=1 is the lasso, which can drop terms altogether; alpha=0 is ridge, which only shrinks them.
  • The terms are put on a common scale before the penalty, as glmnet does, and the coefficients come back on the covariates' own scale.
  • The path runs over nlambda values of lambda (100 by default, from 5 to 500), from the smallest that keeps every term at 0 down to ratio times it (0.0001, or 0.01 when there are fewer rows than terms).
  • Plot Coefficient against Log lambda, a line a Variable: the lasso's picture of which terms come in first as the penalty eases.
  • There is no cross-validation here; to choose a lambda, use SURVIVAL.COX.CV.

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

Five steps of the lasso

At the largest lambda every coefficient is 0; at the smallest they are nearly the plain Cox fit's.

EVALUATE
VAR Customers =
    DATATABLE (
        "Plan", STRING, "Months", INTEGER, "Left", INTEGER, "Spend", INTEGER, "Tickets", INTEGER,
        {
            { "Basic", 3, 1, 20, 4 }, { "Basic", 5, 1, 25, 3 }, { "Basic", 6, 0, 40, 1 }, { "Basic", 8, 1, 30, 5 },
            { "Plus", 9, 1, 35, 2 }, { "Basic", 10, 0, 45, 0 }, { "Basic", 12, 1, 28, 3 }, { "Plus", 14, 0, 60, 1 },
            { "Plus", 15, 1, 38, 4 }, { "Basic", 16, 0, 50, 1 }, { "Plus", 18, 1, 42, 2 }, { "Plus", 20, 0, 55, 0 },
            { "Basic", 22, 1, 33, 2 }, { "Plus", 24, 0, 65, 1 }, { "Plus", 25, 1, 48, 3 }, { "Basic", 27, 0, 36, 0 },
            { "Plus", 30, 1, 52, 1 }, { "Plus", 32, 0, 70, 0 }, { "Basic", 34, 0, 44, 2 }, { "Plus", 36, 0, 58, 1 },
            { "Basic", 4, 1, 22, 2 }, { "Plus", 7, 1, 30, 3 }, { "Basic", 13, 1, 26, 1 }, { "Plus", 28, 0, 62, 2 }
        }
    )
RETURN
    SURVIVAL.COX.PATH ( Customers, [Months], [Left], "nlambda=5", "Plan", [Plan], "Spend", [Spend], "Tickets", [Tickets] )
LambdaLog lambdaVariableCoefficientDeviance ratio
0.587607236285896-0.531696519772035Plan: Plus00
0.587607236285896-0.531696519772035Spend00
0.587607236285896-0.531696519772035Tickets00
0.0587607236285896-2.83428161276608Plan: Plus1.442602853450840.571507499768426
0.0587607236285896-2.83428161276608Spend-0.219852826897780.571507499768426
0.0587607236285896-2.83428161276608Tickets0.4131323457411050.571507499768426
0.00587607236285896-5.13686670576013Plan: Plus3.991968051153040.677222441997696
0.00587607236285896-5.13686670576013Spend-0.5156796727105950.677222441997696
0.00587607236285896-5.13686670576013Tickets0.7466272786314620.677222441997696
0.000587607236285896-7.43945179875417Plan: Plus4.676455056960840.680812505120616
0.000587607236285896-7.43945179875417Spend-0.6001643836455420.680812505120616
0.000587607236285896-7.43945179875417Tickets0.8513887314805170.680812505120616
5.87607236285896e-05-9.74203689174822Plan: Plus4.762749288760330.680860017238365
5.87607236285896e-05-9.74203689174822Spend-0.6108126639184990.680860017238365
5.87607236285896e-05-9.74203689174822Tickets0.8645454441123660.680860017238365

The elastic net

With alpha=0.5, half lasso and half ridge.

EVALUATE
VAR Customers =
    DATATABLE (
        "Plan", STRING, "Months", INTEGER, "Left", INTEGER, "Spend", INTEGER, "Tickets", INTEGER,
        {
            { "Basic", 3, 1, 20, 4 }, { "Basic", 5, 1, 25, 3 }, { "Basic", 6, 0, 40, 1 }, { "Basic", 8, 1, 30, 5 },
            { "Plus", 9, 1, 35, 2 }, { "Basic", 10, 0, 45, 0 }, { "Basic", 12, 1, 28, 3 }, { "Plus", 14, 0, 60, 1 },
            { "Plus", 15, 1, 38, 4 }, { "Basic", 16, 0, 50, 1 }, { "Plus", 18, 1, 42, 2 }, { "Plus", 20, 0, 55, 0 },
            { "Basic", 22, 1, 33, 2 }, { "Plus", 24, 0, 65, 1 }, { "Plus", 25, 1, 48, 3 }, { "Basic", 27, 0, 36, 0 },
            { "Plus", 30, 1, 52, 1 }, { "Plus", 32, 0, 70, 0 }, { "Basic", 34, 0, 44, 2 }, { "Plus", 36, 0, 58, 1 },
            { "Basic", 4, 1, 22, 2 }, { "Plus", 7, 1, 30, 3 }, { "Basic", 13, 1, 26, 1 }, { "Plus", 28, 0, 62, 2 }
        }
    )
RETURN
    SURVIVAL.COX.PATH ( Customers, [Months], [Left], "alpha=0.5, nlambda=5", "Plan", [Plan], "Spend", [Spend], "Tickets", [Tickets] )
LambdaLog lambdaVariableCoefficientDeviance ratio
1.175214472571790.16145066078791Plan: Plus00
1.175214472571790.16145066078791Spend00
1.175214472571790.16145066078791Tickets00
0.117521447257179-2.14113443220614Plan: Plus0.3458162462677270.438162185739789
0.117521447257179-2.14113443220614Spend-0.1063504757805430.438162185739789
0.117521447257179-2.14113443220614Tickets0.3970536185045190.438162185739789
0.0117521447257179-4.44371952520018Plan: Plus2.530070807419340.63943350935419
0.0117521447257179-4.44371952520018Spend-0.3342528647273610.63943350935419
0.0117521447257179-4.44371952520018Tickets0.565825393681340.63943350935419
0.00117521447257179-6.74630461819423Plan: Plus4.19672647893890.678943242694114
0.00117521447257179-6.74630461819423Spend-0.5401523397610710.678943242694114
0.00117521447257179-6.74630461819423Tickets0.7844763466348920.678943242694114
0.000117521447257179-9.04888971118827Plan: Plus4.698869012301350.680832179609879
0.000117521447257179-9.04888971118827Spend-0.6028437245023540.680832179609879
0.000117521447257179-9.04888971118827Tickets0.8555749877886560.680832179609879

SURVIVAL.COX.CV, SURVIVAL.COX.PENALIZED, SURVIVAL.COX.

Last updated · OpenBI Studio 0.3.74