Skip to content
Conyso.
Free tools · Statistics

Linear regression calculator.

Paste paired x and y data for the least-squares line: slope, intercept, the equation, r and r-squared, the residual standard error, and the slope p-value, with a live scatter and the fitted line drawn over it. Instant, deterministic, and nothing you paste leaves your browser.

One pair per line, x then y, separated by a comma, space, or tab. At least two points are needed; three or more to test the slope.

gives y = —
— the fitted line
Intercept a — Slope b — r — r² — Std. error — t — p-value — n —
Enter values to calculate.
What this line is not A regression line can be fit to any data, even data with no real linear relationship: check r² and the residual pattern, do not extrapolate beyond the range of your data, and remember the line describes association, not causation.
Go beyond a single line.

Bench fits the model, checks the residuals for normality and pattern, and reports the full analysis on your real data, free, in your browser.

Open in Bench ↗

How it works

The method.

Simple linear regression fits a straight line through your points by least squares: it picks the slope and intercept that make the sum of the squared vertical gaps between the points and the line as small as possible. The slope is the average product of the x and y deviations divided by the spread in x, and the intercept follows so the line passes through the mean of the data.

Once the line is fixed, r-squared reports the share of the variation in y that the line explains, and the residual standard error measures the typical size of a point's miss from the line. The slope p-value comes from a t-test: the slope divided by its standard error, read against the t-distribution with n minus 2 degrees of freedom, tells you whether the trend is stronger than noise.

x →
The least-squares line through a cloud of points.

The formula

The maths, in the open.

b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)²  ·  a = ȳ − b·x̄  ·  ŷ = a + b·x

Worked example. For the points (1, 2), (2, 4), (3, 6), (4, 8) the line is exactly y = 2x: the slope is 2, the intercept is 0, and r-squared is 1 because every point sits on the line. With real, noisier data the slope stays near 2 but r-squared drops below 1 and the slope p-value tells you whether the trend is real.


Watch out

Common pitfalls.

A line can be fit to anything, so a slope alone means little: read it with r-squared and, if you can, a look at the residuals. A curved or fanning residual pattern says a straight line is the wrong model even when r-squared looks high. Extrapolating past the range of your data is guesswork, the line is only supported where you have points. And a strong fit is association, never proof of cause.


FAQ

Linear regression, answered.

How do you fit a simple linear regression line?

By least squares. The slope is the sum of (x minus mean-x) times (y minus mean-y), divided by the sum of (x minus mean-x) squared. The intercept is mean-y minus slope times mean-x. The line is y = intercept + slope times x.

What does r-squared tell me?

R-squared is the fraction of the variation in y explained by the line, from 0 to 1. An r-squared of 0.9 means the line accounts for 90 percent of the spread in y. A high r-squared means a tight fit, not that the relationship is causal.

What is the p-value for the slope?

It tests whether the slope differs from zero. A small p-value (below 0.05, say) means the trend is unlikely to be noise. The test uses t = slope divided by its standard error, with n minus 2 degrees of freedom.

Can I predict a y value?

Yes. Enter an x value in the predictor and it returns the fitted y from the line. Do not extrapolate far beyond the range of your data: the line is only supported where you have observations.

Is this calculator free?

Yes, free and no signup, running entirely in your browser.



Embed this calculator

Put it on your site, free.

A clean, responsive widget that runs in your visitor's browser, no signup. Pick an accent to match your brand, then copy the snippet. The Conyso mark stays on the widget.

Accent
Powered by Conyso.