Elecmetric

Linear Regression Calculator

Fit a straight line y = m x + c through up to 10 measured points by least squares. Gives the slope, the intercept, the correlation coefficient r and r²

Point 1: x 0, point 1: y 4, point 2: x 25, point 2: y 8.1 gives
Slope m: 0.1596 · Intercept c: 4.04 · Correlation coefficient r: 0.99978964

Estimate only. Not engineering or safety advice. Check the result against the applicable standard and the equipment data, and have a competent engineer review it before it is relied on. Terms of use.

Open in the calculator with these values

About this calculator

This page calculates slope m, intercept c, correlation coefficient r and 6 more results from point 1 x, point 1 y, point 2 x, point 2 y and 17 more inputs. Change any value or its unit and the result updates. The steps below show the working for the default values, so you can check each line against your own method.

Limits of this calculator

Use this to fit a calibration line to instrument readings, to find the slope and offset of a sensor, to find a resistance from voltage and current pairs (the slope of V against I), or to see whether test readings follow a trend. Check that the points look straight before relying on r². For just two points use the linear interpolation calculator.

Cross-check: 34 reference cases, calculated from textbook formulas coded separately from the engine by the same author, agree with this calculator. This is not an independent review.

Verification status: Engineering reference

Engineering reference. Formula and method documented and tested against separately coded reference calculations. Not yet Verified: the evidence listed on this page is still needed.

What this calculator checks

What remains unverified

Verification register entry

Calculation authorRahul Sharma (author)
Technical reviewNo independent technical review has been carried out
Individual professional approvalNot recorded
Formula referencenot recorded
Standard and editionNot applicable: Pure mathematics or statistics; no electrical standard governs the method
Standard review stateNot applicable
Scope-screening notenot recorded
Cross-check test cases34 reference vectors (tests/reference_vectors.json)
Review datenot recorded
Next review datenot recorded
StatusEngineering reference

Needed before this calculator can be marked Verified: reviewer name, qualification and review date; exact formula reference; formula source (textbook or standard); next review date.

Formula

m = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² c = ȳ − m x̄ r = Σ(x − x̄)(y − ȳ) / √(Σ(x − x̄)² Σ(y − ȳ)²) r² = r × r standard error = √(Σ(y − m x − c)² / (n − 2))

Worked example

InputValue
Point 1: x0
Point 1: y4
Point 2: x25
Point 2: y8.1
Point 3: x50
Point 3: y11.9
Point 4: x75
Point 4: y16.2
Point 5: x100
Point 5: y19.9
  1. n = 5 points, mean x = 50, mean y = 12.02
  2. Σ(x − x̄)² = 6,250, Σ(y − ȳ)² = 159.268, Σ(x − x̄)(y − ȳ) = 997.5
  3. Slope m = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² = 0.1596
  4. Intercept c = ȳ − m x̄ = 12.02 − 0.1596 × 50 = 4.04
  5. r = 0.99978964, r² = 0.99957933
  6. Standard error of the fit = 0.14944341
  7. To read y from the line, enter an x to predict

Assumptions

Use this to fit a calibration line to instrument readings, to find the slope and offset of a sensor, to find a resistance from voltage and current pairs (the slope of V against I), or to see whether test readings follow a trend. Check that the points look straight before relying on r². For just two points use the linear interpolation calculator.

Inputs and results

InputUnitAllowed or shownNote
Point 1: x(number)-1,000,000,000,000 or more, up to 1,000,000,000,000Enter each point as an x and a y. At least two points are needed, and the x values must not all be the same. Blank pairs are ignored.
Point 1: y(number)-1,000,000,000,000 or more, up to 1,000,000,000,000
Point 2: x(number)-1,000,000,000,000 or more, up to 1,000,000,000,000
Point 2: y(number)-1,000,000,000,000 or more, up to 1,000,000,000,000
Point 3: x(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 3: y(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 4: x(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 4: y(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 5: x(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 5: y(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 6: x(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 6: y(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 7: x(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 7: y(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 8: x(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 8: y(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 9: x(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 9: y(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 10: x(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
Point 10: y(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blank
x to predict y at (optional)(number)-1,000,000,000,000 or more, up to 1,000,000,000,000; may be left blankEnter an x to read y from the fitted line. Leave blank to skip.
ResultUnitAllowed or shownNote
Slope m(number)Shown to 10 decimal places
Intercept c (y at x = 0)(number)Shown to 10 decimal places
Correlation coefficient r(number)Shown to 8 decimal places
Coefficient of determination r²(number)Shown to 8 decimal places
Standard error of the fit (n − 2)(number)Shown to 8 decimal places
Number of points(number)Shown to 0 decimal places
Mean of x(number)Shown to 8 decimal places
Mean of y(number)Shown to 8 decimal places
y at the chosen x(number)Shown to 10 decimal places

How it is calculated

Each input is converted to the base unit of its quantity, the formula above is applied in the order shown in the worked example, and each result is shown in the unit you choose. Results are held at full precision and rounded only for display, except where a step selects a standard size, as the worked example shows. A value outside its allowed range is refused with a message instead of giving a result.

How the result changes with point 1: y

Point 1: ySlope mIntercept cCorrelation coefficient r
0.40.18841.880.98774485
10.18362.240.99085469
20.17562.840.99529342
40.15964.040.99978964
80.12766.440.97109979
160.063611.240.55529272
40-0.128425.64-0.40812223

Other inputs are the same as in the worked example above.

Standards and further reading

Complex numbers, rectangular and polar form and angle conversion are standard mathematics, not the subject of a standard. Standards apply when the result feeds an electrical design, and they set the method there.

Frequently asked questions

What do I need to enter?

Enter point 1: x, point 1: y, point 2: x, point 2: y, point 3: x, point 3: y, point 4: x, point 4: y, point 5: x, point 5: y, point 6: x, point 6: y, point 7: x, point 7: y, point 8: x, point 8: y, point 9: x, point 9: y, point 10: x, point 10: y and x to predict y at (optional). Change the unit of a value with its selector and the result stays the same.

What does this calculator assume?

The relation is assumed to be a straight line, and the line is the one that makes the sum of the squared vertical distances from the points as small as possible; x is treated as exact and y as the measured quantity. At least two points are needed and the x values must not all be the same, because then the slope is not defined. With exactly two points the line passes through both, so r² is 1 and the standard error is not defined; a warning is shown. r² near 1 means the points lie close to the line; it does not prove that the relation is a straight line, so look at the points as well. If the y values are all equal the line is level and r is not defined, and a warning is shown. A chosen x outside the entered points is extrapolation and is less reliable.

Which calculators should I use next?

Common next steps are Linear Interpolation Calculator, Standard Deviation and Variance, Mean, Median and Mode and Percentage Error. The related links at the bottom of this page open them.

How accurate are the results?

Every figure comes from the same tested engine as the Elecmetric calculators and is meant for estimating. 34 reference cases, calculated from textbook formulas coded separately from the engine by the same author, agree with this calculator. This is not an independent review. Check design values against the standard and the equipment data you work to.

Formula guides and reference

Longer explanations with worked examples and tables, written for the same topic.

More Engineering Mathematics calculatorsAll engineering calculatorsLinear Regression (Line of Best Fit) in Elecmetric

Tell us how to improve this page

This opens your email app. Nothing is sent until you press send.