Best-fit line tool

Linear Regression Calculator

Analyze paired x and y data to calculate the best-fit line, slope, intercept, correlation coefficient, and R squared.

Enter paired data

Calculate linear regression

Free tool

Enter one x,y pair per line. Spaces or commas can separate each pair.

The calculator uses ordinary least squares for the model y = mx + b.

Try an example:

Your regression results will appear here

Enter at least two paired x and y values to calculate the best-fit line.

Trend analysis

What does linear regression calculate?

Linear regression fits a straight line to paired numerical data. The model estimates how the dependent variable changes as the independent variable changes.

Model

Linear regression equation

Best-fit liney = mx + b

  • m is the slope.
  • b is the y-intercept.
  • x is the predictor variable.
  • y is the predicted response.

Worked example

Fit a line to 1,2; 2,4; and 3,6

  1. Mean of x = 2.
  2. Mean of y = 4.
  3. Calculated slope = 2.
  4. Calculated intercept = 0.
  5. Regression equation = y = 2x + 0.

Correlation

Interpret the correlation coefficient

The correlation coefficient r ranges from −1 to +1. Its sign indicates direction, and its magnitude indicates the strength of the linear association.

Positive r

Upward relationship

Larger x values tend to occur with larger y values.

Negative r

Downward relationship

Larger x values tend to occur with smaller y values.

Model fit

Interpret R squared

R squared describes the proportion of variation in y explained by the fitted linear relationship. A value closer to one indicates that the points lie more closely around the line.

Limitations

Avoid overinterpreting regression

  • Correlation does not prove causation.
  • A straight-line model may not fit curved relationships.
  • Extreme points can strongly affect the slope and correlation.
  • Predictions outside the measured x range may be unreliable.
  • Units and experimental context still matter.

Graphing

Plot the data before interpreting the model

A scatter graph helps reveal curvature, clusters, anomalies, or other patterns that summary statistics alone may hide.

Review the Tables and Graphs Guide and the Graphing Scientific Data Worksheet.

Experimental interpretation

Connect the trend to the research question

Use the regression equation, direction, strength, anomalies, and experimental limitations when describing the evidence.

Follow the Experimental Results Analysis Guide for a complete interpretation workflow.

Questions and answers

Linear regression FAQ

What does the slope represent?

The slope represents the predicted change in y for each one-unit increase in x.

What does the intercept represent?

The intercept is the predicted y value when x equals zero, although it may not always have a meaningful experimental interpretation.

What does the correlation coefficient mean?

The correlation coefficient r describes the direction and strength of a linear relationship, with values closer to minus one or plus one indicating a stronger linear association.

What does R squared mean?

R squared is the proportion of variation in y explained by the fitted linear model.

Accuracy and transparency

Created and maintained by our editorial team

This laboratory calculator is maintained by the Science Lab Tools Editorial Team. Its calculation logic is tested with representative inputs, while the supporting guidance is checked for formula clarity, units, assumptions, and common mistakes.

Learn more about our formula-review and correction process, or read about Science Lab Tools.

  • Calculation logic tested
  • Variables and units explained
  • Assumptions stated clearly
  • Corrections handled transparently