Mathematics · Statistics
Linear Regression Calculator
Fit a least-squares line to three paired observations.
Inputs and results stay in this browser. Change one value at a time to explore the relationship.
Calculation steps
- x̄=2; ȳ=4.
- Slope=2; intercept=0; line y=2x+0.
Understand Linear regression
One idea, three depths
Choose how deeply to explain Linear regression
Linear regression: Fit a least-squares line to three paired observations.
Age 5Explain it to a 5-year-oldStart with a picture
Imagine using Linear regression to answer this question: fit a least-squares line to three paired observations? Enter x₁, y₁, x₂, and 3 other inputs; the calculator shows Slope. For example: (1,2),(2,4),(3,6) fits y=2x. The answer tells you Slope.
Age 15Explain it to a 15-year-oldConnect it to the formula
Least squares chooses the line minimizing summed squared vertical residuals. The rule is slope=Σdx·dy/Σdx²; intercept=ȳ−slope·x̄. Its input values are x₁, y₁, x₂, y₂, x₃, y₃, and the main result is Slope. For example: (1,2),(2,4),(3,6) fits y=2x.
CollegeExplain it at college levelState the model precisely
This calculator evaluates the stated linear regression relation over the valid real-number domain stated below. The implemented relation is slope=Σdx·dy/Σdx²; intercept=ȳ−slope·x̄, evaluated from x₁, y₁, x₂, y₂, x₃, y₃ to produce Slope. Least squares chooses the line minimizing summed squared vertical residuals. Extrapolating beyond the observed x range may be unreliable.
Inputs and valid domain
- x₁ must be a finite real number.
- y₁ must be a finite real number.
- x₂ must be a finite real number.
- y₂ must be a finite real number.
- x₃ must be a finite real number.
- y₃ must be a finite real number.
Important boundary: Extrapolating beyond the observed x range may be unreliable.
The formula
slope=Σdx·dy/Σdx²; intercept=ȳ−slope·x̄
How the calculator works through it
It substitutes x₁, y₁, x₂, y₂, x₃, y₃ into the formula and exposes every numerical step above. The main output is Slope, accompanied by Intercept, Prediction at mean x.
Read the result correctly
The Slope is the direct answer to “fit a least-squares line to three paired observations.” Read it with the units shown beside the inputs; a sign, angle, percentage or rate changes what the number means.
A worked check
(1,2),(2,4),(3,6) fits y=2x.
Where this model stops being reliable
Extrapolating beyond the observed x range may be unreliable.
Learn it by changing one value
Begin with the worked example, then change one value while keeping the others fixed. Compare the new result and calculation steps to identify which part of the formula changed.
Dictionary terms behind this calculator
Before studying the codeWhat you should know firstUse the calculator immediately, or check the foundations before reading the implementation.
These foundations help you understand why Linear regression works. They never block the calculator, and “optional” means useful context rather than a hidden requirement.
Hard requirements
- Reading formulas and substituting values
Linear regression uses slope=Σdx·dy/Σdx²; intercept=ȳ−slope·x̄. You need to recognise what each side represents before substituting the stated inputs or rearranging the relationship.
Review this foundation about 4 min
Strong support
- Averages and representative values
Representative values help you judge what the Linear regression inputs summarise and what the result can legitimately describe.
Review this foundation about 5 min
Optional enrichment
- Spread and measurement variation
Variation is not always part of the Linear regression formula, but it helps you judge how stable a reported result may be.
Review this foundation about 6 min
Mathematics → algorithm → program
Implement this calculation in code
These are direct reference implementations of the calculator's principal relationship and first output. They run locally and include a small known-answer check where the language supports it.
Algorithm
- Read x₁, y₁, x₂, y₂, x₃, y₃.
- Evaluate the principal relationship: slope=Σdx·dy/Σdx²; intercept=ȳ−slope·x̄.
- Return Slope and check the domain conditions described above.
Python
from math import *
def linear_regression_three_pairs(v1, v2, v3, v4, v5, v6) -> float:
return (((((v1 - (((v1 + v3) + v5) / 3.0)) * (v2 - (((v2 + v4) + v6) / 3.0))) + ((v3 - (((v1 + v3) + v5) / 3.0)) * (v4 - (((v2 + v4) + v6) / 3.0)))) + ((v5 - (((v1 + v3) + v5) / 3.0)) * (v6 - (((v2 + v4) + v6) / 3.0)))) / ((((v1 - (((v1 + v3) + v5) / 3.0)) * (v1 - (((v1 + v3) + v5) / 3.0))) + ((v3 - (((v1 + v3) + v5) / 3.0)) * (v3 - (((v1 + v3) + v5) / 3.0)))) + ((v5 - (((v1 + v3) + v5) / 3.0)) * (v5 - (((v1 + v3) + v5) / 3.0)))))
assert abs(linear_regression_three_pairs(1, 2, 2, 4, 3, 6) - 2) < 1e-6 * max(1.0, abs(2))
C
#include <assert.h>
#include <math.h>
double linear_regression_three_pairs(double v1, double v2, double v3, double v4, double v5, double v6) {
return (((((v1 - (((v1 + v3) + v5) / 3.0)) * (v2 - (((v2 + v4) + v6) / 3.0))) + ((v3 - (((v1 + v3) + v5) / 3.0)) * (v4 - (((v2 + v4) + v6) / 3.0)))) + ((v5 - (((v1 + v3) + v5) / 3.0)) * (v6 - (((v2 + v4) + v6) / 3.0)))) / ((((v1 - (((v1 + v3) + v5) / 3.0)) * (v1 - (((v1 + v3) + v5) / 3.0))) + ((v3 - (((v1 + v3) + v5) / 3.0)) * (v3 - (((v1 + v3) + v5) / 3.0)))) + ((v5 - (((v1 + v3) + v5) / 3.0)) * (v5 - (((v1 + v3) + v5) / 3.0)))));
}
int main(void) {
const double expected = 2;
const double actual = linear_regression_three_pairs(1, 2, 2, 4, 3, 6);
assert(fabs(actual - expected) < 1e-6 * fmax(1.0, fabs(expected)));
}
C++
#include <cassert>
#include <cmath>
#include <numbers>
double linear_regression_three_pairs(double v1, double v2, double v3, double v4, double v5, double v6) {
return (((((v1 - (((v1 + v3) + v5) / 3.0)) * (v2 - (((v2 + v4) + v6) / 3.0))) + ((v3 - (((v1 + v3) + v5) / 3.0)) * (v4 - (((v2 + v4) + v6) / 3.0)))) + ((v5 - (((v1 + v3) + v5) / 3.0)) * (v6 - (((v2 + v4) + v6) / 3.0)))) / ((((v1 - (((v1 + v3) + v5) / 3.0)) * (v1 - (((v1 + v3) + v5) / 3.0))) + ((v3 - (((v1 + v3) + v5) / 3.0)) * (v3 - (((v1 + v3) + v5) / 3.0)))) + ((v5 - (((v1 + v3) + v5) / 3.0)) * (v5 - (((v1 + v3) + v5) / 3.0)))));
}
int main() {
constexpr double expected = 2;
const double actual = linear_regression_three_pairs(1, 2, 2, 4, 3, 6);
assert(std::fabs(actual - expected) < 1e-6 * std::fmax(1.0, std::fabs(expected)));
}
Linux x86-64 assembly
x86-64 NASM · System V ABI · Linux · SSE2 with libm where required
; double linear_regression_three_pairs(double v1, double v2, double v3, double v4, double v5, double v6)
; Linux x86-64 NASM · System V ABI · first eight doubles in xmm0–xmm7
global linear_regression_three_pairs
section .text
linear_regression_three_pairs:
push rbp
mov rbp, rsp
sub rsp, 624
movsd [rbp-8], xmm0
movsd [rbp-16], xmm1
movsd [rbp-24], xmm2
movsd [rbp-32], xmm3
movsd [rbp-40], xmm4
movsd [rbp-48], xmm5
movsd xmm0, [rbp-8]
addsd xmm0, [rbp-24]
movsd [rbp-112], xmm0
movsd xmm0, [rbp-112]
addsd xmm0, [rbp-40]
movsd [rbp-104], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-120], xmm0
movsd xmm0, [rbp-104]
divsd xmm0, [rbp-120]
movsd [rbp-96], xmm0
movsd xmm0, [rbp-8]
subsd xmm0, [rbp-96]
movsd [rbp-88], xmm0
movsd xmm0, [rbp-16]
addsd xmm0, [rbp-32]
movsd [rbp-152], xmm0
movsd xmm0, [rbp-152]
addsd xmm0, [rbp-48]
movsd [rbp-144], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-160], xmm0
movsd xmm0, [rbp-144]
divsd xmm0, [rbp-160]
movsd [rbp-136], xmm0
movsd xmm0, [rbp-16]
subsd xmm0, [rbp-136]
movsd [rbp-128], xmm0
movsd xmm0, [rbp-88]
mulsd xmm0, [rbp-128]
movsd [rbp-80], xmm0
movsd xmm0, [rbp-8]
addsd xmm0, [rbp-24]
movsd [rbp-200], xmm0
movsd xmm0, [rbp-200]
addsd xmm0, [rbp-40]
movsd [rbp-192], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-208], xmm0
movsd xmm0, [rbp-192]
divsd xmm0, [rbp-208]
movsd [rbp-184], xmm0
movsd xmm0, [rbp-24]
subsd xmm0, [rbp-184]
movsd [rbp-176], xmm0
movsd xmm0, [rbp-16]
addsd xmm0, [rbp-32]
movsd [rbp-240], xmm0
movsd xmm0, [rbp-240]
addsd xmm0, [rbp-48]
movsd [rbp-232], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-248], xmm0
movsd xmm0, [rbp-232]
divsd xmm0, [rbp-248]
movsd [rbp-224], xmm0
movsd xmm0, [rbp-32]
subsd xmm0, [rbp-224]
movsd [rbp-216], xmm0
movsd xmm0, [rbp-176]
mulsd xmm0, [rbp-216]
movsd [rbp-168], xmm0
movsd xmm0, [rbp-80]
addsd xmm0, [rbp-168]
movsd [rbp-72], xmm0
movsd xmm0, [rbp-8]
addsd xmm0, [rbp-24]
movsd [rbp-288], xmm0
movsd xmm0, [rbp-288]
addsd xmm0, [rbp-40]
movsd [rbp-280], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-296], xmm0
movsd xmm0, [rbp-280]
divsd xmm0, [rbp-296]
movsd [rbp-272], xmm0
movsd xmm0, [rbp-40]
subsd xmm0, [rbp-272]
movsd [rbp-264], xmm0
movsd xmm0, [rbp-16]
addsd xmm0, [rbp-32]
movsd [rbp-328], xmm0
movsd xmm0, [rbp-328]
addsd xmm0, [rbp-48]
movsd [rbp-320], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-336], xmm0
movsd xmm0, [rbp-320]
divsd xmm0, [rbp-336]
movsd [rbp-312], xmm0
movsd xmm0, [rbp-48]
subsd xmm0, [rbp-312]
movsd [rbp-304], xmm0
movsd xmm0, [rbp-264]
mulsd xmm0, [rbp-304]
movsd [rbp-256], xmm0
movsd xmm0, [rbp-72]
addsd xmm0, [rbp-256]
movsd [rbp-64], xmm0
movsd xmm0, [rbp-8]
addsd xmm0, [rbp-24]
movsd [rbp-392], xmm0
movsd xmm0, [rbp-392]
addsd xmm0, [rbp-40]
movsd [rbp-384], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-400], xmm0
movsd xmm0, [rbp-384]
divsd xmm0, [rbp-400]
movsd [rbp-376], xmm0
movsd xmm0, [rbp-8]
subsd xmm0, [rbp-376]
movsd [rbp-368], xmm0
movsd xmm0, [rbp-8]
addsd xmm0, [rbp-24]
movsd [rbp-432], xmm0
movsd xmm0, [rbp-432]
addsd xmm0, [rbp-40]
movsd [rbp-424], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-440], xmm0
movsd xmm0, [rbp-424]
divsd xmm0, [rbp-440]
movsd [rbp-416], xmm0
movsd xmm0, [rbp-8]
subsd xmm0, [rbp-416]
movsd [rbp-408], xmm0
movsd xmm0, [rbp-368]
mulsd xmm0, [rbp-408]
movsd [rbp-360], xmm0
movsd xmm0, [rbp-8]
addsd xmm0, [rbp-24]
movsd [rbp-480], xmm0
movsd xmm0, [rbp-480]
addsd xmm0, [rbp-40]
movsd [rbp-472], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-488], xmm0
movsd xmm0, [rbp-472]
divsd xmm0, [rbp-488]
movsd [rbp-464], xmm0
movsd xmm0, [rbp-24]
subsd xmm0, [rbp-464]
movsd [rbp-456], xmm0
movsd xmm0, [rbp-8]
addsd xmm0, [rbp-24]
movsd [rbp-520], xmm0
movsd xmm0, [rbp-520]
addsd xmm0, [rbp-40]
movsd [rbp-512], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-528], xmm0
movsd xmm0, [rbp-512]
divsd xmm0, [rbp-528]
movsd [rbp-504], xmm0
movsd xmm0, [rbp-24]
subsd xmm0, [rbp-504]
movsd [rbp-496], xmm0
movsd xmm0, [rbp-456]
mulsd xmm0, [rbp-496]
movsd [rbp-448], xmm0
movsd xmm0, [rbp-360]
addsd xmm0, [rbp-448]
movsd [rbp-352], xmm0
movsd xmm0, [rbp-8]
addsd xmm0, [rbp-24]
movsd [rbp-568], xmm0
movsd xmm0, [rbp-568]
addsd xmm0, [rbp-40]
movsd [rbp-560], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-576], xmm0
movsd xmm0, [rbp-560]
divsd xmm0, [rbp-576]
movsd [rbp-552], xmm0
movsd xmm0, [rbp-40]
subsd xmm0, [rbp-552]
movsd [rbp-544], xmm0
movsd xmm0, [rbp-8]
addsd xmm0, [rbp-24]
movsd [rbp-608], xmm0
movsd xmm0, [rbp-608]
addsd xmm0, [rbp-40]
movsd [rbp-600], xmm0
mov rax, 0x4008000000000000
movq xmm0, rax
movsd [rbp-616], xmm0
movsd xmm0, [rbp-600]
divsd xmm0, [rbp-616]
movsd [rbp-592], xmm0
movsd xmm0, [rbp-40]
subsd xmm0, [rbp-592]
movsd [rbp-584], xmm0
movsd xmm0, [rbp-544]
mulsd xmm0, [rbp-584]
movsd [rbp-536], xmm0
movsd xmm0, [rbp-352]
addsd xmm0, [rbp-536]
movsd [rbp-344], xmm0
movsd xmm0, [rbp-64]
divsd xmm0, [rbp-344]
movsd [rbp-56], xmm0
movsd xmm0, [rbp-56]
leave
ret
MATLAB
function result = linear_regression_three_pairs(v1, v2, v3, v4, v5, v6)
result = (((((v1 - (((v1 + v3) + v5) / 3.0)) * (v2 - (((v2 + v4) + v6) / 3.0))) + ((v3 - (((v1 + v3) + v5) / 3.0)) * (v4 - (((v2 + v4) + v6) / 3.0)))) + ((v5 - (((v1 + v3) + v5) / 3.0)) * (v6 - (((v2 + v4) + v6) / 3.0)))) / ((((v1 - (((v1 + v3) + v5) / 3.0)) * (v1 - (((v1 + v3) + v5) / 3.0))) + ((v3 - (((v1 + v3) + v5) / 3.0)) * (v3 - (((v1 + v3) + v5) / 3.0)))) + ((v5 - (((v1 + v3) + v5) / 3.0)) * (v5 - (((v1 + v3) + v5) / 3.0)))));
end
Wolfram Language
ClearAll[mwCalculate];
mwCalculate[v1_, v2_, v3_, v4_, v5_, v6_] := (((((v1 - (((v1 + v3) + v5) / 3.0)) * (v2 - (((v2 + v4) + v6) / 3.0))) + ((v3 - (((v1 + v3) + v5) / 3.0)) * (v4 - (((v2 + v4) + v6) / 3.0)))) + ((v5 - (((v1 + v3) + v5) / 3.0)) * (v6 - (((v2 + v4) + v6) / 3.0)))) / ((((v1 - (((v1 + v3) + v5) / 3.0)) * (v1 - (((v1 + v3) + v5) / 3.0))) + ((v3 - (((v1 + v3) + v5) / 3.0)) * (v3 - (((v1 + v3) + v5) / 3.0)))) + ((v5 - (((v1 + v3) + v5) / 3.0)) * (v5 - (((v1 + v3) + v5) / 3.0)))));
Continue in mathematical software
The downloaded file includes your current inputs and first calculated result. It is created locally.
Floating-point answers can differ slightly by language, compiler and processor. Compare within a suitable tolerance rather than assuming every decimal representation will be identical.
Supporting sourcesAcademic referencesPrimary standards, textbooks and complete citations
Standards, reading and academic references
Use the calculator as the worked interaction, then consult the primary standards and academic textbooks listed below. MW SysArc links to the original sources; the explanation on this page is original and does not reproduce them.
Introductory Statistics 2e
Read the free OpenStax statistics textbookCite this book
- APA 7
- Illowsky, B., & Dean, S. (2023). Introductory statistics 2e. OpenStax. https://openstax.org/books/introductory-statistics-2e/pages/1-introduction
- MLA 9
- Illowsky, Barbara, and Susan Dean. Introductory Statistics 2e. OpenStax, 2023, https://openstax.org/books/introductory-statistics-2e/pages/1-introduction.
- Chicago author-date
- Illowsky, Barbara, and Susan Dean. 2023. Introductory Statistics 2e. Houston, TX: OpenStax. https://openstax.org/books/introductory-statistics-2e/pages/1-introduction.
OpenStax entries are free to read online. Follow the licence shown on each linked source before redistributing or adapting its content.
Reuse the page responsiblyCite this pageAPA, MLA, Chicago, Harvard, BibTeX and RIS
These formats cite this calculator page itself. They are separate from the academic references above, which support the mathematical method and terminology.
APA 7
MW SysArc. (2026, July 21). Linear Regression Calculator. MW SysArc Tools. https://math.mwsysarc.com/statistics/linear-regression-three-pairs
MLA 9
MW SysArc. “Linear Regression Calculator.” MW SysArc Tools, 21 July 2026, https://math.mwsysarc.com/statistics/linear-regression-three-pairs. Accessed 31 Aug. 2026.
Chicago 17
MW SysArc. “Linear Regression Calculator.” MW SysArc Tools. Published July 21, 2026. Accessed August 31, 2026. https://math.mwsysarc.com/statistics/linear-regression-three-pairs.
Harvard
MW SysArc (2026) ‘Linear Regression Calculator’, MW SysArc Tools. Published 21 July 2026. Available at: https://math.mwsysarc.com/statistics/linear-regression-three-pairs (Accessed: 31 August 2026).
BibTeX and RIS records
BibTeX
@misc{mwsysarc_linear_regression_three_pairs_2026,
author = {{MW SysArc}},
title = {Linear Regression Calculator},
howpublished = {MW SysArc Tools},
year = {2026},
url = {https://math.mwsysarc.com/statistics/linear-regression-three-pairs},
note = {Published July 21, 2026; accessed August 31, 2026}
}RIS
TY - ELEC
AU - MW SysArc
TI - Linear Regression Calculator
T2 - MW SysArc Tools
PY - 2026
DA - 2026-07-21
Y2 - 2026-08-31
UR - https://math.mwsysarc.com/statistics/linear-regression-three-pairs
N1 - Published July 21, 2026
ER -Clear answers
Frequently asked questions
What does the Linear regression do?
Fit a least-squares line to three paired observations.
How does the Linear regression work?
The calculator applies slope=Σdx·dy/Σdx²; intercept=ȳ−slope·x̄. Least squares chooses the line minimizing summed squared vertical residuals.
What can I learn from the Linear regression?
It connects the mathematical rule to your chosen numbers and shows each calculation step. Change one input at a time to see how the result responds.
Does MW SysArc receive or store what I enter?
No. The calculation runs locally in your browser. MW SysArc does not receive or store your calculation inputs.
How should I use the result?
Use the steps to understand the method, then verify important school or professional work using the notation and rounding rules required in your setting.
Last reviewed . Calculations tested .