The linReg() function calculates a linear relationship between two variables by using least-squares fitting.

The function creates this relationship between x and y variables:

logscale
y = slope * x + intercept

The result is outputted in fields named _slope and _intercept — unless a different prefix than _ is specified.

Also outputted is the adjusted R-squared value in a field named _r2 and the number of data points in a field named _n.

These four key values indicate relationship strength and reliability.

Note that if all x values are the same or if all y values are the same, then the function cannot calculate results, therefore, nothing is outputted.

ParameterTypeRequiredDefault ValueDescription
prefixstringoptional[a] _ Prefix for all output field names.
xstringrequired   Specifies the field name that contains the independent variable.
ystringrequired   Specifies the field name that contains the dependent variable.

[a] Optional parameters use their default value unless explicitly set.

linReg() Examples

Click + next to an example below to get the full details.

Calculate Relationship Between X And Y Variables - Example 1

Calculate the linear relationship between message size and transmission time using the linReg() function

Calculate Relationship Between X And Y Variables - Example 2

Calculate the linear relationship between server load and total response size using the linReg() function with bucket()

Calculate Relationship Between X And Y Variables - Example 3

Calculate the linear relationship between server load and each of several types of request types using the linReg() function with bucket() and groupBy()