1. Home
  2. Calculators
  3. Linear Regression Calculator

Linear Regression Calculator

For science labs and data work: paste x y pairs to get the line, how well it fits and a plot you can download.

Free, no sign-up. Runs in your browser: nothing is uploaded.

Free workspace included. Docs, spreadsheets, notes and tasks that save on your device. No sign-up.Take a look

How to use Linear Regression Calculator

  1. Enter your numbers, or press a sample to see an example.
  2. Read the results and the table under them.
  3. Copy the results or download the table as a CSV file.

Features

  • Slope, intercept, r and R²
  • Standard errors, t-test and confidence interval for the slope
  • Predictions with confidence and prediction intervals
  • Scatter plot with line and confidence band
  • A residuals table

Supported formats

Input

  • x y pairs, one per line

You get

  • On-screen results
  • Scatter plot with line (SVG and PNG)
  • CSV residuals

Private by design

Everything you enter is processed by your browser on this device. Nothing is sent to openWorkstand or anyone else, so the Linear Regression Calculator is safe for private and work data. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • It fits a straight line to one predictor; it does not do multiple or non-linear regression.
  • Correlation does not show causation, and predictions outside the data range are unreliable.

Guide

Linear regression: line of best fit, R², standard errors and predictions

Regression turns a cloud of points into a line you can read and use. It tells you how much y changes for each unit of x, how well a straight line describes the data and what to expect at a new x. This calculator fits an ordinary least-squares line to pasted x and y values, reports the standard errors and a significance test for the slope, predicts at any x with two kinds of interval and draws the scatter plot with the line and a confidence band.

How the line is fitted

Least squares chooses the slope and intercept that make the sum of the squared vertical distances from the points to the line as small as possible. The slope is the sum of the products of the deviations, Sxy, divided by the sum of squared x-deviations, Sxx, and the intercept is ȳ − slope · x̄, so the line always passes through the mean point. The residual of each point is its y minus the fitted value, and the table lists them for the first forty points.

Entering data

Type one x y pair per line, separated by a space, comma or tab, with at least three points; the page tells you which line has the wrong number of values. Set the confidence level, from 80% to 99.9%, and optionally an x at which to predict y. The page opens on eight points and x = 9. Every x must not be identical, otherwise no line can be fitted, and the message says so.

Reading the results

For the eight sample points the line is y = 1.997619x + 0.035714286. The slope has a standard error of 0.0278004, the intercept 0.140385, and the correlation coefficient is r = 0.99941947, so R² = 0.99883929: 99.88% of the variation in y is explained by x. The slope’s p-value is below 0.0001, the 95% interval for the slope is 1.9295938 to 2.0656443, the standard error of the estimate is 0.18016747 and n = 8 with 6 degrees of freedom. The page also labels the strength of the relation, here very strong and positive.

Predictions and intervals

At x = 9 the line gives 18.014286. The confidence interval for the mean of y at that x is 17.6708 to 18.3578, and the prediction interval for one new observation is 17.4554 to 18.5732, which is wider because it includes the scatter of individual points around the line. The dashed curves in the chart show the confidence band; it is narrowest at the mean of x and widens towards the ends of the data, where the line is less certain.

Worked examples

Height and weight in seven people (150 to 180 cm) give y = 0.81428571x − 70.642857, r = 0.99647913 and R² = 0.99297066, with a prediction of 66.157143 at 168 cm. Ice cream sales against temperature for ten days give y = 28.428184x − 156.74959, r = 0.92924086, R² = 0.86348858 and a slope p-value of 0.0001; at 20 degrees the prediction is 411.81409 with a prediction interval of 280.448 to 543.18, which is wide because the scatter is large. Each sample is a chip on the page.

Residuals and the scatter plot

Always look at the plot. A good fit has points scattered evenly above and below the line. A curve, a fan shape or a few extreme points can hide behind a high R², and R² can be high when a line is the wrong model. A prediction outside the range of your x values triggers a warning, because extrapolation assumes the same relationship holds where you have no data. Download the chart as SVG or PNG for a report.

Limits

The tool fits one straight line to one predictor. It does not do multiple regression, curves, logarithmic or exponential fits, weighted regression or robust methods, and it does not check the assumptions of independence, equal spread and normal errors that the intervals rely on. Correlation does not show cause: both variables may be driven by a third. For more than 40 points only the first 40 residuals are listed, though all are used in the fit.

Checked against the current version of the Linear Regression Calculator on .

Frequently asked questions

What is the difference between r and R²?

The correlation coefficient r runs from −1 to 1 and gives the direction and strength of the straight-line relation, while R² is its square and gives the share of the variation in y that the line explains. An r of 0.929, as in the ice cream data, means R² = 0.863, so about 86% of the variation in sales is accounted for by temperature and 14% is not.

Why is the prediction interval wider than the confidence interval?

The confidence interval is for the average value of y at a given x, which depends only on how well the line is known. The prediction interval is for one new observation, which also scatters around the line by the standard error of the estimate. At x = 9 the first spans 0.69 units and the second 1.12, and the gap does not shrink with more data.

What does R² mean?

The share of the variation in y that the line explains: 0.9 means 90%. It does not show that x causes y.

Why is a prediction interval wider than a confidence interval?

The confidence interval is for the average y at that x; the prediction interval also includes the scatter of a single new point.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.