Linear Regression Calculator

Paste an X and a Y column to fit a simple linear regression. You get the equation, slope and intercept with standard errors, t and p values, R², adjusted R², the F test, residual standard error, a scatter plot with the fitted line, and an APA 7 sentence — all computed in your browser.

Results
StatisticValue
Slope1.50
Intercept0.67
R².96
Adj. R².93
p-value0.121

APA report

y = 0.67 + 1.50x. F(1, 1) = 27.00, p = .121, R² = .96

Have full study data?

Upload your dataset and generate a complete paper draft with statistics, figures, and references—free preview.

Generate paper

How to use the regression calculator

1. **Enter X and Y.** X is the predictor (independent variable), Y is the outcome (dependent variable). Paste two columns from a spreadsheet, type comma- or space-separated values, or load a CSV and choose the columns. 2. **Check n.** Rows with a missing X or Y are dropped; the calculator shows how many complete pairs it used. You need at least 3. 3. **Read the coefficient table.** For both the intercept and the slope you get the estimate, standard error, t statistic and two-sided p-value. 4. **Read the model summary.** R², adjusted R², residual standard error, and the F statistic with its p-value. 5. **Check the plot.** The scatter plot with the fitted line shows whether a straight line is a sensible description of your data. 6. **Copy the APA 7 sentence** and the regression equation into your write-up.

No data leaves your device: the calculation runs entirely in the browser.

What simple linear regression does

Simple linear regression fits the straight line `ŷ = b0 + b1·x` that minimises the sum of squared vertical distances between the observed Y values and the line (ordinary least squares, OLS).

  • The **slope b1** is the expected change in Y for a one-unit increase in X.
  • The **intercept b0** is the predicted Y when X = 0. It is only meaningful if X = 0 is a realistic value.
  • **R²** is the proportion of the variance in Y explained by X.

Use it when you want to **predict** an outcome from one predictor or **quantify** how much Y changes per unit of X — for example, how much weekly sales rise for every extra $1,000 of advertising, or how blood pressure changes with age. If you only want to know how strongly two variables move together, without a direction of prediction, the [correlation calculator](/tools/correlation-calculator) is the better fit. With two or more predictors you need multiple regression, which this page does not cover.

Assumptions (LINE)

  • **Linearity:** the mean of Y changes linearly with X. Look at the scatter plot; a curve means a straight line is the wrong model.
  • **Independence:** residuals are independent of each other. Repeated measurements on the same people, or time series data, usually violate this.
  • **Normality:** residuals are approximately normally distributed. This matters mostly for p-values and confidence intervals in small samples.
  • **Equal variance (homoscedasticity):** the spread of residuals is roughly constant across X. A funnel shape in the plot signals a problem.

Also watch for **influential points**: a single observation far from the others in X can pull the line toward itself and change the slope substantially.

Formulas

Slope and intercept (OLS):

`b1 = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)²`

`b0 = ȳ − b1·x̄`

Residual standard error, with df = n − 2:

`s = √[ Σ(y − ŷ)² / (n − 2) ]`

Standard errors and t tests:

`SE(b1) = s / √Σ(x − x̄)²`, `t = b1 / SE(b1)`

`SE(b0) = s · √[ 1/n + x̄² / Σ(x − x̄)² ]`, `t = b0 / SE(b0)`

Goodness of fit:

`R² = 1 − SS_res / SS_tot`, `adjusted R² = 1 − (1 − R²)(n − 1)/(n − 2)`

`F = (SS_reg / 1) / (SS_res / (n − 2))`, with df = (1, n − 2). In simple regression `F = t²` for the slope, so both give the same p-value.

Worked example

A small shop records weekly advertising spend (X, in $1,000) and weekly sales (Y, in $1,000) for ten weeks:

| Week | Ad spend X | Sales Y | |---|---|---| | 1 | 1 | 12 | | 2 | 2 | 15 | | 3 | 3 | 14 | | 4 | 4 | 19 | | 5 | 5 | 21 | | 6 | 6 | 20 | | 7 | 7 | 25 | | 8 | 8 | 27 | | 9 | 9 | 26 | | 10 | 10 | 31 |

Results (verified with Python and SciPy):

  • Equation: **ŷ = 10.00 + 2.00·x**
  • Slope b1 = 2.00, SE = 0.165, t(8) = 12.11, **p < .001**; 95% CI [1.62, 2.38]
  • Intercept b0 = 10.00, SE = 1.025, t(8) = 9.76, p < .001
  • **R² = .948**, adjusted R² = .942
  • Residual standard error = 1.50
  • **F(1, 8) = 146.67, p < .001**

Each additional $1,000 of advertising is associated with about $2,000 more weekly sales, and advertising explains about 95% of the week-to-week variation in sales in this sample. The predicted sales for a $6,500 week are 10 + 2 × 6.5 = 23, i.e. $23,000. Predicting for $12,000 (outside the observed 1–10 range) would be extrapolation — see the common mistakes below.

Interpreting the output

  • **Slope and its p-value:** the test of H0: b1 = 0 tells you whether there is evidence of a linear relationship. Report the confidence interval for the slope too; it shows the plausible range of the effect.
  • **Intercept:** often not of substantive interest. Its p-value only tests whether the predicted Y at X = 0 is zero.
  • **R² vs adjusted R²:** R² never decreases when predictors are added; adjusted R² penalises model size. With a single predictor they are close unless n is small.
  • **Residual standard error:** the typical size of a prediction error, in the units of Y. Here, predictions miss by about 1.5 ($1,500) on average.
  • **F test:** with one predictor it is equivalent to the slope t test.

A high R² does not prove the model is correct, and a low R² does not mean the slope is unimportant — check the residual pattern and the size of the slope.

Reporting the regression in APA 7 style

State the predictor and outcome, the slope (b, or β if standardised) with its test, and the overall model fit:

> A simple linear regression showed that advertising spend significantly predicted weekly sales, *b* = 2.00, *SE* = 0.17, *t*(8) = 12.11, *p* < .001, 95% CI [1.62, 2.38]. The model explained 94.8% of the variance in sales, *R*² = .95, *F*(1, 8) = 146.67, *p* < .001.

Include the regression equation if the paper uses it for prediction. R² is written without a leading zero because it cannot exceed 1.

If your dataset has many variables and you need the whole paper rather than one result, Data2Paper's [Generate Paper](/generate-paper) runs the analysis and writes a complete draft from your CSV or Excel file, with a free preview of the first half.

Common mistakes

  • **Extrapolating** beyond the range of X you observed. The line may not hold there.
  • **Reading causation into the slope.** Observational data shows association; a causal claim needs a design that supports it.
  • **Ignoring the residual plot.** Curvature or a funnel shape means p-values and CIs can be misleading.
  • **Interpreting a meaningless intercept**, such as the predicted weight of a person with height 0.
  • **Swapping X and Y.** Regressing Y on X and X on Y give different lines; choose based on your research question.
  • **Letting one outlier drive the result.** Refit without it and report both if it changes the conclusion.
  • **Using simple regression when you need to control for other variables.** Then you need multiple regression.

FAQ

Related calculators