Regression Calculator
Perform linear regression analysis on x,y data. Fits a linear regression model (y = mx + b) to paired x,y data, computing slope, intercept, coefficient of…
Fits a linear regression model (y = mx + b) to paired x,y data, computing slope, intercept, coefficient of determination (R²), and the regression equation.
What Is Linear Regression?
Linear regression fits a straight line y = mx + b to observed (x, y) data by minimizing the sum of squared residuals — the vertical distances between data points and the fitted line. This Ordinary Least Squares (OLS) method produces the best linear unbiased estimator under the Gauss-Markov assumptions.
The slope (m) represents the change in y for a one-unit increase in x. The intercept (b) is the predicted y when x = 0. The coefficient of determination (R²) measures the proportion of variance in y explained by the model, ranging from 0 (no explanatory power) to 1 (perfect fit).
Linear regression assumes a linear relationship, constant variance of residuals (homoscedasticity), independence of observations, and approximately normal residuals. Violation of these assumptions can lead to biased or inefficient estimates.
Formula: y = mx + b m = [nΣxᵢyᵢ − ΣxᵢΣyᵢ] / [nΣxᵢ² − (Σxᵢ)²] b = ȳ − m·x̄ R² = 1 − Σ(yᵢ − ŷᵢ)² / Σ(yᵢ − ȳ)²
Example Calculation
Data: (1,2), (2,4), (3,5), (4,4), (5,5). n=5, Σx=15, Σy=20, Σxy=66, Σx²=55. m = (5×66 − 15×20)/(5×55 − 225) = (330−300)/(275−225) = 30/50 = 0.6. b = 4 − 0.6×3 = 2.2. Equation: y = 0.6x + 2.2. R² = 0.6.
When to Use This Calculator
- A scientist quantifying the relationship between an independent variable and a measured outcome in experimental data
- A business analyst building a simple predictive model to estimate future sales based on advertising spend
- A quality engineer determining the correlation between a process parameter and a product specification through regression
- A student learning regression fundamentals by fitting lines to datasets and interpreting slopes, intercepts, and R-squared values
Common Mistakes to Avoid
- Assuming correlation proves causation — a strong linear relationship between two variables does not prove one causes the other; confounding variables may be responsible
- Extrapolating far beyond the data range — the linear model is only validated within the observed x range; predictions outside this range are unreliable and increasingly inaccurate
- Ignoring residual patterns — if residuals show a systematic pattern (e.g., U-shape), the linear model is inadequate and a non-linear model should be considered
- Relying solely on R-squared to judge model quality — a low R-squared does not invalidate the relationship, and a high R-squared does not confirm it; always check assumptions and residuals
How to Interpret Results
- The slope (m) tells you how much y changes for each unit increase in x — a slope of 2.5 means y increases by 2.5 units for every 1-unit increase in x
- R-squared of 0.85 means 85% of the variation in y is explained by x — the remaining 15% is due to other factors or noise
- If the intercept (b) is negative or implausibly large, it may indicate the linear model does not apply near x = 0 — the intercept is only meaningful if x = 0 is within the data range
Related Standards & References
- Legendre, A.-M. (1805), Nouvelles méthodes pour la détermination des orbites des comètes — first publication of the method of least squares
- Draper & Smith, Applied Regression Analysis (Wiley) — classic reference for least-squares fitting and residual diagnostics
- NIST/SEMATECH e-Handbook of Statistical Methods (Section 4, Process Modeling) — practical guidance on linear regression and model validation
Frequently Asked Questions
What does R² tell me and what is a 'good' value?
R² indicates the fraction of variance in the dependent variable explained by the model. In physical sciences, R² > 0.95 is common. In social sciences and economics, R² = 0.3-0.7 may be acceptable. A high R² does not prove causation, and a low R² does not mean the relationship is unimportant — it may just mean other factors are at play.
Can I use linear regression for non-linear data?
Not directly. If the relationship is curved, consider polynomial regression, logarithmic transformation (log-linear models), or other non-linear approaches. Plotting residuals vs. fitted values will reveal non-linearity: a pattern in the residuals indicates the linear model is inadequate.