Linear Regression Calculator

Paste paired X and Y values to find the least-squares line, slope, intercept, and R². See the scatter plot and predict Y at any X.

Enter one pair per line. Separate X and Y with a tab, space, or semicolon. A comma also works in languages that use a decimal point.

Line of best fit

ŷ = 1.7x + 1.5

Slope
1.7
Y-intercept
1.5
R²
0.9796610169
ObservationsFitted line

Predict Y

Predicted Y8.3

Fit a line to paired data

Paste two spreadsheet columns into X and Y data, with X first and Y second. Use one pair per line. A tab, space, or semicolon can separate the two values. Skip the column headings. X is the predictor and Y is the response.

The sample uses the pairs (1, 3), (2, 5), (3, 7), and (4, 8). Their least-squares line is ŷ = 1.7x + 1.5. The slope of 1.7 means the fitted Y increases by 1.7 units per unit of X. The Y-intercept of 1.5 is the fitted value at X = 0.

Read the fit and scatter plot

Ordinary least squares chooses the line that minimizes the sum of squared vertical residuals. A residual is an observed Y minus its fitted value. The scatter plot shows the observations and the fitted line over the observed X range. Look at both to see how closely the points follow a line.

R² is the fraction of the observed variation in Y explained by the fitted line with an intercept. The example has an R² of about 0.98. If every Y value is the same, the fitted line is horizontal and R² is undefined. If every X is the same, there is no unique regression line of this form.

Predict a Y value

Enter an X value to evaluate the fitted line. With X = 4, the example gives a predicted Y of 8.3. The observed value there is 8, so its residual is −0.3. A prediction outside the observed X range is extrapolation and may be less reliable.

Show more related tools