SURVIVAL.HAZARD OpenBI
The hazard rate over time, smoothed, with its band.
Group: Survival analysis. OpenBI’s own: DAX has no function of this name.
Syntax
SURVIVAL.HAZARD ( <table>, <duration>, <event> [, <group>] [, <bandwidth>] )
| 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). |
group | Expression optional, evaluated for each row | Splits the rows into groups, such as plans or regions, each with its own result. Left out, all the rows are one group. |
bandwidth | Number optional | How far each event's weight spreads in time, above 0; larger is smoother. Left out, Silverman's rule of thumb on the times of the events. |
Returns
Table. 101 rows a group, at even steps from 0 to the longest duration. The columns: Group (when grouped), Time, Hazard, Lower, Upper and Bandwidth.
Remarks
- The hazard is the rate of the event among the rows still at risk: events per row per unit of time. A hazard of 0.05 a month is about one in twenty of those left, each month.
- It is the Nelson-Aalen estimate smoothed with the Epanechnikov kernel (Ramlau-Hansen's estimator), corrected near 0 and near the longest duration, where the kernel would reach outside the data.
- Lower and Upper are a 95 % band on the log scale; blank where the hazard is 0.
- Without a bandwidth, at least two events are needed. Every group uses the same bandwidth and the same times.
- Rows with a blank duration or a blank event are left out. An event other than 0, 1, TRUE or FALSE is an error.
- The groups come in sorted order; rows whose group is 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 rate of leaving, month by month
At whole months only. The default bandwidth here is about 2.5 months.
EVALUATE
VAR Customers =
DATATABLE (
"Plan", STRING, "Months", INTEGER, "Left", INTEGER,
{
{ "Basic", 2, 1 }, { "Basic", 3, 0 }, { "Basic", 5, 1 }, { "Basic", 7, 1 }, { "Basic", 8, 0 },
{ "Plus", 4, 1 }, { "Plus", 9, 0 }, { "Plus", 11, 1 }, { "Plus", 12, 1 }, { "Plus", 15, 0 }
}
)
RETURN
FILTER (
SURVIVAL.HAZARD ( Customers, [Months], [Left] ),
ROUND ( [Time], 4 ) = ROUND ( [Time], 0 )
)
| Time | Hazard | Lower | Upper | Bandwidth |
|---|---|---|---|---|
| 0 | 0.0215416527132661 | 0.0030344324697333 | 0.152925730345796 | 2.49736604361386 |
| 3 | 0.0721238784924673 | 0.022296921287985 | 0.233299197750645 | 2.49736604361386 |
| 6 | 0.0915144099896647 | 0.0270160295351771 | 0.309996967720651 | 2.49736604361386 |
| 9 | 0.0538541317831652 | 0.0124959954294147 | 0.23209575631658 | 2.49736604361386 |
| 12 | 0.234212994726844 | 0.0554890627705838 | 0.988586293585713 | 2.49736604361386 |
| 15 | 0 | (blank) | (blank) | 2.49736604361386 |
By plan, with a bandwidth of 4 months
Basic customers leave early, Plus customers late; after month 8 no Basic customer is left to leave.
EVALUATE
VAR Customers =
DATATABLE (
"Plan", STRING, "Months", INTEGER, "Left", INTEGER,
{
{ "Basic", 2, 1 }, { "Basic", 3, 0 }, { "Basic", 5, 1 }, { "Basic", 7, 1 }, { "Basic", 8, 0 },
{ "Plus", 4, 1 }, { "Plus", 9, 0 }, { "Plus", 11, 1 }, { "Plus", 12, 1 }, { "Plus", 15, 0 }
}
)
RETURN
FILTER (
SURVIVAL.HAZARD ( Customers, [Months], [Left], [Plan], 4 ),
ROUND ( [Time], 4 ) = ROUND ( [Time], 0 )
)
| Group | Time | Hazard | Lower | Upper | Bandwidth |
|---|---|---|---|---|---|
| Basic | 0 | 0.05625 | 0.00792357154274348 | 0.399322765363013 | 4 |
| Basic | 3 | 0.0857142857142857 | 0.0211374263838101 | 0.34757962687158 | 4 |
| Basic | 6 | 0.146484375 | 0.0356435654618004 | 0.602006893562234 | 4 |
| Basic | 9 | 0.0703125 | 0.00990446442842935 | 0.499153456703766 | 4 |
| Basic | 12 | 0 | (blank) | (blank) | 4 |
| Basic | 15 | 0 | (blank) | (blank) | 4 |
| Plus | 0 | 0 | (blank) | (blank) | 4 |
| Plus | 3 | 0.036734693877551 | 0.00517457733403656 | 0.26078221411462 | 4 |
| Plus | 6 | 0.028125 | 0.00396178577137174 | 0.199661382681506 | 4 |
| Plus | 9 | 0.087890625 | 0.021913720499782 | 0.352508008075008 | 4 |
| Plus | 12 | 0.159183673469388 | 0.0383874572562517 | 0.660096909520673 | 4 |
| Plus | 15 | 0.08203125 | 0.0115552084998342 | 0.582345699487727 | 4 |