Computes a linear relationship model between two variables using least-squares fitting. Given variables x and y, the relationship is

logscale
y = slope * x + intercept

The result is output in fields named _slope and _intercept — unless a different prefix than _ is specified. Also output are the adjusted R-squared value _r2 and the number of data points _n. No output is produced, however, if all x values are the same or if all y values are the same.

ParameterTypeRequiredDefault ValueDescription
prefixstringoptional[a]_ Prefix for the names of all the output fields.
xstringrequired  The name of the field containing the independent variable.
ystringrequired  The name of the field containing the dependent variable.

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

linReg() Examples

Find the correlation between the bytes sent in a server response and the time to send them.

logscale
linReg(x=bytes_sent, y=send_duration)

Find the correlation between server load and total response size across time.

logscale
bucket(function=[ sum(bytes_sent, as=x), avg(server_load_pct, as=y) ])
| linReg(x=x, y=y)

Find the correlation between server load and each of several types of request types across time.

logscale
bucket(function=[ avg(server_load_pct, as=y), groupby(request_type, function=count(as=x)) ])
| groupby(request_type, function=linReg(x=x, y=y))