Skip to main content
engineering

Linear Regression Calculator

Simple linear regression with slope, intercept, R², adjusted R², residuals, predictions, and scatter/residual plots

By Christopher FloiedPublished Updated

The example below uses these same controls. Shared inputs stay in the URL fragment; anyone with the link can read them.

Simple linear regression: ŷ = b₀ + b₁x with R², residual diagnostics, 95% intervals and predictions.

xy
Intercept (b₀)
0.342857
Slope (b₁)
1.873810
R²
0.998063
Adj. R²
0.997740
Corr. coeff. r
0.999031
Std Error (se)
0.218400
n
8
se(b₁)
0.033700
ŷ = 0.3429 + 1.8738 × x

R² and correlation are undefined when all y values are equal. Coefficient tests are undefined when residual variance is zero. Predictions outside the observed x range are extrapolations.

CoeffEstimateStd Errort-statp-value
b₀ (intercept)0.34290.17022.01470.090560
b₁ (slope)1.87380.033755.60300.000000
Predicted ŷ
17.2071

95% intervals

Fixed at 95% (two-sided), using t* = 2.4469 on 6 degrees of freedom (n − 2).

Slope b₁, 95% confidence interval
[1.7913, 1.9563]
Mean response at x = 9, 95% confidence interval
[16.7907, 17.6235]
New observation at x = 9, 95% prediction interval
[16.5297, 17.8846]

The confidence interval is for the average y at this x; the prediction interval is for one new observation, so it is always wider. Both assume the straight-line model with independent errors of constant variance that are roughly normal. x = 9 is outside the observed x range (1 to 8), so both intervals also assume the line still holds there.

Scatter Plot with Regression Line

Tip: hover to read values, click to pin a point for export

Residuals vs fitted values

Each point is one observation: its residual (y − ŷ) against its fitted value ŷ. A curve, a funnel or an isolated point suggests the straight-line model or its constant-variance assumption does not hold. The diagnostics table below lists the same values.

Tip: hover to read values, click to pin a point for export

Residual diagnostics

Leverage h = 1/n + (x − x̄)²/Sxx; standardized residual = residual/(se·√(1 − h)); Cook's D = (std. residual)²·h/(2(1 − h)). A row is flagged when |std. residual| > 2 or Cook's D > 4/n = 0.5000. Flags prompt inspection; they are not automatic deletion rules. Check the data entry and the context before removing anything.

No point exceeds either rule.

RowxyFitted ŷResidualLeverage hStd. residualCook's DFlag
112.12.2167-0.11670.4167-0.69940.1747—
223.94.0905-0.19050.2738-1.02340.1975—
336.25.96430.23570.17861.19080.1541—
447.87.8381-0.03810.1310-0.18710.0026—
5510.19.71190.38810.13101.90620.2738—
6611.511.5857-0.08570.1786-0.43300.0204—
7713.413.4595-0.05950.2738-0.31980.0193—
8815.215.3333-0.13330.4167-0.79930.2282—

Learn with a worked scenario

Ordinary least squares for one predictor with an intercept, predictions, residual diagnostics and 95% intervals.

Question

Fit points (1,2), (2,4), (3,5), (4,4), (5,5); predict at x = 6.

  1. The means are x̄ = 3 and ȳ = 4.
  2. Σ(x − x̄)² = 10 and Σ(x − x̄)(y − ȳ) = 6.
  3. Slope = 6/10 = 0.6; intercept = 4 − 0.6 × 3 = 2.2.
  4. At x = 6, ŷ = 2.2 + 0.6 × 6 = 5.8. R² = 0.60.

Fitted line: ŷ = 2.2 + 0.6x. Prediction at 6: 5.8.

Precision: Coefficients, R², r and standard errors are shown to 6 decimals in the summary; the fitted equation, coefficient table, prediction, diagnostics and intervals to 4; p-values to 6. Intermediate values are not rounded.

Load this example in the calculator

Try a variation

Predict at x = 4 instead of x = 6. What fitted value do you get, and is it an extrapolation? Predict the answer before you reveal it.

Predict, then reveal

4.6, from ŷ = 2.2 + 0.6 × 4. It is not an extrapolation: x = 4 lies inside the observed x range of 1 to 5, whereas x = 6 does not.

Change one input and compare
Prediction xFitted y
23.4
44.6
65.8 (extrapolation)
Load the variation in the calculator

Check the assumptions

  • All complete supplied rows participate; missing rows are not silently discarded.
  • Coefficient inference needs suitable independent errors with constant variance and an appropriate distribution.
  • x = 6 is outside the observed range, so this prediction is extrapolation.

Common mistake: Treating R² as proof of causation or ignoring a pattern in residuals.

Method reference: NIST/SEMATECH: Linear Least Squares Regression. These examples illustrate the method; they do not validate every possible input.

How to Use This Calculator

1

Enter your input values

Fill in all required input fields for the Linear Regression Calculator. Follow the units and input format printed next to each field. Where a unit selector is available, choose the units that match your data.

2

Review your inputs

Double-check that all values are correct and match the units or format shown for each field. Incorrect units are the most common source of calculation errors and can produce results that are off by factors of 2, 10, or more.

3

Read the results

The Linear Regression Calculator computes the output in your browser and displays the results, with units clearly labeled, as soon as they are ready — no data sent to a server.

4

Explore parameter sensitivity

Try adjusting individual input values to see how the output changes. This is a quick and effective way to develop intuition about how different parameters influence the result and to identify which inputs have the largest effect.

When to Use This Calculator

  • •Use the Linear Regression Calculator to check your hand calculations on homework or exam problems — comparing its result with your own working helps identify arithmetic errors before they propagate.
  • •Use it during the early design phase to rapidly iterate on parameters and narrow down feasible configurations before committing time to detailed finite element simulations or full design packages.
  • •Use it when reviewing a colleague's calculation or checking a vendor's data sheet for plausibility — a quick sanity check can prevent costly downstream errors.
  • •Use it to generate reference data for a technical report or presentation without manual computation, ensuring consistent, reproducible numbers throughout the document.
  • •Use it in the field when a quick estimate is needed and a full engineering software package is not available.

About This Calculator

The Linear Regression Calculator is a precision engineering calculation tool designed for students, engineers, and technical professionals. Simple linear regression with slope, intercept, R², adjusted R², residuals, predictions, and scatter/residual plots All calculations are performed using established engineering formulas from the relevant scientific literature and standards. Follow the units printed beside each field. Where a unit selector is provided, the selected unit is converted internally. Results are computed in your browser without sending data to a server, which keeps your inputs private. This calculator is intended as a supplementary tool for learning and design exploration; always verify results against authoritative references for safety-critical applications.

The Theory Behind It

Simple linear regression fits a straight line y = β₀ + β₁·x + ε to data, minimizing the sum of squared residuals (method of least squares). The slope β₁ = Σ((x − x̄)(y − ȳ)) / Σ(x − x̄)² and the intercept β₀ = ȳ − β₁·x̄. The coefficient of determination R² = 1 − SS_residual/SS_total measures the proportion of variance in y explained by x, ranging from 0 (no fit) to 1 (perfect fit). The adjusted R² accounts for the number of predictors: R²_adj = 1 − (1 − R²)·(n−1)/(n−p−1), where p is the number of predictors. For simple linear regression, p = 1. Standard errors of the coefficients quantify uncertainty: SE(β₁) = √(MSE/Σ(x − x̄)²) and SE(β₀) similarly. Hypothesis tests on β₁ use t = β₁/SE(β₁), which follows a t-distribution with n−2 degrees of freedom. Confidence intervals on β₁ are β₁ ± t_(α/2, n−2)·SE(β₁). The regression assumes: (1) linearity — y is a linear function of x; (2) independence — observations are independent; (3) homoscedasticity — residuals have constant variance; (4) normality — residuals are normally distributed. Violations require transformations, weighted regression, or non-parametric methods. For multiple predictors, use multiple linear regression with matrix computations. The calculator handles simple linear regression with slope, intercept, R², SE, and prediction intervals.

Real-World Applications

  • •Calibration curves: relate instrument readings (x) to actual values (y) from calibration standards, then use the regression to convert new readings to values.
  • •Trend analysis: fit linear trend to time-series data (revenue, temperature, performance metrics) to quantify direction and rate of change.
  • •Predictive modeling: predict one variable from another using the fitted regression, with prediction intervals quantifying uncertainty.
  • •Quality control: relate process variables to output variables and identify which process factors control product quality.
  • •Scientific data analysis: fit experimental data to a theoretical linear relationship to estimate the slope (often a physical constant) and test agreement.

Frequently Asked Questions

What's the formula for simple linear regression slope?

β₁ = Σ((x − x̄)(y − ȳ)) / Σ((x − x̄)²), which is the covariance of x and y divided by the variance of x. The intercept is β₀ = ȳ − β₁·x̄. These minimize the sum of squared residuals Σ(y − ŷ)² and are the 'best' fit in a least-squares sense.

What's R²?

The coefficient of determination R² measures the proportion of variance in y explained by x. R² = 0 means the regression explains nothing (as good as just using ȳ). R² = 1 means perfect fit (all variance explained). R² = 0.6 means 60% of the variance is explained, 40% is unexplained (random or due to other factors). High R² doesn't imply causation or practical significance — it just means the data fit the linear model well.

How do I test if the slope is significant?

Compute t = β₁/SE(β₁), where SE(β₁) is the standard error of the slope. Compare to t critical value with n−2 degrees of freedom. Equivalently, compute p-value from the t-statistic and reject H₀ (slope = 0) if p < α. If p < 0.05, you have evidence that the slope is significantly different from zero, meaning x has a statistically significant relationship with y.

When is linear regression inappropriate?

When the relationship between x and y is nonlinear (curved), when residuals have non-constant variance (heteroscedasticity), when observations are not independent (autocorrelation in time series), when outliers dominate the fit, or when predictors are highly correlated (multicollinearity in multiple regression). Check residual plots to detect these problems.

What's the difference between correlation and regression?

Correlation measures the strength of a linear relationship (r ranges from −1 to +1); it is symmetric in x and y. Regression fits a specific linear relationship y = f(x) and treats x as predictor and y as response; the roles are not symmetric. R² in simple regression equals r² (the squared correlation coefficient). Regression predicts; correlation just measures strength.

Related Calculators

References & Further Reading

Add the live Linear Regression Calculator to your site. Free to embed, with a link back to MegaCalc.