Available: math:stdDevOutliers()
v1.268.0
The math:stdDevOutliers() function is
available from version 1.268.0.
The math:stdDevOutliers() function is a
filter function that finds events with unusual numeric values.
The math:stdDevOutliers() function keeps an
event only if its value is far from an average. You define "far"
as a number of standard deviations, called the factor.
In most queries, an earlier aggregation or join calculates the
average and standard deviation. For this reason, the
math:stdDevOutliers() function reads the
_avg and _stddev
fields by default.
Typical use cases include the following tasks:
Find anomalous readings compared to a baseline distribution. Examples include latency, payload size, and error counts.
Compare each event against its own baseline from other fields. For example, store one average and one standard deviation for each host.
Exclude outliers from further analysis with the negated function:
!math:stdDevOutliers(...).
For example:
math:stdDevOutliers(value=responseTime, average=200, standardDeviation=40, factor=3)| Signature | math:stdDevOutliers([average], [factor], [standardDeviation], value) |
math:stdDevOutliers()| Parameter | Type | Interpreted Type | Required | Default Value | Description |
|---|---|---|---|---|---|
average | ย | expression | optional[a] | _avg | The average (mean) of the baseline distribution. Any expression. If the result is non-numeric, the event is undecided. |
factor | ย | expression | optional[a] | 1 | The maximum distance from the average for a normal event. The function measures this distance in standard deviations. Any expression. If the result is non-numeric, the event is undecided. |
standardDeviation | ย | expression | optional[a] | _stddev | The standard deviation of the baseline 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:stdDevOutliers("value")and:
logscale Syntaxmath:stdDevOutliers(value="value")These examples show basic structure only.
math:stdDevOutliers() Function Operation
The math:stdDevOutliers() function has
specific implementation and operational considerations,
outlined below.
The math:stdDevOutliers() 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 responseTime.
An arithmetic expression, such as
bytes / 1024.A function call.
You can combine literal arguments and field-based arguments in the same function call.
The first parameter is
value,
not
field.
The math:rangeOutliers() function names
its first parameter
field.
This function names its first parameter
value.
As a result, you cannot call this function in a
match statement or with the =~
operator. These constructs pass the implicit subject as a
field
argument. This function has no
field
parameter, so the query returns an
UnrecognizedNamedArgument error.
Behavior
For each event, the
math:stdDevOutliers() function
calculates a normalized distance, called
z.
math:stdDevOutliers() calculates
z with the following formula:
z = (value - average) / standardDeviation
The math:stdDevOutliers() function
performs this calculation with IEEE 754 double-precision
floating-point numbers.
The math:stdDevOutliers() function
applies the following rules:
Undecided events: If any argument is missing or non-numeric, the event is undecided. If
zevaluates toNaN, the event is also undecided.math:stdDevOutliers()treats undecided events as non-outliers.Outlier events: If all arguments are valid numbers, the
math:stdDevOutliers()function compareszto the factor. The event is an outlier only ifz < -factororz > factor. This condition is equivalent to!(-factor <= z and z <= factor).
A missing baseline makes the event undecided. Some events
might lack the default _avg field or
_stddev field. These events are
undecided. The non-negated
math:stdDevOutliers() drops them, and
the negated math:stdDevOutliers() keeps
them. The math:stdDevOutliers()
function does not treat a missing value as
0.
NaN in any argument makes the event
undecided.
For a positive standard deviation, the normal range covers values between the following limits:
Lower limit:
average - (factor * standardDeviation).Upper limit:
average + (factor * standardDeviation).
Note
The math:stdDevOutliers() function
only filters events. It returns each kept event unchanged,
with all fields intact. Kept events retain their original
order. math:stdDevOutliers() 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:stdDevOutliers()
|
!math:stdDevOutliers()
|
|---|---|---|
z < -factor or z > factor
| Kept | Dropped |
-factor <= z and z <= factor
| Dropped | Kept |
| Any argument is missing | Dropped | Kept |
| Any argument is non-numeric | Dropped | Kept |
z evaluates to NaN, such as from 0/0
| Dropped | Kept |
Negation keeps undecided events. The negated 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. An event exactly
factor
standard deviations from the average is not an outlier.
The math:stdDevOutliers() function
applies no tolerance. For example, with
average=2, standardDeviation=1,
and the default factor=1, the function
evaluates values as follows:
3is not an outlier.3.0001is an outlier.
A standard deviation of 0 creates a
single-point range. Every numeric value that differs from
the average is an outlier. A value equal to the average is
undecided. For more information, see
math:stdDevOutliers() Syntax Examples.
A factor of 0 creates a single-point
range. Every numeric value that differs from the average is
an outlier.
A value of +Infinity or
-Infinity is an outlier. An infinite
factor makes every event with a valid z
value normal.
math:stdDevOutliers() Syntax Examples
Note
In the following input and result listings, an empty CSV value represents a missing field.
This example uses a fixed baseline with the default factor.
This example finds events more than one standard deviation
from an average of 2. The normal range is
[1, 3].
math:stdDevOutliers(value=value, average=2, standardDeviation=1)
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 |
| 1 |
| 1.5 |
| 2 |
| 3 |
| 3.0001 |
| 0.9999 |
| 5 |
it would return:
| value |
|---|
| 0 |
| 3.0001 |
| 0.9999 |
| 5 |
This example uses a custom factor.
In this example, factor=2 sets the normal range
to [0, 4].
math:stdDevOutliers(value=value, average=2, standardDeviation=1, factor=2)If event data looks like this:
| value |
|---|
| -1 |
| 0 |
| 2 |
| 4 |
| 4.0001 |
| 5 |
it would return:
| value |
|---|
| -1 |
| 4.0001 |
| 5 |
This example uses the default _avg and _stddev fields.
This query omits the
average
and
standardDeviation
arguments. As a result, the function reads the
_avg and _stddev
fields.
math:stdDevOutliers(value=value)If event data looks like this:
| value | _avg | _stddev |
|---|---|---|
| 2 | 2 | 1 |
| 3 | 2 | 1 |
| 3.5 | 2 | 1 |
| 0 | 2 | 1 |
it would return:
| value | _avg | _stddev |
|---|---|---|
| 3.5 | 2 | 1 |
| 0 | 2 | 1 |
This example uses a per-event baseline from fields.
In this example, the avg and stddev fields of each event define the baseline.
math:stdDevOutliers(value=value, average=avg, standardDeviation=stddev)If event data looks like this:
| value | avg | stddev |
|---|---|---|
| 10 | 10 | 2 |
| 16 | 10 | 2 |
| 12 | 10 | 2 |
| 7 | 10 | 2 |
The following table shows the z value and
result for each event. The default factor is
1.
| value | z | Result |
|---|---|---|
10
|
0
| Inside range (dropped) |
16
|
3
| Outlier (kept) |
12
|
1
| Inside range (dropped) |
7
|
-1.5
| Outlier (kept) |
it would return:
| value | avg | stddev |
|---|---|---|
| 16 | 10 | 2 |
| 7 | 10 | 2 |
This example uses calculated expressions.
All arguments can be expressions. In this example, the query
converts bytes to kilobytes. Values more than
1.5 standard deviations from
10 are outliers. The normal range is
[7, 13].
math:stdDevOutliers(value=bytes / 1024, average=10, standardDeviation=2, factor=1.5)If event data looks like this:
| bytes |
|---|
| 8192 |
| 20480 |
| 5120 |
| 13312 |
it would return:
| bytes |
|---|
| 20480 |
| 5120 |
The math:stdDevOutliers() function
evaluates each value as follows:
8192bytes =8KB. This value is inside the range, so the function drops the event.20480bytes =20KB. This value is an outlier, so the function keeps the event.5120bytes =5KB. This value is an outlier, so the function keeps the event.13312bytes =13KB. This value equals the upper limit, so the function drops the event.
This example applies the negated
math:stdDevOutliers() function. The
negated function keeps events inside the normal range. It also
keeps events with missing, non-numeric, or
NaN values.
!math:stdDevOutliers(value=value, average=2, standardDeviation=1)If event data looks like this:
| value |
|---|
| 1.5 |
| notanumber |
| 2 |
| <no value> |
| NaN |
| 3 |
| 100 |
it would return:
| value |
|---|
| 1.5 |
| notanumber |
| 2 |
| <no value> |
| NaN |
| 3 |
The negated math:stdDevOutliers()
function removes only the confirmed outlier,
100. The non-negated function returns only
100.
This example sets standardDeviation=0. A value
equal to the average produces 0/0, which is
NaN. The event is undecided. Every other
numeric value produces +Infinity or
-Infinity, which is an outlier.
math:stdDevOutliers(value=value, average=2, standardDeviation=0)If event data looks like this:
| value |
|---|
| 2 |
| 1.9999 |
| 2.0001 |
| 0 |
| 4 |
| notanumber |
it would return:
| value |
|---|
| 1.9999 |
| 2.0001 |
| 0 |
| 4 |
The math:stdDevOutliers() function
evaluates each value as follows:
2producesNaN. The event is undecided, so themath:stdDevOutliers()function drops the event.1.9999and0produce-Infinity. These events are outliers, so themath:stdDevOutliers()function keeps them.2.0001and4produce+Infinity. These events are outliers, so themath:stdDevOutliers()function keeps them.notanumberis non-numeric. The event is undecided, so themath:stdDevOutliers()function drops the event.
For the numeric input values, the negated function
!math:stdDevOutliers(...) returns only
2.