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²
Try your own numbers
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
- The arithmetic of the published formula for the values you entered, in the units shown.
What remains unverified
- That the inputs suit your application. Take ratings, resistances and constants from the manufacturer data sheet or project specification.
Verification register entry
| Calculation author | Rahul Sharma (author) |
|---|---|
| Technical review | No independent technical review has been carried out |
| Individual professional approval | Not recorded |
| Formula reference | not recorded |
| Standard and edition | Not applicable: Pure mathematics or statistics; no electrical standard governs the method |
| Standard review state | Not applicable |
| Scope-screening note | not recorded |
| Cross-check test cases | 34 reference vectors (tests/reference_vectors.json) |
| Review date | not recorded |
| Next review date | not recorded |
| Status | Engineering 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
Worked example
| Input | Value |
|---|---|
| Point 1: x | 0 |
| Point 1: y | 4 |
| Point 2: x | 25 |
| Point 2: y | 8.1 |
| Point 3: x | 50 |
| Point 3: y | 11.9 |
| Point 4: x | 75 |
| Point 4: y | 16.2 |
| Point 5: x | 100 |
| Point 5: y | 19.9 |
- n = 5 points, mean x = 50, mean y = 12.02
- Σ(x − x̄)² = 6,250, Σ(y − ȳ)² = 159.268, Σ(x − x̄)(y − ȳ) = 997.5
- Slope m = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)² = 0.1596
- Intercept c = ȳ − m x̄ = 12.02 − 0.1596 × 50 = 4.04
- r = 0.99978964, r² = 0.99957933
- Standard error of the fit = 0.14944341
- To read y from the line, enter an x to predict
Assumptions
- 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
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
| Input | Unit | Allowed or shown | Note |
|---|---|---|---|
| Point 1: x | (number) | -1,000,000,000,000 or more, up to 1,000,000,000,000 | Enter 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 blank | Enter an x to read y from the fitted line. Leave blank to skip. |
| Result | Unit | Allowed or shown | Note |
|---|---|---|---|
| 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: y | Slope m | Intercept c | Correlation coefficient r |
|---|---|---|---|
| 0.4 | 0.1884 | 1.88 | 0.98774485 |
| 1 | 0.1836 | 2.24 | 0.99085469 |
| 2 | 0.1756 | 2.84 | 0.99529342 |
| 4 | 0.1596 | 4.04 | 0.99978964 |
| 8 | 0.1276 | 6.44 | 0.97109979 |
| 16 | 0.0636 | 11.24 | 0.55529272 |
| 40 | -0.1284 | 25.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.
- Mean and Standard Deviation Formulas: Statistics formulas for test readings: mean, median, mode, range, standard deviation, variance and standard error
- Measurement Uncertainty Formulas: Measurement uncertainty formulas: the standard uncertainty of a rectangular limit
- Percentage Error Formulas for Measurements: Percentage error formulas for engineers: absolute, relative and percentage error of a meter reading
More Engineering Mathematics calculatorsAll engineering calculatorsLinear Regression (Line of Best Fit) in Elecmetric