mathematical.linear_regression

Functions for performing linear regression.

Data:

ArrayLike_Float

Type hint for arguments that take either a sequence of floats or a numpy array.

Functions:

linear_regression_perpendicular(x[, y])

Calculate coefficients of a linear regression y = a * x + b.

linear_regression_vertical(x[, y, a, b])

Calculate coefficients of a linear regression y = a * x + b.

ArrayLike_Float

Type hint for arguments that take either a sequence of floats or a numpy array.

Alias of Union[Sequence[float], ndarray]

linear_regression_perpendicular(x, y=None)[source]

Calculate coefficients of a linear regression y = a * x + b. The fit minimizes perpendicular distances between the points and the line.

Parameters

If y is omitted, x must be a 2-D array of shape (N, 2).

Return type

Tuple[float, float, float, float]

Returns

(a, b, r, stderr), where a – slope coefficient, b – free term, r – Peason correlation coefficient, stderr – standard deviation.

linear_regression_vertical(x, y=None, a=None, b=None)[source]

Calculate coefficients of a linear regression y = a * x + b. The fit minimizes vertical distances between the points and the line.

Parameters

If y is omitted, x must be a 2-D array of shape (N, 2).

Return type

Tuple[float, float, float, float]

Returns

(a, b, r, stderr), where a – slope coefficient, b – free term, r – Pearson correlation coefficient, stderr – standard deviation.