Linear Regression Calculator
Find the line of best fit for a set of x and y points using ordinary least squares. Enter your data and the calculator returns the slope, intercept, the full equation, r-squared, and the correlation coefficient, with a scatter plot of your points and the fitted line.
How to run a linear regression
- Enter your data as (x, y) pairs, one row per observation.
- Add or remove rows until every data point is in the table.
- Read the slope, intercept, equation, and r-squared from the result cards.
Examples
A perfect straight line
(1, 2), (2, 4), (3, 6)
y = 2x + 0, r-squared = 1
A noisy data set
(1, 2), (2, 3), (3, 5), (4, 4), (5, 6)
y = 0.9x + 1.3, r-squared = 0.81
Frequently asked questions
What is linear regression?
Linear regression finds the straight line that best describes the relationship between an input x and an output y. This calculator uses ordinary least squares, which picks the slope and intercept that make the total squared distance between the line and your data points as small as possible.
What does r-squared mean?
R-squared, the coefficient of determination, is the share of the variation in y that the line explains, on a scale from 0 to 1. A value of 1 means every point sits exactly on the line, while a value near 0 means the line explains almost none of the variation. For example, r-squared of 0.81 means the line accounts for 81 percent of the variance in y.
How are the slope and intercept calculated?
The slope equals the covariance of x and y divided by the variance of x (Sxy divided by Sxx). The intercept is the mean of y minus the slope times the mean of x, which forces the line to pass through the average point. Together they give the equation y = slope times x plus intercept.
What is the difference between r and r-squared?
The correlation coefficient r ranges from -1 to 1 and shows both the strength and direction of the relationship: positive means y rises with x, negative means it falls. R-squared is simply r multiplied by itself, so it is always between 0 and 1 and drops the sign, measuring only how much of the variation is explained.
Why do I need at least two points, and why must the x values differ?
A line is defined by two points, so a single point cannot fix a slope. The x values also cannot all be identical, because that would be a vertical line with no finite slope and the formula would divide by zero. The calculator asks for two or more points that vary in x.
Is my data sent anywhere?
No. The regression runs entirely in your browser, so your data points never leave your device and nothing is stored on a server.
Related tools
Standard Deviation Calculator
Calculate standard deviation and variance online. Paste a list of numbers to get the mean, count, and both sample and population results instantly.
Average Calculator
Find the mean, median, mode, range, sum, count, min and max of a list of numbers. Paste values separated by commas, spaces or new lines.
Matrix Calculator
Add, subtract, multiply, transpose, and invert matrices online. Find determinants and scale by a scalar with editable grids and instant results.
Area Calculator
Find the area of a circle, square, rectangle, triangle, trapezoid, parallelogram, ellipse, sector or rhombus. Free and runs in your browser.
Arithmetic Sequence Calculator
Find the nth term, the sum of n terms and the full term list for any arithmetic or geometric sequence. Enter the first term, step or ratio, and n.
Big Number Calculator
Add, subtract, multiply, divide, power, modulo, factorial, GCD and LCM on integers of any length. Exact results with no rounding, computed in your browser.