Math / Statistics
Linear Regression Calculator
Calculate regression equation, steps, graph, uncertainty analysis, and predictions for simple and multiple linear regression.
About this calculator
Method, formulas, and limits.What this does
Fits a linear regression model to paired data using ordinary least squares, returning the regression equation, slope, intercept, R-squared, correlation coefficient, and residuals. Supports simple regression with one predictor and multiple regression with two or more predictors, and computes confidence intervals and prediction intervals for any given x value.
Who it is for
Students, researchers, data analysts, and anyone who needs to model the relationship between variables or make predictions from data. Useful for coursework, data exploration, trend analysis, and quick regression checks without firing up a full statistics package.
How it works
For simple regression, the calculator computes Sxx (sum of squared x deviations), Sxy (sum of cross products), then derives the slope b = Sxy/Sxx and intercept a = ȳ - b·x̄. For multiple regression it uses matrix algebra to solve the normal equations. R-squared is computed from the ratio of explained sum of squares to total sum of squares, and intervals use the t-distribution with the appropriate standard error.
Limitations
The calculator checks basic assumptions but cannot verify independence, homoscedasticity, or normality from raw data alone. Outliers can heavily influence the regression line, and extrapolating beyond the observed x range produces unreliable predictions. Multiple regression with many predictors relative to sample size risks overfitting.
Key calculations
- Slope (Simple Regression)
- The slope b = Sxy / Sxx, where Sxx = Σ(xᵢ - x̄)² and Sxy = Σ(xᵢ - x̄)(yᵢ - ȳ). It measures the expected change in y for a one-unit change in x.
- Intercept
- The intercept a = ȳ - b·x̄, where ȳ and x̄ are the sample means. It represents the predicted y value when x equals zero.
- Coefficient of Determination (R²)
- R² = 1 - SS_res / SS_total, where SS_res is the sum of squared residuals and SS_total is the total sum of squares. It ranges from 0 to 1, with higher values indicating a better fit.
- Prediction Interval
- A 100(1-α)% prediction interval for a new observation at x₀ is ŷ ± t_(α/2, n-2) × SE × √(1 + 1/n + (x₀ - x̄)²/Sxx), where SE is the residual standard error.
Reference ranges
- R² Interpretation
- R² > 0.7 indicates a strong linear relationship. R² between 0.3 and 0.7 is moderate. R² < 0.3 suggests a weak fit, meaning x explains little of the variation in y.
- Correlation Strength
- |r| > 0.8 is a very strong linear correlation, |r| between 0.5 and 0.8 is moderate, |r| between 0.3 and 0.5 is weak, and |r| < 0.3 is negligible.
- Residual Patterns
- Well-behaved residuals should be randomly scattered around zero with no obvious pattern (funnel, curve, or clusters). Patterns suggest a nonlinear relationship or heteroscedasticity.
- Sample Size Guidelines
- For simple regression, 10-20 data points is the minimum for reliable intervals. For multiple regression, aim for at least 10-15 observations per predictor variable.
How to use it
- 1.Enter paired dataAdd x and y values for simple regression, or y and predictor columns for multiple regression.
- 2.Review the regression fitRead the equation, slope, intercept, R^2, correlation, and residual outputs.
- 3.Check intervals and predictionsUse the prediction input and uncertainty options to compare fitted values, confidence intervals, and prediction intervals.
Linear regression is a statistical method that models the relationship between a dependent variable and one or more independent variables by fitting a linear equation to observed data. The most common method is ordinary least squares, which finds the line that minimizes the sum of squared vertical distances between data points and the fitted line. It is widely used for prediction, trend analysis, and understanding variable relationships.
Simple linear regression finds the best-fit line y = a + bx by minimizing the sum of squared residuals. The slope b = Sxy / Sxx and the intercept a = ȳ - b·x̄, where Sxx is the sum of squared deviations of x and Sxy is the sum of cross products between x and y. Multiple regression extends this using matrix algebra to solve for multiple coefficients simultaneously.
R² (coefficient of determination) measures the proportion of variance in the dependent variable that is predictable from the independent variables. An R² of 0.85 means the model explains 85% of the variance in y. However, a high R² does not prove causation, and adding more predictors always inflates R² even if they are irrelevant, which is why adjusted R² is sometimes preferred.
A confidence interval estimates the mean response at a given x value — it tells you where the average y falls for all observations with that x. A prediction interval estimates where a single new observation will fall. Prediction intervals are always wider because they include both the uncertainty in the regression line and the inherent random scatter of individual data points.
Linear regression assumes: linearity (the true relationship is linear), independence of observations, homoscedasticity (constant variance of residuals), approximate normality of residuals, and no severe outliers. For multiple regression, it also assumes no severe multicollinearity among predictors. Violating these assumptions can produce biased coefficients or misleading confidence intervals.
Simple linear regression has one independent variable and fits a line (y = a + bx). Multiple linear regression has two or more independent variables and fits a hyperplane (y = b0 + b1x1 + b2x2 + ...). Multiple regression can capture more complex relationships but requires more data and careful attention to multicollinearity and model selection.
This calculator is designed for linear regression only, but you can fit polynomial models by entering transformed variables (e.g., x²) as additional predictors in multiple regression mode. True nonlinear regression requires iterative methods not included here.
Data Input
Enter paired x and y values
Need a change for Linear Regression Calculator?
Related calculators
Quick jumps
Binomial Distribution Calculator
Calculate exact binomial probabilities, CDF tails, and range probability.
Percentage Calculator
Solve percentage questions, points, margins, and money cases.
MAP Calculator
Calculate mean arterial pressure from systolic and diastolic blood pressure.
Cubic Feet Calculator
Calculate cubic feet from room dimensions, square feet plus depth, cylinders, logs, slabs, and metric or imperial inputs.