Linear Regression Calculator

Read the Theory Guide →

Enter paired X and Y values, choose a Target X, and fit a straight line to the data. The solver shows the means, deviations, slope, and intercept before using the fitted line to predict Y. Edit the data or Target X and recalculate to see how the result changes.

What You Can Explore

  • Edit the X and Y values in the table, and add or remove data rows. The values must be numeric.
  • Set the Target X at the bottom of the table to choose where you want the fitted line to make a prediction.
  • Press Calculate Regression Line to generate the fitted line and see the calculations behind its slope and intercept.
  • Follow the solution from the means and deviations to the final equation, then see your Target X substituted into the line.
Core Mechanics
▼
  • The Best-Fit Line: The model finds the single straight line that sits as close as possible to all your data points. It is defined by the intercept (β0\beta_0) and the slope (β1\beta_1).
  • Prediction via Interpolation: To make a prediction for any new input (xx), you simply plug it into the equation of the line. The model effectively treats the line as its "memory" of the data trend.
  • The Slope Meaning: The coefficient (β1\beta_1) is the "rate of change." For every one-unit increase in your input (xx), your predicted output (y^\hat{y}) changes by exactly β1\beta_1 units.
  • The Linearity Trap: This model assumes the world is a straight line. If your real-world data curves or changes direction, this model will fail. No amount of extra data can fix a structural mismatch!
Initializing Workspace...

Understanding Your Result

The fitted line and prediction come from the data and Target X you entered. The solver first finds the means of X and Y, measures how each value differs from those means, and uses those deviations to calculate the slope and intercept. The resulting line is then evaluated at your Target X.

  • Predicted Value (Y) is the value given by the fitted line at your Target X. Step 5 shows the substitution so you can follow how the final number was obtained.
  • The slope tells you how much the predicted Y changes when X increases by one unit. A positive slope means the line rises as X increases, while a negative slope means it falls.
  • The intercept is the line's predicted Y value when X is 0. It may not have a useful real-world meaning if X = 0 is outside the situation represented by your data.
  • All data rows contribute to the fitted line. After changing a row, compare the means, deviation totals, and coefficients to see how that one change affected the result.

Try These Experiments

Shift Every Y Value

Setup: Run the preloaded data first. Note the mean of Y (54), the slope (17), the intercept (3), and the prediction of 105 at Target X = 6.

Action: Add 10 to every Y value, changing 20 to 30, 40 to 50, and so on. Then press Calculate Regression Line again.

What to Observe: The slope remains 17 and the deviation values stay unchanged. The mean of Y becomes 64, the intercept becomes 13, and the prediction at X = 6 becomes 115.

Takeaway: Adding the same amount to every Y value moves the whole line up without changing its slope. The relationship between X and Y stays the same; only the overall Y level has shifted.

Predict at the Mean of X

Setup: Run the preloaded data with Target X = 6. Step 1 shows a mean of X of 3 and a mean of Y of 54.

Action: Change the Target X from 6 to 3, which is the mean of X, and press Calculate Regression Line again.

What to Observe: The predicted Y becomes 54, exactly matching the mean of Y. The fitted line itself does not change and remains Y = 17X + 3.

Takeaway: The fitted regression line passes through the point formed by the two means, (mean X, mean Y). So when you predict at the mean of X, the prediction is the mean of Y.

Add a Far-Right Point

Setup: Run the preloaded data and note the slope of 17. The existing X values range only from 1 to 5.

Action: Add a sixth row with X = 15 and Y = 20, leave the other rows unchanged, and calculate the regression line again.

What to Observe: The mean of X moves to 5, the slope falls from 17 to -1.308, and the prediction at Target X = 6 drops from 105 to 47.026.

Takeaway: A point far from the other X values can have a strong effect on the fitted line. One unusual data point can change both the direction and the prediction of the regression line, so check extreme values before interpreting the trend.