Statistics / Relationships

Linear Regression Calculator (Line of Best Fit)

Fit a straight line to paired data by least squares: the equation, slope and intercept with standard errors, R², the p-value for the slope, predictions, a scatter plot with the line, and the residuals.

Linear Regression Calculator (Line of Best Fit): Least squares chooses the slope b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² and intercept a = ȳ − b·x̄, so the line passes through the means and the squared vertical distances are as small as possible. R² is 1 minus the residual sum of squares over the total. For the example data the line is y = 1.998x + 0.036 with R² = 0.999. Standard errors and the p-value match SciPy's linregress. Runs 100% locally in your browser with zero server file uploads.

Runs
In your browser
Cost
Free · no sign-up
Availability
Ready to use
Linear regression calculatorLocal processing

Runs entirely in your browser

Line of best fity = 1.9976x + 0.0357
R²0.9988share of the variation in Y explained
Slope1.9976SE 0.0278, p < 0.0001
Intercept0.0357SE 0.1404
XYFittedResidual
12.12.03330.0667
23.94.031-0.131
36.26.02860.1714
47.88.0262-0.2262
510.110.02380.0762
612.212.02140.1786
713.814.019-0.219
816.116.01670.0833

Least squares picks the line that makes the squared vertical distances from the points as small as possible: slope = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², and the line passes through the means. R² is the share of Y's variation the line explains. Predictions outside the range of your X values are guesses, and a pattern in the residuals means a straight line is the wrong shape.

Worked example

Weight against height for 160–185 cm in steps of 5 with weights 55, 60, 65, 72, 78, and 85 kg: weight = 1.206 × height − 138.8, R² = 0.996, predicting 74.6 kg at 177 cm.

To plot other functions, use the graphing calculator.

Slope and correlation

The slope equals r × (SD of Y ÷ SD of X), so the slope's p-value is the same as the correlation's. R² for a simple line is exactly r².

To measure the strength of the relation without fitting a line, use the correlation calculator.

How to use it

  1. Paste the X values and the Y values in the same order.
  2. Read the equation, R², and the slope's p-value.
  3. Enter an X value to predict Y, and check the residuals.

Privacy & limitations

Your data stay in your browser.

Related tools

Frequently asked questions

What does R² tell me?

The share of the variation in Y that the line accounts for: 0.9 means 90%. A high R² does not prove the line is the right model.

Can I predict outside my data?

You can, but extrapolating beyond the range of X is risky: the relation may bend or stop.

What are residuals for?

They are the vertical gaps between each point and the line. If they show a pattern, such as a curve, a straight line is the wrong shape.

Free tool · runs in your browser · no account required