Skip to content

Linear Regression Calculator

Fit a least-squares regression line to a set of (x, y) data points. Get the slope, intercept, R² value, and a chart of the fitted line.

Category: math
Use Case: Trend Analysis, Statistics Homework, Forecasting
Privacy: 100% browser-based

6 valid points detected

Slope (m)
1.9971
Intercept (b)
0.0267
R² (Fit Quality)
0.9985

y = 1.9971x + 0.0267

y ≈ 14.0067

Recommended Settings

Pro Tips

  • R² ranges from 0 to 1 and indicates how well the line fits the data - closer to 1 means a stronger linear relationship
  • The slope tells you how much y changes for each one-unit increase in x, and the intercept is the predicted y value when x is 0
  • Predictions far outside your original data's x range are extrapolations and become less reliable the further you go
  • This calculates simple linear regression with one predictor variable - it won't fit curves or multiple variables

Most Popular

Most users paste x,y data copied from a spreadsheet to quickly find the trend line

When to Use This Tool

Trend Analysis

Find the linear trend in a data set, such as sales over time or a relationship between two measurements.

Statistics Homework

Calculate the least-squares regression line and R² value for a statistics course.

Forecasting

Use a fitted linear trend to make a rough prediction for a new x value.

Correlation Strength Checking

Use the R² value to gauge how strong the linear relationship is between two variables.

How It Works

1

Parse each line of input into an (x, y) coordinate pair

2

Calculate the slope and intercept that minimize the sum of squared vertical distances between the data points and the line (the least-squares method)

3

Calculate R² by comparing how much of the variation in y is explained by the line versus the total variation in y

4

Plot the data points and the fitted line together on a chart

100% Private

Files never leave your device. All processing happens locally in your browser.

Lightning Fast

Powered by Least-squares linear regression for optimal performance on modern browsers.

Open Source

Built with verified, open-source libraries. Fully transparent.

Frequently Asked Questions

What is R² and how do I interpret it?

R² (the coefficient of determination) ranges from 0 to 1 and measures how well the line fits your data. An R² of 1 means the line fits perfectly, while a value close to 0 means the linear relationship explains very little of the variation in y.

How is the regression line calculated?

This tool uses the least-squares method, which finds the slope and intercept that minimize the sum of the squared vertical distances between each data point and the line.

Can I use this to predict values outside my data range?

You can enter any x value for a prediction, but predictions far outside the range of your original data (extrapolation) are less reliable, since the linear trend may not continue to hold.

Is my data sent to a server?

No. All calculations happen instantly in your browser using JavaScript. Nothing you enter is transmitted anywhere.

What if my data isn't actually linear?

This tool always fits a straight line, even to non-linear data - it will just result in a low R² value, which is a signal that a linear model isn't a good fit for your data.