Linear Regression Calculator: Least-Squares Line, r, R^2

Linear Regression Calculator

Fit the least-squares best-fit line y = mx + b to your paired (x, y) data. Get the slope, intercept, correlation coefficient r, R-squared, a full computation table, residuals, and a predicted Y for any X you choose.

📈Real Data Presets

📝Enter Your (x, y) Data

The predictor variable. Example: study hours, temperature, ad spend.

The outcome variable. Each Y pairs with the X in the same position.

Estimates y-hat = m × X + b at your chosen X.

Best-fit equation y = mx + b least-squares line
Slope (m) 0 change in y per unit x
Correlation (r) 0 strength and direction
R-squared 0 variance explained

🔢Formula Snapshot

nData pairs
mSlope
bIntercept
r squared

🧮Least-Squares Computation Table

#xyx × y
Enter X and Y data above to build the computation table.

📏Residuals Table

#xy actualy predictedresidualresidual²
Residuals appear after calculation.

📊Correlation Strength Reference

|r| RangeStrengthR-squared RangeInterpretation
0.90 – 1.00Very strong0.81 – 1.00Points hug the line; predictions are reliable
0.70 – 0.89Strong0.49 – 0.79Clear trend with modest scatter around the line
0.40 – 0.69Moderate0.16 – 0.47Real but loose relationship; use with caution
0.20 – 0.39Weak0.04 – 0.15Faint pattern; the line explains little variance
0.00 – 0.19Negligible0.00 – 0.03Essentially no linear link between x and y

🗂Regression Scenario Comparison

ScenarioX VariableY VariableExpected SlopeTypical rUse Case
Study timeHours studiedExam scorePositive0.85 to 0.95Predict grades from effort
Retail seasonalityTemperatureCold drink salesPositive0.80 to 0.97Plan inventory by weather
Growth chartHeightWeightPositive0.70 to 0.90Screen for healthy ranges
MarketingAd spendRevenuePositive0.60 to 0.90Estimate return on spend
EconomicsPriceQuantity demandedNegative-0.70 to -0.95Model a demand curve
CareersYears experienceSalaryPositive0.65 to 0.90Benchmark pay by tenure

Full Formula Breakdown

Data pairsEach observation is a pair (x, y). You need at least 2 valid pairs and X values that are not all identical.
Required sumsSx = Σx, Sy = Σy, Sxy = Σ(x×y), Sxx = Σx², Syy = Σy², over all n pairs.
Slope mm = (n·Sxy – Sx·Sy) / (n·Sxx – Sx²). It is the rise in y for a one-unit rise in x.
Intercept bb = (Sy – m·Sx) / n. This is the predicted y when x = 0, and the line passes through the point (mean x, mean y).
Correlation rr = (n·Sxy – Sx·Sy) / √((n·Sxx – Sx²)·(n·Syy – Sy²)). It ranges from –1 to +1.
R-squaredR² = r². It is the share of the variance in y that the fitted line explains, from 0 to 1.
PredictionFor any X, the predicted value is y-hat = m×X + b. The residual for a point is y – y-hat.

📘Regression Terms Glossary

TermSymbolMeaningRange or Units
SlopemSteepness of the fitted lineAny real number
InterceptbPredicted y when x = 0Any real number
CorrelationrStrength and direction of linear link–1 to +1
Coefficient of determinationVariance in y explained by the line0 to 1
Predicted valuey-hatEstimate from the line at a given xSame units as y
ResidualeActual y minus predicted ySame units as y
Sum of squared residualsSSETotal squared prediction errorMinimized by least squares

💡Practical Regression Tips

Correlation vs cause: A high r shows x and y move together, not that one causes the other. A hidden third variable can drive both, so confirm the mechanism before acting.
Mind the range: The line is only trustworthy near the x values you measured. Predicting far outside that range (extrapolation) can give misleading y-hat values.

You have some numbers paired together (like ad spending vs. Revenue) or other things like time studied vs. It is a test score. And you want to know if there’s a pattern in the data.

Well, linear regression can help you figure out that pattern. Not magic, mind you, just pretty good for most practical applications. It fits a line to your data so that the sum of squares of differences between observed points and predicted values is minimized. This is known as least-squares line. It also provides an equation describing relationship between one variable and another.

What Is Linear Regression?

From this, you derive the slope and intercept. The former indicate how fast the variable changes; the latter pins down where on the x-axis the line hits the y-axis. But the true value is knowing what these numbers tell you about your own circumstance.

But slope, how much one variable change for every one-unit change in the other, is usually the simplest to grasp. More study time? Better grades? That’s the expectation with a positive slope. But a negative slope reverses everything. Price down = Demand up? Those are healthy signs in any economy. Your job is to know how to interpret the direction, something the calculator figure out from the algebra for you. One mistake people make all the time here: they get the sign backward and draw incorrect conclusions.

And then there’s r, or the correlation coefficient. This represents the degree to which points group along best-fit line. R can range between -1 to 1. It doesn’t say whether one thing causes another; it indicates that when this happens, that also happens. And that difference matter much more than many think. Both shark attacks and ice cream sales increase in July, for instance, but sharks don’t flock for cones.

(The page has a handy chart classifying correlations by strength, and a reminder that even with a weak correlation, you explain only a small amount of the variance in your results.) That’s where R-squared comes into play. It extends that correlation with a measure of explained variance as a percent. So if an R-squared is one, it’s a perfect fit (with all points lying on the curve), and if it’s zero, it’s completely useless for predicting anything. In reality, most business data don’t look like that. The trend is there, but it’s muddied by other factors, and most business metric hover somewhere in the middle, moderately predicted. What matters then is not just understanding the trend itself, but knowing what kind of error to anticipate… So you can have confidence in your prediction.

You’ll notice the error spelled out in form of residuals. Residuals are simply the difference between what the model predicted and what actualy occurred. These should appears random with no obvious patterns present. This indicates a good model. Perhaps the linear assumption was incorrect from the beginning if you observe a pattern (e.g., a curve) when looking at the residuals. You can check for this by inspecting the residual table. It’s worth taking a moment to go through it… Don’t just glance at the final equation.

In most cases, it’s all about prediction. With the line, you’re able to predict a Y value given a new X input. Within your range of initial data points, that works fine. But if you guess way out into places where you haven’t seen anything happen, where the trend bends and breaks at extremes… That becomes dicey. You can put a particular X value into the tool and get an estimate of how it would of work. That’s useful for rapid scenario planning.

Linear regression boils down complexity while keeping its truth. You get a line through a cloudy dot plot. Clarity from scatter. It is a tool for spotting trends, checking assumptions, and making an educated guess. But remember: it’s just a line. It is a moddern model, not a law of nature. All the messy details remain in the data, none of which any equation can ever fully include.

Linear Regression Calculator: Least-Squares Line, r, R^2