stddev()

Calculates the population standard deviation of numeric values returned by an expression.

Syntax

stddev(NUM_EXPR)

Parameters

NUM_EXPR
An expression that returns the numeric values for which to calculate the standard deviation.

Description

The stddev() function internally computes the square root of var(NUM_EXPR). Because it is based on the population variance (divided by N), it returns the population standard deviation. Null values and non-numeric values are ignored. If there are no values, it returns null. If there is exactly one value, it returns 0.0. The return value is a 64-bit floating-point number (double).

Use this function in aggregation commands such as stats and timechart.

Error codes

CodeDescription
91020The number of arguments is incorrect.

Usage examples

To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.

  1. Calculate the standard deviation of response sizes across all requests

    table WEB_APACHE_SAMPLE | stats stddev(bytes)
    
  2. Calculate the standard deviation of response sizes per HTTP method

    table WEB_APACHE_SAMPLE | stats stddev(bytes) by method
    
  3. Null value handling

    json "[{'val': 10}, {'val': null}, {'val': 30}]"
    | stats stddev(val)
    | # Null values are ignored.
    

Compatibility

The stddev() function has been available since before Logpresso Sonar 4.0.