SURVIVAL.COX.ZPH.SMOOTH OpenBI
The smoothed effect over time and its band, as R's plot.cox.zph draws it.
Group: Survival analysis. OpenBI’s own: DAX has no function of this name.
Syntax
SURVIVAL.COX.ZPH.SMOOTH ( <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: those of SURVIVAL.COX.ZPH, and df (the smooth's degrees of freedom, 2 to 10, 4 when left out) and points (how many points it is drawn at, 2 to 1,000, 40 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 point and term. The columns: Variable; Transformed time and Time; Beta(t), its Std error, Lower and Upper; Coefficient; PH p-value; and Transform.
Remarks
- The line R's plot.cox.zph draws through the points of
SURVIVAL.COX.ZPH: a natural spline fitted to Beta(t) against the transformed time, at points spread evenly over the events' transformed times. - Lower and Upper are two standard errors either side. A band that a flat line at Coefficient fits inside is an effect that holds over time.
- Time is the transformed time turned back into the duration's own unit, for the axis labels.
- 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 plan's effect, smoothed
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.ZPH.SMOOTH ( Customers, [Months], [Left], "points=5", "Plan", [Plan] ),
"Variable", [Variable],
"Time", [Time],
"Beta(t)", [Beta(t)],
"Lower", [Lower],
"Upper", [Upper]
)
| Variable | Time | Beta(t) | Lower | Upper |
|---|---|---|---|---|
| Plan | 2 | -1.04082645488219 | -6.44598697414092 | 4.36433406437653 |
| Plan | 4.5 | -0.125421945481238 | -4.56182777797589 | 4.31098388701341 |
| Plan | 6.77777777777778 | -2.33247068783199 | -5.92789046534241 | 1.26294908967844 |
| Plan | 11.1666666666667 | -3.37055102213472 | -7.87651768741787 | 1.13541564314843 |
| Plan | 12 | -1.0296794117063 | -6.6831870157908 | 4.62382819237819 |
An effect that fades
Among 24 customers, spend protects early on, and less later: its PH p-value is below 0.05.
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
SELECTCOLUMNS (
SURVIVAL.COX.ZPH.SMOOTH ( Customers, [Months], [Left], "points=4", "Spend", [Spend], "Tickets", [Tickets] ),
"Variable", [Variable],
"Transformed time", [Transformed time],
"Beta(t)", [Beta(t)],
"Std error", [Std error],
"PH p-value", [PH p-value]
)
| Variable | Transformed time | Beta(t) | Std error | PH p-value |
|---|---|---|---|---|
| Spend | 0 | -0.451206212518723 | 0.178176011943117 | 0.0198057592095955 |
| Spend | 0.194638694638695 | -0.199042323884425 | 0.116989345721709 | 0.0198057592095955 |
| Spend | 0.389277389277389 | -0.237615766970601 | 0.124621533860735 | 0.0198057592095955 |
| Spend | 0.583916083916084 | 0.190180111680242 | 0.197038119895661 | 0.0198057592095955 |
| Tickets | 0 | 0.714418239158115 | 0.753837482696728 | 0.375903924630139 |
| Tickets | 0.194638694638695 | 0.474472351788181 | 0.494965359923677 | 0.375903924630139 |
| Tickets | 0.389277389277389 | 1.14114766912285 | 0.527256067474299 | 0.375903924630139 |
| Tickets | 0.583916083916084 | 0.0395505983766092 | 0.833640391192845 | 0.375903924630139 |