Least Squares Calculator

Enter your X values and Y values as comma-separated numbers to find the best-fit line using the Least Squares method. Your results include the slope (m), y-intercept (b), the full regression equation, and the Pearson correlation coefficient (r) — giving you a complete picture of how well the line fits your data.

Enter your X (predictor) values separated by commas.

Enter your Y (response) values separated by commas. Must match the count of X values.

Results

Regression Equation

--

Slope (m)

--

Y-Intercept (b)

--

Pearson Correlation (r)

--

Coefficient of Determination (r²)

--

Number of Data Points (n)

--

Data Points & Best-Fit Line

Results Table

Frequently Asked Questions

What is the least squares method?

The least squares method is a statistical technique used to find the best-fitting straight line through a set of data points. It works by minimizing the sum of the squares of the vertical distances (residuals) between each observed data point and the fitted line. This approach is the foundation of simple linear regression.

What is the formula for the least squares regression line?

The least squares line is written as Ŷ = mx + b, where m is the slope and b is the y-intercept. The slope is calculated as m = (n·Σxy − Σx·Σy) / (n·Σx² − (Σx)²), and the intercept as b = (Σy − m·Σx) / n, where n is the number of data points.

How do I use this least squares calculator?

Simply enter your X values in the first field and your Y values in the second field, using commas to separate each number. Both lists must contain the same number of values. The calculator will instantly return the slope, y-intercept, full regression equation, Pearson correlation coefficient, and a table of residuals.

What is a linear regression model?

A linear regression model describes the relationship between a predictor variable (X) and a response variable (Y) using a straight line. Unlike correlation, it produces an equation that lets you predict Y values for any given X, making it useful for forecasting and trend analysis.

What does the Pearson correlation coefficient (r) tell me?

The Pearson correlation coefficient r measures the strength and direction of the linear relationship between X and Y. It ranges from −1 to +1: values close to +1 indicate a strong positive relationship, values close to −1 indicate a strong negative relationship, and values near 0 suggest little or no linear association.

What is r² (coefficient of determination)?

r² is the square of the Pearson correlation coefficient and represents the proportion of variance in Y that is explained by X. For example, an r² of 0.85 means 85% of the variation in Y is accounted for by the linear relationship with X. Higher values indicate a better-fitting model.

What are residuals in linear regression?

A residual is the difference between an observed Y value and the Y value predicted by the regression line (Ŷ). Residuals help you assess how well the model fits the data. The least squares method minimizes the sum of squared residuals, which is why it produces the optimal best-fit line.

What are common applications of least squares regression?

Least squares regression is used across many fields, including economics (forecasting prices), biology (growth modeling), engineering (calibrating sensors), finance (analyzing trends), and social sciences (studying behavioral relationships). Any situation where you need to model or predict a linear relationship between two variables can benefit from this method.

More Math Tools