ToolZoneX
Blog

Linear Regression Calculator - Slope, Intercept & R²

Calculate the least-squares linear regression line from a list of (x, y) data points, with slope, intercept, and R².

Slope (m)

1.9600

Intercept (b)

0.1800

0.9960

y = 1.9600x + 0.1800


How Linear Regression Works

Linear regression finds the straight line, y = mx + b, that best fits a set of (x, y) data points by minimizing the sum of squared vertical distances between the line and each point (the "least squares" method). The slope (m) shows how much y changes per unit of x, the intercept (b) is the predicted y value when x is 0, and R² (the coefficient of determination) shows how well the line fits the data, from 0 (no fit) to 1 (perfect fit).

m = (nΣxy − ΣxΣy) ÷ (nΣx² − (Σx)²)  |  b = (Σy − mΣx) ÷ n

Example

For the points (1, 2.2), (2, 4.1), (3, 5.8), (4, 8.3), and (5, 9.9), the least-squares line comes out to approximately y = 1.95x + 0.13, with an R² close to 0.998 — indicating the points fall very close to a straight line.

Common Use Cases

  • Finding the trend line for a scatter plot of experimental or business data.
  • Predicting a y value for a new x value based on an established linear relationship.
  • Checking how strongly two variables are linearly correlated using R².
  • Statistics coursework covering least-squares regression.

FAQs

What does R² actually tell me?

R² represents the proportion of variation in y that's explained by the linear relationship with x. An R² of 0.998 means about 99.8% of the variation in y is explained by the fitted line, while values closer to 0 mean the linear model explains very little of the pattern in the data.

How many data points do I need?

At least 2 points are needed to define a line mathematically, but 2 points will always produce a perfect R² of 1 regardless of any real relationship. Meaningful regression analysis typically needs several data points to reveal whether a genuine linear trend exists.

What if my data isn't actually linear?

Linear regression will still produce a best-fit straight line and an R² value, but a low R² is a signal that the relationship between x and y may be curved, cyclical, or otherwise non-linear, and a different type of model might describe the data better.