Math & Science· 4 min read

Linear Regression Calculator: Fit Lines to Data Instantly

You will learn how ordinary least squares regression works, what R-squared actually tells you, and how to interpret the slope and intercept for real predictions.

By EasyMath Team Last updated: 2026-08-23.

Why this matters

Scatterplots show you a pattern; linear regression quantifies it. When you have a set of (x, y) data points and suspect a straight-line relationship, the calculator fits the best possible line using ordinary least squares — the method that minimizes the sum of squared vertical distances from every point to the line. The result is an equation `y = mx + b` where the slope `m` tells you how much y changes per unit of x, and the intercept `b` tells you the predicted y when x equals zero.

Beyond the equation itself, the calculator reports R-squared (the coefficient of determination) and the Pearson correlation coefficient r. R-squared tells you what fraction of the variance in y is explained by the linear relationship with x — an R-squared of 0.85 means 85 percent of the spread in your y values is captured by the line. Pearson r gives you the direction and strength of the linear association, ranging from -1 (perfect negative) through 0 (no linear relationship) to +1 (perfect positive). Together, these numbers let you assess whether a linear model is actually appropriate for your data before you use it for predictions.

See it in action

Output metrics explained

MetricFormulaRangeMeaning
Slope (m)Sum((x-xbar)(y-ybar)) / Sum((x-xbar)^2)Any realChange in y per unit x
Intercept (b)ybar - m * xbarAny realPredicted y at x=0
R-squaredr^20 – 1Variance in y explained by line
Pearson rCov(x,y) / (sx * sy)-1 – +1Strength and direction of linear link

How to use it

Enter your data as comma-separated x,y pairs, one pair per line (for example: `1,2` then `3,5` then `4,7`).

The slope, intercept, R-squared, and Pearson r update instantly as you type or paste.

Use the resulting equation to predict any x value by plugging it into y = mx + b.

Testing your result

Start by entering a dataset where you already know the answer — for instance, the points (1,2), (2,4), (3,6) should produce a slope of exactly 2 and an intercept of 0, with R-squared of 1. Then paste real data and check whether the R-squared value matches your visual intuition from the scatterplot. If R-squared is below 0.3, the linear model explains less than a third of the variance and you should consider whether a different model (polynomial, logarithmic) might fit better. The Pearson r should be close in magnitude to the square root of R-squared — if it is not, something is wrong with the input formatting.

Common mistakes

Forgetting that linear regression assumes a straight-line relationship; applying it to clearly curved data produces misleading R-squared values.

Interpreting a high R-squared as proof of causation — correlation does not imply that x causes y.

Extrapolating far beyond the range of your input x values, where the linear assumption may break down completely.

Edge cases and limitations

You need at least two distinct x values for the slope to be defined — a vertical line of identical x values with different y values produces an undefined (infinite) slope. A single data point gives R-squared of exactly 1, which is mathematically correct but statistically meaningless. Outliers exert disproportionate influence on the least-squares fit; a single point far from the cluster can drag the line significantly. All computation happens in your browser, so there is no data transmission to worry about when working with sensitive datasets.

Real-world use cases

A student fitting a trendline to experimental physics lab data and extracting the slope to determine a physical constant.

A small business owner plotting monthly advertising spend against revenue to quantify return on ad spend.

A data analyst quickly screening multiple variable pairs for linear correlation before building a more complex model.

Frequently asked questions

Q: What is linear regression?

A: Linear regression fits a straight line y = mx + b through a set of (x, y) points by minimizing the sum of squared vertical distances (least squares).


Q: How is the slope computed?

A: m = Sum((x - xbar)(y - ybar)) / Sum((x - xbar)^2). The intercept is b = ybar - m times xbar where xbar and ybar are the means of x and y.


Q: What is R-squared?

A: The coefficient of determination: the fraction of variance in y explained by the line. R-squared = 1 means a perfect fit; R-squared = 0 means the line is no better than the mean of y.


Q: What is Pearson r?

A: The Pearson correlation coefficient between x and y, ranging from -1 (perfect negative) to +1 (perfect positive). r squared equals R-squared for a simple linear fit.


Q: Is the math done locally?

A: Yes — entirely in your browser.

Start using it now

Fit a line to your data and get instant slope, intercept, R-squared, and correlation with the Linear Regression Calculator. For related statistical analysis, try the Z-Score Calculator or the Average Calculator. Explore matrix operations for multivariate regression with the Matrix Calculator.

Need help using this tool?

Read our complete Linear Regression Calculator tutorial for step-by-step guidance.

Ready to try the tool?

No accounts. No uploads. No limits. Start now.