series_stats
This page explains how to use the series_stats function in APL.
The series_stats function computes comprehensive statistical measures for a numeric dynamic array (series), returning an array with seven elements containing minimum, maximum, average, variance, standard deviation, and the positions of minimum and maximum values.
You can use series_stats when you need a complete statistical summary of time-series data in a single operation. This is particularly useful for understanding data distribution, identifying outliers, calculating confidence intervals, or performing comprehensive data quality assessments without running multiple separate aggregations.
Usage
Syntax
series_stats(array)Parameters
| Parameter | Type | Description |
|---|---|---|
array | dynamic | A dynamic array of numeric values. |
Returns
An array with seven numeric elements in the following order:
| Index | Statistic | Description |
|---|---|---|
| 0 | min | The minimum value in the input array. |
| 1 | min_idx | The first position of the minimum value in the array. |
| 2 | max | The maximum value in the input array. |
| 3 | max_idx | The first position of the maximum value in the array. |
| 4 | avg | The average value of the input array. |
| 5 | variance | The sample variance of the input array. |
| 6 | stdev | The sample standard deviation of the input array. |
Use case examples
In log analysis, you can use series_stats to get a comprehensive statistical summary of request durations for each user, helping identify performance patterns and outliers.
Query
Output
| id | min_duration | max_duration | avg_duration | stdev_duration |
|---|---|---|---|---|
| u123 | 15 | 245 | 95 | 45.2 |
| u456 | 8 | 189 | 78 | 38.7 |
This query calculates comprehensive statistics for each user's request durations by extracting specific elements from the 7-element stats array.
In security logs, you can use series_stats to establish behavioral baselines and calculate anomaly detection thresholds based on variance.
Query
Output
| status | typical_duration | variance | stdev | max_observed | anomaly_threshold |
|---|---|---|---|---|---|
| 200 | 52 | 156.25 | 12.5 | 340 | 89.5 |
| 401 | 450 | 722840 | 850.2 | 8900 | 3000.6 |
| 500 | 125 | 9082 | 95.3 | 550 | 410.9 |
This query uses statistical analysis to establish normal behavior patterns and calculate anomaly detection thresholds based on standard deviations.
List of related functions
- series_stats_dynamic: Returns the same statistics as a dynamic object with named properties instead of an array.
- series_max: Compares two arrays element-wise and returns the maximum values.
- series_min: Compares two arrays element-wise and returns the minimum values.
- avg: Aggregation function for calculating averages across rows.
- stdev: Aggregation function for standard deviation across rows.