What this calculator does
Simple linear regression fits a straight line through a set of (X, Y) pairs so that you can describe how Y changes when X changes, and predict Y for a value of X you have not observed. The calculator uses ordinary least squares: it picks the line that makes the sum of squared vertical distances between the points and the line as small as possible.
You get the fitted equation, how well the line fits (R² and the standard error of the estimate), whether the slope is statistically different from zero (t-test and p-value), confidence intervals for both coefficients, an ANOVA table with the F-test, and a residual plot for checking assumptions.
How to use it
- Put your predictor in one column and your outcome in the next, in Excel, Google Sheets or a CSV file.
- Select both columns, copy, and paste into the box above. Include the header row if you want the variable names carried through.
- Press Calculate. Use the tabs to switch between the chart, residuals, coefficient table, ANOVA table and the fitted values.
- Enter a new X in the Predict box to get a predicted Y with its confidence and prediction intervals.
The formulas behind the line
The fitted line has the form
The slope and intercept come from the means of X and Y and two sums of squares:
b₁ = Sxy / Sxx · b₀ = ȳ − b₁x̄
Fit is measured from the residuals, the gaps e = y − ŷ between each actual value and the line. The sum of squared residuals (SSE) and the total variation in Y (SST) give
The slope’s t statistic is b₁ / SE(b₁), tested on n − 2 degrees of freedom. Open Show the working under any result to see each of these numbers for your own data.
Worked example: does ad spend move online sales?
Press Load example to use this data. A Bengaluru D2C brand recorded its monthly digital ad spend and its online sales for 12 months, both in ₹ lakh. Spend ranged from ₹1.2 lakh to ₹5.8 lakh.
- Equation: Sales = 5.423 + 3.557 × Ad spend. Each extra ₹1 lakh of ad spend is associated with about ₹3.56 lakh more in sales, with a 95% confidence interval of ₹3.09 lakh to ₹4.02 lakh.
- Fit: R² = 0.9665, so ad spend explains about 96.7% of the month-to-month variation in sales. The typical miss (standard error of the estimate) is about ₹1.01 lakh.
- Significance: the slope’s p-value is below 0.0001, so a relationship this strong is very unlikely to be chance.
- Prediction: at ₹4.5 lakh of spend the model predicts ₹21.43 lakh of sales. The 95% prediction interval for a single month is ₹19.03 lakh to ₹23.83 lakh.
Two cautions apply. The data is observational, so other things that rose with ad spend (a festive season, a price cut) may be doing part of the work. And predicting for spend well outside ₹1.2 to ₹5.8 lakh is extrapolation: nothing in this data says the straight line holds at ₹15 lakh.
Checking the assumptions
The p-values and intervals are only trustworthy if the data roughly meets four conditions:
- Linearity: the relationship is a straight line, not a curve. A curved pattern in the residual plot says otherwise.
- Independence: each observation is separate. Monthly or daily data often breaks this, because one period affects the next.
- Constant variance: residuals spread out evenly across the fitted values. A funnel shape means the error grows with Y.
- Roughly normal errors: matters most for small samples. A few extreme residuals can distort the slope and its p-value.
The residual tab is the quickest check. For a fuller treatment, with tests and fixes for each violation, see the chapter on regression assumptions and diagnostics.
Getting the same result in Excel and Python
In Excel, =SLOPE(B2:B13, A2:A13), =INTERCEPT(B2:B13, A2:A13) and
=RSQ(B2:B13, A2:A13) return the slope, intercept and R². =LINEST(B2:B13, A2:A13, TRUE, TRUE)
returns the full table including standard errors. In Python:
import statsmodels.api as sm
x = [1.2, 1.8, 2.0, 2.5, 2.9, 3.1, 3.6, 4.0, 4.4, 4.9, 5.3, 5.8]
y = [9.8, 12.1, 11.4, 14.9, 15.2, 17.8, 16.9, 20.3, 21.0, 22.6, 25.9, 24.8]
model = sm.OLS(y, sm.add_constant(x)).fit()
print(model.summary()) # same coefficients, R², t and p as the calculator
Common mistakes
- Swapping X and Y. Regressing sales on ad spend is not the same model as regressing ad spend on sales. Put the variable you want to predict in the second column.
- Reading R² as accuracy. A high R² says the line follows the points closely. It says nothing about whether X causes Y, and a low R² can still come with a real, useful slope.
- Ignoring outliers. One extreme point can tilt the whole line. Check the fitted values tab for unusually large residuals before you trust the slope.