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:

logscale
math:stdDevOutliers(value=responseTime, average=200, standardDeviation=40, factor=3)
Function Summary
Signaturemath:stdDevOutliers([average], [factor], [standardDeviation], value)
Parameters for math:stdDevOutliers()
ParameterTypeInterpreted TypeRequiredDefault ValueDescription
averageย expressionoptional[a] _avg The average (mean) of the baseline distribution. Any expression. If the result is non-numeric, the event is undecided.
factorย expressionoptional[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ย expressionoptional[a] _stddev The standard deviation of the baseline distribution. Any expression. If the result is non-numeric, the event is undecided.
value[b]ย expressionrequired ย  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.

[b] The parameter name value can be omitted.

Hide omitted argument names for this function

Show omitted argument names for this function

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 z evaluates to NaN, 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 compares z to the factor. The event is an outlier only if z < -factor or z > 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:

  • 3 is not an outlier.

  • 3.0001 is 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.

Fixed baseline with the default factor

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].

logscale
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
Custom factor

This example uses a custom factor.

In this example, factor=2 sets the normal range to [0, 4].

logscale
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
Default _avg and _stddev fields

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.

logscale
math:stdDevOutliers(value=value)

If event data looks like this:

value_avg_stddev
221
321
3.521
021

it would return:

value_avg_stddev
3.521
021
Per-event baseline from fields

This example uses a per-event baseline from fields.

In this example, the avg and stddev fields of each event define the baseline.

logscale
math:stdDevOutliers(value=value, average=avg, standardDeviation=stddev)

If event data looks like this:

valueavgstddev
10102
16102
12102
7102

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:

valueavgstddev
16102
7102
Calculated expressions

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].

logscale
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:

  • 8192 bytes = 8 KB. This value is inside the range, so the function drops the event.

  • 20480 bytes = 20 KB. This value is an outlier, so the function keeps the event.

  • 5120 bytes = 5 KB. This value is an outlier, so the function keeps the event.

  • 13312 bytes = 13 KB. This value equals the upper limit, so the function drops the event.

Negation keeps missing and non-numeric events

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.

logscale
!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.

Zero standard deviation

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.

logscale
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:

  • 2 produces NaN. The event is undecided, so the math:stdDevOutliers() function drops the event.

  • 1.9999 and 0 produce -Infinity. These events are outliers, so the math:stdDevOutliers() function keeps them.

  • 2.0001 and 4 produce +Infinity. These events are outliers, so the math:stdDevOutliers() function keeps them.

  • notanumber is non-numeric. The event is undecided, so the math:stdDevOutliers() function drops the event.

For the numeric input values, the negated function !math:stdDevOutliers(...) returns only 2.