Linear Regression Calculator

Simple linear regression finds the straight line that best fits a set of (x, y) data pairs by minimizing the sum of squared residuals. The result is a line equation y = b0 plus b1 times x, where b1 is the slope (change in y per unit change in x) and b0 is the y-intercept (value of y when x is zero). The calculator also computes R-squared, measuring how well the line explains the variation in Y. Enter two comma-separated lists of equal length: the first for the X values and the second for the Y values.

0.00
0.00
0.00
0.00

Least-squares regression formulas

b1 = ∑(xi - x̄)(yi - ȳ) / ∑(xi - x̄)²
b0 = ȳ - b1 × x̄
R² = [∑(xi - x̄)(yi - ȳ)]² / [∑(xi - x̄)² × ∑(yi - ȳ)²]

Where x-bar and y-bar are the sample means of X and Y respectively. These formulas minimize the sum of squared vertical distances from each point to the fitted line.

Reading the results

  • The equation of the best-fit line is: y = b0 plus b1 times x. Substitute any x value to predict y.
  • A positive slope means Y increases as X increases. A negative slope means Y decreases as X increases.
  • R-squared close to 1.00 indicates a strong linear fit. R-squared near 0.00 indicates a poor fit.
  • Pearson r is the square root of R-squared with the sign of the slope, giving the correlation coefficient.

Frequently asked questions

What is simple linear regression?

Simple linear regression models the relationship between two variables by fitting a straight line through the data. The line minimizes the sum of squared vertical distances (residuals) between the data points and the line. The equation is y = b0 plus b1 times x, where b0 is the intercept and b1 is the slope.

How are slope and intercept calculated?

The slope b1 = sum((xi - x-bar)(yi - y-bar)) / sum((xi - x-bar)^2), and the intercept b0 = y-bar minus b1 times x-bar, where x-bar and y-bar are the sample means. These are the ordinary least squares (OLS) formulas.

What does R-squared mean?

R-squared (the coefficient of determination) measures what proportion of the variability in Y is explained by the regression model. It ranges from 0 to 1: an R-squared of 0.80 means the regression line explains 80% of the variation in Y. It equals the square of the Pearson correlation coefficient.

What assumptions does linear regression make?

Ordinary least squares regression assumes: the relationship is linear, residuals are independent, residuals have constant variance (homoscedasticity), and residuals are approximately normally distributed. Violations can affect the reliability of predictions and significance tests.

Can I use this to predict Y values?

Yes. Once you have the slope and intercept, substitute any X value into y = b0 plus b1 times x to predict the corresponding Y. This is valid within the range of the observed X values; extrapolating far beyond that range is unreliable.

Official sources

Reviewed by the CalculatorHub team, edited by James Graham, 15 June 2026. See our methodology.