Math & Stats
Linear Regression Calculator
Enter data points and get the best-fit line equation (y = mx + b), R² correlation coefficient, slope, intercept, and predicted values.
Data Points (x, y)
Add at least 2 data points and click Calculate
Least Squares Formulas
Slope (m) = [n*Sum(xy) - Sum(x)*Sum(y)] / [n*Sum(x^2) - (Sum(x))^2]
Intercept (b) = y_mean - m*x_mean
R^2 = [n*Sum(xy) - Sum(x)*Sum(y)]^2 / ([n*Sum(x^2) - (Sum(x))^2] * [n*Sum(y^2) - (Sum(y))^2])
Where:
n = number of data points
x_mean = mean of x values
y_mean = mean of y values FAQ
Frequently asked questions about linear regression
What is linear regression?
Linear regression is a statistical method that finds the best-fitting straight line through a set of data points. It minimizes the sum of squared vertical distances (residuals) between observed values and the predicted line y = mx + b.
What does R-squared (R²) mean?
R-squared is the coefficient of determination, ranging from 0 to 1. It represents the proportion of variance in the dependent variable explained by the independent variable. An R-squared of 0.85 means 85% of the variation in y is explained by x.
How many data points do I need for linear regression?
You need at least 2 points to define a line, but meaningful regression requires more. A minimum of 5-10 points is recommended to get reliable statistics. More points generally give better estimates.
What is the least squares method?
The least squares method finds the line that minimizes the sum of squared residuals (differences between observed and predicted y-values). It produces the slope m = [n*Sum(xy) - Sum(x)*Sum(y)] / [n*Sum(x^2) - (Sum(x))^2] and intercept b = y_mean - m*x_mean.
When should I not use linear regression?
Don't use linear regression when: the relationship isn't linear (use polynomial or other models), there are significant outliers, the residuals aren't normally distributed, or the data shows heteroscedasticity (unequal variance).
What's the difference between correlation and regression?
Correlation (r) measures the strength and direction of a linear relationship between two variables. Regression goes further by providing a predictive equation (y = mx + b) that lets you estimate y from x. R-squared = r-squared for simple linear regression.