Available: math:iqrOutliers()
v1.268.0
The math:iqrOutliers() function is
available from version 1.268.0.
The math:iqrOutliers() function is a filter
function that finds events with unusual numeric values. The
math:iqrOutliers() function keeps an event
only if its value is outside two thresholds.
math:iqrOutliers() calculates these
thresholds from the interquartile range (IQR).
The IQR is the difference between the upper quartile and the lower quartile. Each threshold extends beyond its quartile by a multiple of the IQR. In statistics, these thresholds are called Tukey fences.
Typical use cases include the following tasks:
Find outliers in the output of the
percentile()function. Setpercentiles=[25, 75]to produce the _25 and _75 fields.Find outliers relative to the quartiles of each group. An earlier join or calculation can add these quartiles to each event.
Exclude outliers from further analysis with the negated function:
!math:iqrOutliers(...).
For example:
math:iqrOutliers(value=responseTime, lowerQuartile=q25, upperQuartile=q75)| Signature | math:iqrOutliers([factor], [lowerQuartile], [upperQuartile], value) |
math:iqrOutliers()| Parameter | Type | Interpreted Type | Required | Default Value | Description |
|---|---|---|---|---|---|
factor | ย | expression | optional[a] | 1.5 | The multiple of the IQR that extends the normal range. The function applies this extension below the lower quartile and above the upper quartile. Any expression. If the result is non-numeric, the event is undecided. |
lowerQuartile | ย | expression | optional[a] | _25 | The lower quartile (25th percentile) of the distribution. Any expression. If the result is non-numeric, the event is undecided. |
upperQuartile | ย | expression | optional[a] | _75 | The upper quartile (75th percentile) of the distribution. Any expression. If the result is non-numeric, the event is undecided. |
value[b] | ย | expression | required | ย | The value to test. Any expression. If the result is non-numeric, the event is undecided. |
[a] Optional parameters use their default value unless explicitly set. | |||||
Hide omitted argument names for this function
Omitted Argument NamesThe argument name for
valuecan be omitted; the following forms of this function are equivalent:logscale Syntaxmath:iqrOutliers("value")and:
logscale Syntaxmath:iqrOutliers(value="value")These examples show basic structure only.
math:iqrOutliers() Function Operation
The math:iqrOutliers() function has
specific implementation and operational considerations,
outlined below.
The math:iqrOutliers() function evaluates
all four expressions for each event. Each expression can be
any of the following types:
A literal value, such as
2.A field reference, such as q25.
An arithmetic expression, such as
bytes / 1024.A function call.
You can combine literal arguments and field-based arguments in the same function call.
Behavior
For each event, the math:iqrOutliers()
function calculates the IQR and two thresholds.
math:iqrOutliers() applies the
following formulas:
IQR = upperQuartile - lowerQuartile
lower threshold = lowerQuartile - factor * IQR
upper threshold = upperQuartile + factor * IQRThe normal range covers all values between the lower threshold and the upper threshold:
Undecided events: If any argument is missing or non-numeric, the event is undecided. If any argument or threshold evaluates to
NaN, the event is also undecided. Themath:iqrOutliers()function treats undecided events as non-outliers.Outlier events: If all values are valid numbers, the
math:iqrOutliers()function compares the value to the thresholds. The event is an outlier only if the value is less than the lower threshold. The event is also an outlier if the value is greater than the upper threshold.
Missing quartiles make events undecided. If you omit the
quartile arguments, the function reads the
_25 and _75
fields. For events that lack any of these fields, the event
is undecided. In this case, the non-negated
math:iqrOutliers() function drops all
events. The negated math:iqrOutliers()
keeps all events.
NaN in any argument or threshold makes
the event undecided.
Note
The math:iqrOutliers() function only
filters events. It returns each kept event unchanged, with
all fields intact. Kept events retain their original
order. math:iqrOutliers() adds no
fields and modifies no fields.
Negation
The negation operator (!) reverses the filter
result. The following table summarizes the results of each
form.
| Condition |
math:iqrOutliers()
|
!math:iqrOutliers()
|
|---|---|---|
value is less than the lower threshold
| Kept | Dropped |
value is greater than the upper threshold
| Kept | Dropped |
value is between the thresholds, inclusive
| Dropped | Kept |
value, lowerQuartile, upperQuartile, or factor is missing
| Dropped | Kept |
value, lowerQuartile, upperQuartile, or factor is non-numeric
| Dropped | Kept |
Any argument or threshold evaluates to NaN
| Dropped | Kept |
Negation keeps undecided events. The negated
math:iqrOutliers() function also
returns events with missing, non-numeric, or
NaN values. This behavior might be
unexpected. To return only valid numbers inside the normal
range, write an explicit numeric comparison instead.
Boundary Values
The normal range is closed. If a value equals a threshold, the value is inside the range. That value is not an outlier.
The math:iqrOutliers() function applies
no tolerance. For example, with
lowerQuartile=2, upperQuartile=3,
and the default factor, the function evaluates values as
follows:
4.5is not an outlier.4.5001is an outlier.
math:iqrOutliers() performs no argument
validation. The function accepts a
lowerQuartile
value that is greater than the
upperQuartile
value. The function also accepts a negative
factor
value. These values can produce an empty range. In that
case, every event with valid numeric values is an outlier.
A negative factor narrows the range. For a positive IQR, a
factor between -0.5 and
0 narrows the range. A factor less than
-0.5 makes the range empty.
math:iqrOutliers() Syntax Examples
Note
In the following input and result listings, an empty CSV value represents a missing field.
This example uses literal quartiles.
In this example, the lower quartile is 2,
and the upper quartile is 3. The IQR is
1. With the default factor of
1.5, the thresholds are
0.5 and 4.5.
math:iqrOutliers(value=value, lowerQuartile=2, upperQuartile=3)
In this query, the first value is the
parameter name. The second value is the
name of the event field.
If event data looks like this:
| value |
|---|
| 0 |
| 0.5 |
| 1.5 |
| 4.5 |
| 4.9999 |
| 0.4999 |
| -1 |
| 6 |
it would return:
| value |
|---|
| 0 |
| 4.9999 |
| 0.4999 |
| -1 |
| 6 |
The boundary values 0.5 and
4.5 are inside the range, so the function
drops them.
This example uses a custom factor.
In this example, factor=1 sets the thresholds to
1 and 4.
math:iqrOutliers(value=value, lowerQuartile=2, upperQuartile=3, factor=1)If event data looks like this:
| value |
|---|
| 0 |
| 1 |
| 1.5 |
| 4 |
| 4.5 |
| 0.9999 |
| 4.0001 |
it would return:
| value |
|---|
| 0 |
| 4.5 |
| 0.9999 |
| 4.0001 |
This example uses the default _25 and _75 fields.
This query omits the
lowerQuartile
and
upperQuartile
arguments. As a result, the
math:iqrOutliers() function reads the
_25 and _75 fields.
The percentile() function produces these
fields when you set percentiles=[25, 75].
math:iqrOutliers(value=value)If event data looks like this:
| value | _25 | _75 |
|---|---|---|
| 5 | 2 | 4 |
| 10 | 2 | 4 |
| 1 | 0 | 2 |
| 6 | 0 | 2 |
The following table shows the IQR, normal range, and result for each event.
| value | IQR | Normal range | Result |
|---|---|---|---|
5
|
2
|
[-1, 7]
| Inside range (dropped) |
10
|
2
|
[-1, 7]
| Outlier (kept) |
1
|
2
|
[-3, 5]
| Inside range (dropped) |
6
|
2
|
[-3, 5]
| Outlier (kept) |
it would return:
| value | _25 | _75 |
|---|---|---|
| 10 | 2 | 4 |
| 6 | 0 | 2 |
This example uses quartiles from custom fields.
In this example, the p25 and p75 fields of each event define the quartiles. Some events contain non-numeric or missing quartiles.
math:iqrOutliers(value=value, lowerQuartile=p25, upperQuartile=p75)If event data looks like this:
| value | p25 | p75 |
|---|---|---|
| 2 | 2 | 3 |
| 100 | 2 | 3 |
| 2 | notanumber | 3 |
| 2 | 2 | notanumber |
| 2 | <no value> | <no value> |
it would return:
| value | p25 | p75 |
|---|---|---|
| 100 | 2 | 3 |
The function evaluates each event as follows:
The first event has a value of
2. This value is inside the range[0.5, 4.5], so themath:iqrOutliers()function drops the event.The second event has a value of
100. This value is an outlier, so themath:iqrOutliers()function keeps the event.The third event has a non-numeric p25 field. The event is undecided, so the
math:iqrOutliers()function drops the event.The fourth event has a non-numeric p75 field. The event is undecided, so the
math:iqrOutliers()function drops the event.The fifth event has no quartile fields. The event is undecided, so the
math:iqrOutliers()function drops the event.
This example shows that negation keeps undecided events.
!math:iqrOutliers(value=value, lowerQuartile=p25, upperQuartile=p75)If event data looks like this:
| value | p25 | p75 |
|---|---|---|
| 2 | 2 | 3 |
| 100 | 2 | 3 |
| 2 | notanumber | 3 |
| 2 | 2 | notanumber |
| 2 | <no value> | <no value> |
it would return:
| value | p25 | p75 |
|---|---|---|
| 2 | 2 | 3 |
| 2 | notanumber | 3 |
| 2 | 2 | notanumber |
| 2 | <no value> | <no value> |
The negated math:iqrOutliers() function
removes only the confirmed outlier, 100.
This example uses a zero IQR.
In this example, both quartiles equal 2.
The IQR is 0. As a result, the normal range
is a single point, [2, 2].
math:iqrOutliers(value=value, lowerQuartile=2, upperQuartile=2)If event data looks like this:
| value |
|---|
| 1.9999 |
| 2 |
| 2.0001 |
| 0 |
| 4 |
it would return:
| value |
|---|
| 1.9999 |
| 2.0001 |
| 0 |
| 4 |
Only the value 2 is inside the range. The
math:iqrOutliers() function keeps every
other event.
This example uses inverted quartiles.
In this example, the
lowerQuartile
value is greater than the
upperQuartile
value. The IQR is -3. With the default
factor of 1.5, the function calculates the
following thresholds:
Lower threshold:
5 - (1.5 * -3) = 9.5.Upper threshold:
2 + (1.5 * -3) = -2.5.
The lower threshold is greater than the upper threshold. As a result, no value can be inside the range. Every event with valid numeric values is an outlier.
math:iqrOutliers(value=value, lowerQuartile=5, upperQuartile=2)If event data looks like this:
| value |
|---|
| -100 |
| 0 |
| 3 |
| 5 |
| 100 |
it would return:
| value |
|---|
| -100 |
| 0 |
| 3 |
| 5 |
| 100 |