Advertisement

📈 Regression Calculator

Fit a least-squares line to paired data: slope, intercept, R², predicted y, and residual context.

Linear Regression — Predict y from x with a Line

BrainyCalculators editorial insight — unique to this tool

Simple linear regression fits ŷ = mx + b to minimize squared errors — a SaaS founder might regress monthly ad spend (x) on new signups (y) to forecast next quarter. R² tells you what fraction of variance in y is explained by x; R² = 0.72 means 72% of signup swings track spend linearly. Regression extends correlation by giving intercept, slope, and point predictions, not just strength.

When to use this calculator

Use when you need to predict or interpolate one variable from another and assume a linear relationship. For only measuring association strength, Correlation is enough.

Reference Value Context
Slope m Δy per unit Δx Interpretation key
R² = 0.80 80% explained Good fit heuristic
Residual check Pattern in errors Linearity assumption
Extrapolation risk Outside data range Often unreliable

Not what you need? For curved relationships, simple linear regression misleads — consider polynomial tools. For r without prediction, use Correlation.

Only measuring association, not fitting a line?

This page fits a regression line. For correlation coefficient without prediction, use the Correlation Calculator →

What is Linear Regression?

Linear regression fits y = mx + b to a set of (x, y) points by minimizing squared errors. It outputs slope, intercept, correlation strength, and predicted values for new x.

Use this page when you have two numeric columns and want a predictive line. It models trend; it does not merely report whether two variables move together without a line fit.

For Pearson correlation without fitting a line, use the Correlation Calculator. For slope between exactly two points, use the Slope Calculator.

Linear Regression Formulas

Slope
m = [n Σxy − (Σx)(Σy)] / [n Σx² − (Σx)²]
Intercept
b = (Σy − m × Σx) / n
R² (coefficient of determination)
R² = 1 − SSR / SST

How to Use Linear Regression

  1. 1
    Enter Paired Data
    Input X values (independent variable) and corresponding Y values (dependent variable) in comma-separated format.
  2. 2
    Review the Equation
    The regression line y = mx + b gives you the best linear fit. m is the slope (rate of change) and b is where the line crosses the Y axis.
  3. 3
    Evaluate R²
    R² ranges from 0 to 1. Higher values mean the line explains more of the variance in Y. An R² of 0.9 means 90% of variation is captured.
  4. 4
    Make Predictions
    Enter any X value in the prediction box to calculate the expected Y using y = mx + b. Only interpolate within your data range for reliable predictions.

Worked Example

X = 1, 2, 3, 4, 5 — Y = 2, 4, 5, 4, 5

n=5 | Σx=15 | Σy=20 | Σxy=64 | Σx²=55
m = [5×64 − 15×20] / [5×55 − 15²] = 20/50 = 0.4
b = (20 − 0.4×15) / 5 = (20 − 6) / 5 = 2.8
Equation: y = 0.4x + 2.8
Predict x=6: y = 0.4×6 + 2.8 = 5.2

How the Regression Calculator Works

Formula, assumptions, and calculation steps for this statistics tool.

Formula Used

y = mx + b, where m = covariance(x, y) / variance(x)

Methodology

Statistics calculators organize sample data, apply the selected descriptive or inferential formula, and report the statistic with interpretation.

Calculation Steps

  1. Enter raw values or summary statistics.
  2. Clean separators and count the sample size.
  3. Apply the relevant statistic, probability, or confidence formula.
  4. Display the result with context such as degrees of freedom, percentile, or strength.

Assumptions and Limits

  • Samples should be representative of the population being studied.
  • Normality or independence assumptions apply only where the selected method requires them.
  • Rounded results may differ slightly from spreadsheet software.

Frequently Asked Questions

Linear regression finds the best-fit straight line through a set of data points, described by y = mx + b. It minimises the sum of squared differences between observed Y values and the predicted values on the line.

The slope (m) represents how much Y changes for a one-unit increase in X. A slope of 2 means every time X goes up by 1, Y is expected to go up by 2.

R² (coefficient of determination) is the proportion of variance in Y explained by X. R²=0.8 means 80% of the variation in Y is captured by the linear model. R²=1 is a perfect fit.

Substitute your X value into the equation y = mx + b. For reliable predictions, stay within the range of your original data (interpolation). Predictions beyond your data range (extrapolation) are less reliable.

Real-World Applications

🏠
Real Estate Price Prediction
Linear regression models predict residential property values from features like square footage, number of bedrooms, location score, and age — providing appraisers, buyers, and investors with a data-driven baseline estimate. The slope coefficient for square footage estimates the average price premium per additional square foot in the local market.
📈
Sales Forecasting
Businesses model sales revenue as a linear function of advertising spend, economic indicators, or seasonality variables — using historical data to fit the regression line, then projecting future sales based on planned marketing budgets or economic forecasts.
🔬
Scientific Calibration & Measurement
Laboratory instruments are calibrated by regressing instrument readings against known reference standards — determining the slope and intercept that convert raw sensor output to calibrated physical measurements. The linearity of the calibration curve is assessed using R² to validate instrument accuracy.
💊
Dose-Response Analysis
Pharmacologists model drug response (e.g., blood pressure reduction) as a function of dose using linear regression on the linear portion of the dose-response curve — estimating the effective dose range and per-unit response magnitude for clinical dosing guidelines.
Energy Consumption Modelling
Building energy engineers regress energy consumption against outdoor temperature data — the slope gives the temperature sensitivity (kWh per degree), enabling accurate heating and cooling cost predictions, energy efficiency benchmarking, and detection of consumption anomalies suggesting equipment failure.
📊
Economics & Policy Analysis
Economists use regression to estimate relationships like the effect of unemployment on wage growth (Phillips Curve), the income elasticity of consumer spending, or the impact of education on earnings — providing quantitative evidence for policy decisions and academic economic theory.

Common Mistakes

1
Assuming correlation implies causation
Linear regression quantifies the association between variables — it does not establish that x causes y. A strong R² between ice cream sales and drowning deaths (both increase in summer) does not mean ice cream causes drowning; both are driven by temperature. Causal inference requires experimental design, natural experiments, or instrumental variable approaches — not just regression correlation.
2
Not checking the linearity assumption
Linear regression assumes a linear relationship between x and y. Applying a linear model to an inherently non-linear relationship (exponential growth, saturation curves, U-shaped relationships) produces a poorly fitting model and misleading slope estimates. Always plot the data first and examine residual plots — a curved pattern in residuals indicates that the linearity assumption is violated and a transformation or non-linear model is needed.
3
Extrapolating far beyond the range of the data
A regression line is a good approximation within the observed range of x values — but extrapolating predictions far outside this range assumes the linear relationship continues indefinitely, which is rarely true in reality. Predicting house prices for 50,000 sq ft based on a model fitted to 500–4,000 sq ft properties produces nonsensical results because the market dynamics change completely at that scale.
4
Ignoring influential outliers
A single extreme outlier can dramatically shift the slope and intercept of the best-fit line — especially when it occurs at the extremes of the x range (high leverage points). Always examine scatter plots for outliers before fitting regression and consider robust regression methods or outlier investigation when influential points are present.
5
Treating R² as the only measure of model quality
R² measures the proportion of variance in y explained by x — a high R² does not guarantee the model makes accurate predictions, that the relationship is actually linear, or that the model will generalise well to new data. Residual analysis, prediction intervals, cross-validation, and examination of regression assumptions provide a more complete picture of model quality than R² alone.

R² Interpretation Quick Reference

R² Value Interpretation Typical Context
0.0 – 0.2 Very weak / no linear relationship Complex social science data
0.2 – 0.4 Weak relationship Behavioural / economic data
0.4 – 0.7 Moderate relationship Many real-world business problems
0.7 – 0.9 Strong relationship Engineering, physical sciences
0.9 – 1.0 Very strong / near-perfect fit Calibration curves, physical laws

References

  1. Galton, F. "Regression Towards Mediocrity in Hereditary Stature." Journal of the Anthropological Institute, 1886.
  2. Montgomery, D.C. et al. Introduction to Linear Regression Analysis. Wiley, 2012.
  3. James, G. et al. An Introduction to Statistical Learning. Springer, 2021.
  4. Draper, N. and Smith, H. Applied Regression Analysis. Wiley, 1998.
  5. Freedman, D., Pisani, R. and Purves, R. Statistics. W.W. Norton, 2007.