# Least Squares Calculator

To use the least squares calculator, enter the X values, enter the Y values, and click calculate

Give Us Feedback

## Least Squares Calculator

Find the best-fit line for a number of points on the XY plane using the least squares calculator. You can see all the necessary computations of the slope and intercept of the said line in the result section.

It also finds errors for both values of the line (slope and intercept), Pearson correlation, and the status of the correlation.

## What are least squares?

The method of Least Squares is a widely implemented statistical approach used to find the best-fitting curve to a given set of points by minimizing the sum of the squares of the offsets (the residuals) of the points from the curve.

It is commonly employed in regression analysis to approximate the solution of overdetermined systems.

Imagine your friends are helping you measure the length of your jump on the playground. Each one gets a slightly different result because of where they’re standing. How do you find the most fair estimate of the actual jump length?

Least Squares squares the differences (the little errors) between each friend’s guess and finds the best average spot that is "least" off from all guesses. It minimizes the sum of the squares of those little errors (or differences) to find the best estimate.

## Formula for least squares:

The method of least squares provides formulas to find the coefficients a and b that minimize the sum of squared residuals:

Slope:

It is calculated by dividing the covariance of x and y by the variance of x.

• n is the number of observations,
• ∑xy is the sum of the product of each pair of x and y values,
• ∑x and ∑y are the sums of the x and y values, respectively,
• ∑x^2 is the sum of the squares of the x values.

Intercept:

a = ͞y - b ͞x

Here:

• ͞y is the mean of y values.
• ͞x is the mean of x values.
• b is slope

The least squares technique is used to make a linear regression equation.

## How to find the least squares?

1. Gather Data: Collect data points (xi, yi) where i ranges from 1 to n (the total number of points).
2. Compute Necessary Sums: Calculate the following sums: Sx, Sy, Sxx, and Sxy
3. Calculate the Slope (a)
4. Calculate the Y-Intercept (b): a = ͞y - b ͞x
5. Formulate the Regression Equation: Y = a + bx

### Solved Example:

Let’s consider we have 3 data points (2,4),(3,5),(4,7).

Step 1: Data Points

Given

(x1, y1) = (2,4)

(x2, y2) = (3,5)

(x3, y3) = (4,7)

Step 2: Compute Sums

Sx = x1 + x2 + x3 = 2+3+4 = 9

Sy = y1 + y2 + y3 = 4+5+7 = 16

Sxy = x1.y1 + x2.y2 + x3.y3 = 2x4 + 3x5 + 4x7 = 8+15+28 = 51

Sxx = x1^2 + x2^2 + x3^2 = 4+9+16 = 29

Step 3: Calculate Slope

b = 3 x 51 − 9 x16 /  3 x 29 − 9^2

b = 153−144 / 87−81

b = 9/6 =1.5

Step 4: Calculate Y-Intercept

a = ( y1 + y2 + y3 /3) - (x1 + x2 + x3 /3) b

a = (16/3) - (9/3)1.5

a = 5.33 - (3)1.5

a = 5.33 - 4.5

a = 0.83

Step 5: Regression Equation

Y = 0.83 +1.5X

## Applications:

Linear Regression:

The simplest and most common application of least squares is linear regression, where f is a linear function of the parameters and the independent variable.

Polynomial Curve Fitting:

The method can also be used for polynomial regression, where the function f is polynomial in the independent variable.

General Curve Fitting:

More generally, least squares can be used to fit a model to data whenever there is a linear relationship between the parameters to be estimated and the response variable.

### Math Tools

ADVERTISEMENT
AdBlocker Detected!

To calculate result you have to disable your ad blocker first.