Performs simple (unidimensional) linear regression.
simpleLinearRegression(x, y)
Parameters:
x — Column with explanatory variable values.
y — Column with dependent variable values.
Returned values:
Constants (k, b) of the resulting line y = k*x + b.
Examples
SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3])
┌─arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3])─┐
│ (1,0) │
└───────────────────────────────────────────────────────────────────┘
SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6])
┌─arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6])─┐
│ (1,3) │
└───────────────────────────────────────────────────────────────────┘
simpleLinearRegression
Introduced in: v20.1
Performs simple (unidimensional) linear regression.
Syntax
simpleLinearRegression(x, y)
Arguments
x — Column with explanatory variable values. Float64
y — Column with dependent variable values. Float64
Returned value
Returns constants (k, b) of the resulting line y = k*x + b. Tuple(Float64, Float64)
Examples
Perfect linear fit
SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3]);
┌─arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3])─┐
│ (1,0) │
└───────────────────────────────────────────────────────────────────┘
Linear fit with offset
SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6]);
┌─arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6])─┐
│ (1,3) │
└───────────────────────────────────────────────────────────────────┘