Linear Regression Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

What this linear regression calculator does

This tool fits a straight line to your paired X and Y data using simple linear regression (ordinary least squares). It returns the slope, intercept, correlation, and R-squared, along with the equation of the best fit line so you can make predictions and understand how strongly X and Y move together.

You provide two equal-length lists of numbers (X values and Y values). The calculator then computes the line Y = slope × X + intercept that best summarizes the relationship between them, in the least squares sense.

How to enter your data

Enter your X and Y values as two lists of the same length. Each position in the X list must match the same position in the Y list (they form pairs).

You can copy a column directly from a spreadsheet and paste it into the X or Y box. Then paste the matching column into the other box, making sure you do not insert or delete any rows in between.

Example dataset you can try

To see how the calculator works, try this small example of study time (hours) and test scores (points out of 100):

X (hours studied):

1
2
3
4
5
6

Y (test score):

52
57
63
68
74
79

If you paste these values into the calculator, you will get a positive slope. That slope tells you how many test score points tend to increase, on average, for each additional hour of study. You will also see an R-squared close to 1, meaning the straight line explains most of the variation in scores for this simple example.

Formulas used by the linear regression calculator

The calculator uses the standard least squares formulas for simple linear regression with one predictor X and one outcome Y.

Let there be n data pairs (x1,y1),(x2,y2),,(xn,yn). First compute the sample means of X and Y:

\u03bc_X = \u2211i=1nxi n , \u03bc_Y = \u2211i=1nyi n

Here, the summation symbol means “add up over all data points.” The slope b1 and intercept b0 of the best fit line are:

bb1=(xiμX)(yiμY)(xiμX)2

bb0=μμY-b1μX

The resulting regression line is:

y^=b0+b1x

For any chosen X value, y^ is the predicted Y on the line.

Correlation and R-squared

The calculator often also computes the Pearson correlation coefficient r between X and Y, and then R-squared as R2=r2.

r=(xiμX)(yiμY)(xiμX) 2(yiμY) 2

R-squared (the coefficient of determination) is then:

R2=r2

R-squared measures the proportion of the variability in Y that can be explained by a linear relationship with X in this model.

Plain-language meaning of the symbols

Interpreting the results

Interpreting the slope

The slope tells you how much Y tends to change when X increases by one unit.

Always interpret the slope in the original units. For example, if X is “hours” and Y is “dollars,” a slope of 15 means each extra hour is associated with about $15 more.

Interpreting the intercept

The intercept is the predicted value of Y when X is zero. Sometimes this has a direct meaning (e.g., predicted starting weight when age = 0 days in a growth study). In other cases, X = 0 is outside the realistic range (e.g., 0 years of education in a dataset of adults), so the intercept is just a mathematical anchor for the line and should not be over-interpreted.

Understanding R-squared

R-squared ranges from 0 to 1:

A higher R-squared does not prove a causal relationship, and a lower R-squared does not necessarily mean the model is useless; it depends on the context and how much noise is typical in your field.

Worked example (step by step)

Using the earlier study-time dataset:

X (hours): 1, 2, 3, 4, 5, 6

Y (score): 52, 57, 63, 68, 74, 79

  1. Compute the average of X and Y.
    • Mean of X: (1 + 2 + 3 + 4 + 5 + 6) / 6 = 3.5
    • Mean of Y: (52 + 57 + 63 + 68 + 74 + 79) / 6 = 65.5
  2. For each pair, subtract the mean and multiply: (xi − meanX)(yi − meanY). Add up those products.
  3. Also compute (xi − meanX)2 for each point and add them up.
  4. Divide the sums to get the slope:
    • slope b 1 = ( xi meanX ) ( yi meanY ) ( xi meanX ) 2
  5. Compute the intercept:
    • intercept bb0=meanY-b1×meanX

For this dataset, the resulting equation is approximately:

Predicted score = 48.9 + 4.9 × hours studied

This means each extra hour of study is associated with roughly a 5-point increase in the test score, and the positive intercept shows the baseline level at very low study time. The calculator performs all these steps automatically for any dataset you enter.

Comparing key linear regression outputs

Output What it represents How to interpret it
Slope (b1) Average change in Y for a one-unit increase in X Sign (positive/negative) shows direction; magnitude shows strength of change per unit of X
Intercept (b0) Predicted value of Y when X = 0 Meaningful only if X = 0 is realistic; otherwise mainly anchors the line
Correlation (r) Strength and direction of linear association Ranges from -1 (perfect negative) to +1 (perfect positive); 0 means no linear relationship
R-squared (R2) Proportion of variance in Y explained by the linear model Close to 1: strong linear fit; close to 0: weak linear fit

Assumptions and limitations of simple linear regression

The calculator implements standard simple linear regression, which relies on several assumptions. These are not enforced by the tool, so it is your responsibility to judge whether they are reasonable for your data.

Because the tool is designed for quick, exploratory analysis, you should treat its output as one piece of evidence and combine it with subject-matter knowledge and more detailed diagnostics when decisions are important.

Provide equal-length datasets to see the best fit line.

Residual Run Mini-Game

Click to guide your trend line—catch drifting points before noise pulls them away.

Score0
Best0
Time90s
Stability
Controls: ←/→ slope, ↑/↓ intercept, space to pause, tap/drag to nudge line.
Stay close to the true regression—tight residuals earn higher streaks.
Aim for minimal error. Highlighted captures mirror low residuals in real fits.

Tip: After you calculate, the game tunes targets to your latest slope and intercept.

Embed this calculator

Copy and paste the HTML below to add the Linear Regression Calculator - Find the Best Fit Line to your website.