keencalculator
  1. Home
  2. Statistics
  3. Linear Regression Calculator

Linear Regression Calculator

Fit a straight line through paired data by least squares. Enter X and Y values to get the regression equation, slope, intercept, correlation and r², and enter any x to get a predicted y from the line.

Quick examples

Separate with commas or spaces.

Same number of values as X, in matching order.

Your numbers stay in your browser. They are never uploaded.
Regression liney = 0.6x + 2.2
Slope (m)
0.6
Intercept (b)
2.2
Predicted y
5.8
Correlation (r)
0.7746
r²
0.6

Saved setups

Save a set of inputs you reuse — your usual rate, your loan, your room sizes — and load it back in one tap.

    Your recent calculations

    Results you calculate here are kept on this device so you can come back to them.

      Also free on iPhone and Mac

      Formula

      Slope m = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²
      Intercept b = ȳ − m × x̄
      Predicted y = m × x + b

      How to use it

      1. Type the X values, separated by commas.
      2. Type the Y values in the same order, one for each X.
      3. Read the regression line.
      4. Enter an x value to get a prediction.

      Worked examples

      X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5, predicting at x = 6

      Regression line
      y = 0.6x + 2.2
      Slope (m)
      0.6
      Intercept (b)
      2.2
      Predicted y
      5.8
      r²
      0.6

      Units sold at a price of 10

      Regression line
      y = -12.3x + 180.9
      Slope (m)
      -12.3
      Intercept (b)
      180.9
      Predicted y
      57.9

      A worked example

      For X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5 the means are 3 and 4. The products of the deviations sum to 6 and the squared X deviations sum to 10, so the slope is 0.6. The intercept is 4 − 0.6 × 3 = 2.2, giving y = 0.6x + 2.2. At x = 6 the line predicts 5.8.

      Using the line sensibly

      The slope is the average change in Y for a one-unit rise in X. Least squares picks the line that makes the sum of the squared vertical distances from the points as small as possible.

      r² shows how well the line fits: 0.6 means the line accounts for 60% of the variation in Y. Predictions are most reliable inside the range of your X values; far outside it, nothing guarantees the trend continues. In Excel and Google Sheets the functions are SLOPE and INTERCEPT.

      Questions people ask

      What is the regression line for X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5?

      y = 0.6x + 2.2, with r² = 0.6.

      How do I predict a value with the regression line?

      Substitute x into the equation. With y = 0.6x + 2.2, x = 6 gives 0.6 × 6 + 2.2 = 5.8.

      What does the slope mean?

      It is how much Y changes, on average, when X goes up by one. A slope of −12.3 for price against units sold means each extra dollar of price costs about 12.3 units.

      Keep exploring