Least-Squares Method

Description

The least-squares method is a way to find a simple analytic function that describes the general behavior of the data, even if the function does not pass through every single point. It should minimize the sum of the deviations from the discrete data to the function squared.

The linear regression consists on fitting a line to a set of discrete points (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2), …, (xn,yn)(x_n, y_n). The error is added to the equation of a line:

y=ao+a1x+Ey = a_o + a_1x + E

To get the coefficients of the equation:

a1=nxiyixiyinxi2(xi)2a_1 = \dfrac{n \sum x_iy_i - \sum x_i \sum y_i}{n \sum x_i^2 - (\sum x_i)^2}
a0=ya1xa_0 = \overline{y} - a_1 * \overline{x}

Error calculation

The best adjusted data is the one that minimizes the sum of the squared residues SrS_r, meaning the error between the model and the experimental data, this is the vertical distance between the points and the line:

Sr=i=1n=(yia0a1x)2S_r = \sum_{i=1}^{n} = (y_i - a_0 - a_1x)^2

To calculate the error, we need to sum the squared difference of each point with the mean on the y-axis:

St=i+1n(yiy)2S_t = \sum_{i+1}^{n} (y_i - \overline{y})^2

The coefficient of corelation (how good is the regression) is calculated as:

r=StSrStr = \sqrt{\dfrac{S_t - S_r}{S_t}}

Calculator