Linear Regression Calculator
A free tool by DeepRit, a Google Ads agency that does PPC and nothing else. We build and run Google Ads accounts so every click is accounted for. Book a free audit call
Free linear regression calculator. Find the least-squares line of best fit (y = a + bx), R², the standard error and predictions, with a residuals table.
- Slope (b)
- 0
- Intercept (a)
- 0
- R²
- 0
- Standard error
- 0
- Prediction
- 0
Free, no sign-up. Runs in your browser: nothing you type is uploaded or saved.
How to use the linear regression calculator
- Paste the X values (the independent variable, the one you think influences the other).
- Paste the Y values (the dependent variable), in the same order.
- Enter an X value to predict (optional).
- Read the results. The linear regression calculator shows the equation of the line of best fit, the slope and intercept, R², the standard error, a prediction, and a table of predicted values and residuals.
You need at least three pairs of values. Paste columns directly from a spreadsheet if you like.
What is linear regression?
Simple linear regression finds the straight line that best describes how Y changes with X:
ŷ = a + bx
- b (slope): how much Y changes, on average, for each one-unit increase in X.
- a (intercept): the predicted value of Y when X is 0.
- ŷ ("y-hat"): the predicted value of Y.
The "best" line is found by the least squares method: it minimises the sum of the squared vertical distances (residuals) between the data points and the line.
The formulas
b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²
a = ȳ − b × x̄
For X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5: x̄ = 3, ȳ = 4, Σ(x − x̄)(y − ȳ) = 6, Σ(x − x̄)² = 10.
- b = 6 ÷ 10 = 0.6
- a = 4 − 0.6 × 3 = 2.2
- Line: ŷ = 2.2 + 0.6x
R²: how well does the line fit?
R² = 1 − (sum of squared residuals ÷ total sum of squares)
R² is the share of the variation in Y explained by the line, from 0 (no explanatory power) to 1 (a perfect fit). In the example, R² = 0.6: the line explains 60% of the variation in Y. For simple linear regression, R² equals the square of the correlation coefficient r. Our correlation coefficient calculator shows r and tests its significance.
Standard error of the estimate
The standard error (also called the residual standard error) is the typical size of the residuals:
SE = √(Σ residuals² ÷ (n − 2))
It's in the same units as Y. A smaller standard error means points sit closer to the line, and predictions are more precise.
Residuals
A residual is the difference between an actual value and the predicted value: y − ŷ. The calculator lists them for each point. Looking at residuals helps you check whether a straight line is appropriate:
- Random scatter around zero suggests a linear model is reasonable.
- A curved pattern suggests the relationship isn't linear.
- A funnel shape (residuals growing with X) suggests the variability changes, which affects the reliability of predictions.
- One very large residual may be an outlier worth checking.
Making predictions
Once you have the line, substitute any X to predict Y. With ŷ = 2.2 + 0.6x, at x = 6 the prediction is 2.2 + 3.6 = 5.8.
Be careful with extrapolation: predicting far outside the range of your data assumes the straight-line pattern continues, which often isn't true. A line fitted to children's heights from age 5 to 12 would predict absurd adult heights if extended to age 40.
Assumptions of linear regression
For reliable results, especially when using statistical tests:
- Linearity: the relationship between X and Y is roughly straight.
- Independence: observations don't influence each other.
- Constant variance: the spread of residuals is similar across X values.
- Normal residuals: residuals are roughly normally distributed (important for confidence intervals and tests).
Real data rarely meets these perfectly, but large violations can make conclusions misleading.
Regression and correlation
Correlation measures the strength of a linear relationship; regression describes the relationship with an equation you can use for prediction. Both are sensitive to outliers, and neither proves causation.
Real-world uses
- Sales forecasting: predicting sales from ad spend, price or seasonality.
- Cost estimation: relating costs to output, such as delivery cost to distance.
- Science: calibration curves, growth rates and dose responses.
- Economics and finance: trends, beta of a stock, and relationships between economic indicators.
- Health: relationships between measurements such as height and weight.
In spreadsheets, =SLOPE(), =INTERCEPT(), =RSQ() and =FORECAST.LINEAR() give the same results as the linear regression calculator.
A worked example
Jordan tracks weekly ad spend (X, in hundreds) and sales (Y, in hundreds) for eight weeks:
- X: 1, 2, 3, 4, 5, 6, 7, 8
- Y: 52, 55, 61, 60, 68, 70, 75, 79
In the linear regression calculator: ŷ = 47.64 + 3.86x, with R² = 0.976 and a standard error of about 1.59. Each extra 100 spent on ads is associated with about 386 more in sales.
For a planned spend of 10 (1,000), the prediction is 47.64 + 38.57 ≈ 86.2, about 8,620 in sales. Because 10 is outside the range of the data, Jordan treats this as a rough guide and plans to test it.
Who uses a linear regression calculator
Students use it in statistics, economics and science courses. Analysts and marketers use it to find relationships and forecast. Scientists use it for calibration and experiments. Small business owners use it to understand how costs and sales relate to what they do.
Need more customers from Google?
This tool is free and runs in your browser. If your business also needs more leads or sales, Google Ads is where people search with their wallet out. DeepRit is a Google Ads agency that does PPC and nothing else: we build the campaigns, block the searches that waste money, write the ads, set up conversion tracking and send you a short report every week. Request a free PPC audit and we will show you, in dollars, what we would fix first.
Interpreting the slope and intercept
The slope tells you how much y changes, on average, for each one-unit increase in x. If a regression of monthly sales on advertising spend has a slope of 4.2, each extra unit spent on advertising goes with about 4.2 extra units of sales, on average, within the range of the data. The intercept is the predicted value of y when x is zero. Sometimes that's meaningful, such as baseline sales with no advertising. Sometimes it isn't, such as the predicted weight of a person with zero height. Don't over-interpret the intercept when x = 0 lies far outside your data.
Extrapolation is risky
A regression line describes the relationship within the range of your data. Using it far outside that range, called extrapolation, can give nonsense. A line fitted to children's heights between ages 2 and 12 would predict that a 40-year-old is over 3 metres tall, because growth doesn't continue in a straight line. The linear regression calculator will happily predict any x you enter, so it's up to you to keep predictions close to the data you used.
Checking the residuals
Residuals are the differences between the actual y values and the values the line predicts. If the line is a good model, the residuals should look like random scatter around zero, with no clear pattern. A curved pattern in the residuals suggests the true relationship is curved, not straight. A funnel shape, where residuals spread out as x grows, suggests the variability changes with x. Plotting the residuals is one of the quickest ways to check whether a straight line is the right model.
Transforming data
Some relationships become linear after a simple transformation. Exponential growth, such as compound interest or bacterial growth, becomes a straight line if you take the logarithm of y. Many relationships in economics and biology follow power laws, which become straight lines when you take the logarithm of both x and y. Transform the data first, enter the transformed values in the linear regression calculator, and remember to transform the predictions back afterwards.
Simple versus multiple regression
The linear regression calculator fits a line with one predictor, which is called simple linear regression. In practice, outcomes often depend on several factors at once. House prices depend on size, location, age and condition. Multiple regression extends the same least-squares idea to several predictors, and needs statistical software. Simple regression is still the best place to start: it's easy to understand, easy to plot and often reveals the main relationship clearly.
Which variable is x?
Put the variable you want to predict on the y side and the variable you'll predict from on the x side. Swapping them gives a different line, not just the same line flipped, because least squares minimises vertical distances only.
Sources and further reading
- Simple linear regression on Wikipedia: formulas and interpretation.
- Least squares on Wikipedia: the method behind the line of best fit.
- NIST/SEMATECH: e-Handbook of Statistical Methods, including regression diagnostics.
Frequently asked questions
How do I find the line of best fit?
Use least squares: slope b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², intercept a = ȳ − b x̄.
What does R² mean in regression?
The share of the variation in Y explained by the line, from 0 to 1.
What is a residual?
The difference between an actual value and the value predicted by the line.
Can I use the line to predict outside my data?
You can, but extrapolation is risky because the relationship may not continue.
Is regression the same as correlation?
No. Correlation measures strength; regression gives an equation for prediction.
Is the linear regression calculator free?
Yes. It's free, needs no sign-up, and works in your browser.
Free PPC audit
See where your ad budget leaks.
We look at your Google Ads account before the call, then walk you through what we'd fix first, in dollars. No obligation, no hard sell.