series_pearson_correlation
This page explains how to use the series_pearson_correlation function in APL.
The series_pearson_correlation function calculates the Pearson correlation coefficient between two numeric dynamic arrays (series). This measures the linear relationship between the two series, returning a value between -1 and 1, where 1 indicates perfect positive correlation, -1 indicates perfect negative correlation, and 0 indicates no linear correlation.
You can use series_pearson_correlation when you need to measure the strength and direction of linear relationships between time-series datasets. This is particularly useful for identifying related metrics, detecting causal relationships, validating hypotheses about system behavior, or finding leading indicators of performance issues.
Usage
Syntax
Parameters
| Parameter | Type | Description |
|---|---|---|
series1 | dynamic | A dynamic array of numeric values. |
series2 | dynamic | A dynamic array of numeric values. |
Returns
A numeric value between -1 and 1 representing the Pearson correlation coefficient:
1: Perfect positive linear correlation0: No linear correlation-1: Perfect negative linear correlation
Use case examples
In log analysis, you can use series_pearson_correlation to identify relationships between request durations across different geographic regions, helping understand if performance issues are correlated.
Query
Output
| correlation |
|---|
| 0.87 |
This query calculates the correlation between request durations in Tokyo and Nagasaki, revealing if performance issues in one region tend to coincide with issues in another.
In OpenTelemetry traces, you can use series_pearson_correlation to analyze relationships between service latencies, identifying dependencies and bottlenecks.
Query
Output
| correlation |
|---|
| 0.65 |
This query measures the correlation between frontend and checkout service latencies, helping understand if performance of one service affects the other.
In security logs, you can use series_pearson_correlation to identify relationships between failed authentication attempts and successful requests, detecting potential attack patterns.
Query
Output
| correlation |
|---|
| -0.45 |
This query analyzes the correlation between successful and failed requests, where a negative correlation might indicate that high failure rates suppress successful requests, potentially signaling an attack.
List of related functions
- series_magnitude: Calculates the magnitude of a series. Use when you need vector length instead of correlation.
- series_stats: Returns comprehensive statistics. Use when you need variance and covariance components separately.
- series_subtract: Performs element-wise subtraction. Often used to compute deviations before correlation analysis.
- series_multiply: Performs element-wise multiplication. Use for weighted combinations instead of correlation.