Functions to perform simple ordinary least squares (OLS) linear regression.
The OLS fit finds \(c_0\) and \(c_1\) that minimize
$$\mathcal{L}(c_0, c_1) := \sum_{i=0}^{n-1} (y_i - c_0 - c_1 x_i)^2$$
producing the model \(f(x)=c_0+c_1x\). The optional \(R^2\) output uses
$$R^2 = 1 - \frac{\sum_i (y_i - c_0 - c_1x_i)^2}{\sum_i (y_i - \bar{y})^2}$$
Value
A two-element numeric vector containing the intercept and slope of the regression line, or a three-element vector containing the intercept, slope, and R-squared value if applicable.
See also
Boost Documentation for more details on the mathematical background.