Calculate Relationship Between X And Y Variables - Example 1
Calculate the linear relationship between message size and
transmission time using the linReg()
function
Query
linReg(x=bytes_sent, y=send_duration)
Introduction
The linReg()
function can be used to calculate a
linear relationship between two variables by using least-squares
fitting. The function is used to analyze different performance
relationships in a system, for example: response size and transmission
time, server load and total response size, or server load and request
types.
In this example, the linReg()
function is used to
calculate the linear relationship between
bytes_sent (x
variable) and
send_duration (y
variable). The
example shows the relationship between message size (bytes sent in a
server) and transmission time (time to send the bytes).
Example incoming data might look like this:
@timestamp | bytes_sent | send_duration |
---|---|---|
2025-04-07 13:00:00 | 1024 | 0.15 |
2025-04-07 13:00:01 | 2048 | 0.25 |
2025-04-07 13:00:02 | 4096 | 0.45 |
2025-04-07 13:00:03 | 8192 | 0.85 |
2025-04-07 13:00:04 | 512 | 0.08 |
2025-04-07 13:00:05 | 16384 | 1.65 |
2025-04-07 13:00:06 | 3072 | 0.35 |
2025-04-07 13:00:07 | 6144 | 0.65 |
2025-04-07 13:00:08 | 10240 | 1.05 |
2025-04-07 13:00:09 | 4608 | 0.48 |
Step-by-Step
Starting with the source repository events.
- flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0{{Aggregate}} result{{Result Set}} repo --> 0 0 --> result style 0 fill:#ff0000,stroke-width:4px,stroke:#000;logscale
linReg(x=bytes_sent, y=send_duration)
Correlates bytes_sent with send_duration, showing the relationship between message size and transmission time (the variables
x
andy
) and outputs the results in fields named _slope (slope value),_intercept (intercept value),_r2 (adjusted R-squared value), and _n (number of data points). These four key values indicate relationship strength and reliability. Event Result set.
Summary and Results
The query is used to calculate a linear relationship between
bytes_sent (x
variable) and
send_duration (y
variable).
Calculating the relationship between size of data transferred and time taken to send data is useful, for example, in trend analysis, performance monitoring, or anomaly detection.
Sample output from the incoming example data:
_slope | _intercept | _r2 | _n |
---|---|---|---|
9.823069852941172E-5 | 0.04276470588235326 | 0.9996897336895081 | 10 |
_slope is the additional time needed per byte sent.
_intercept is the baseline transmission time.
_r2 is the statistical accuracy of the linear model.
_n is the total number of data points analyzed.