Linear Regression Calculator
Paste your X and Y values to compute the best-fit regression line.
Result
How it is calculated
Enter the x values and the y values as two lists, separated by spaces, commas or semicolons. They must have the same length, at least two pairs, and be plain numbers with a decimal point (a decimal comma would be read as a separator and the lists would no longer match). With n pairs the tool computes slope = (nΣxy − ΣxΣy) ÷ (nΣx² − (Σx)²), intercept = (Σy − slope × Σx) ÷ n and r = (nΣxy − ΣxΣy) ÷ √[(nΣx² − (Σx)²)(nΣy² − (Σy)²)], and R² = r². All values show four decimals. If every x is identical there is no unique line and no result appears. If every y is identical the line is flat and r and R² are reported as 0.
Worked example
Five points: x = 1, 2, 3, 4, 5 and y = 2.1, 3.9, 6.2, 7.8, 10.1. Sums: Σx = 15, Σy = 30.1, Σx² = 55, Σxy = 110.2. Slope = (5 × 110.2 − 15 × 30.1) ÷ (5 × 55 − 15²) = 99.5 ÷ 50 = 1.99. Intercept = (30.1 − 1.99 × 15) ÷ 5 = 0.05. The line is y = 1.9900x + 0.0500, with r = 0.9987 and R² = 0.9973, so almost all the variation in y is explained by x.
Common mistakes
- Typing decimals with a comma (1,5), which is treated as a list separator and splits one number into two; use a dot.
- Listing x and y in different orders or lengths, so the pairs are misaligned; a single stray non-numeric token makes the whole input invalid.
- Swapping x and y; the regression of y on x is a different line from x on y, and only r and R² stay the same.
- Reading a high R² as proof of cause, or extrapolating far outside the range of the x data.
- Expecting a meaningful R² when all y values are equal; the fit is flat, but the tool then reports r and R² as 0.
About this calculator
A linear regression calculator fits a straight line y = mx + b to a set of (x, y) data points by minimizing the sum of squared vertical distances between the line and the points — the method of least squares. The slope is m = (nΣxy − ΣxΣy) / (nΣx² − (Σx)²) and the intercept is b = (Σy − mΣx) / n; the calculator also reports the Pearson correlation coefficient r and the coefficient of determination R², which tells you what fraction of the variance in y is explained by x.
This is the same math behind the trendline feature in Excel or Google Sheets, and it underpins everything from stock-price trend analysis to lab-instrument calibration curves. Students, scientists, engineers, and analysts use it to quantify a relationship between two variables, forecast a y value for a new x, and judge — via R² — how reliable that forecast actually is.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
When x values are years such as 2015 to 2024, the intercept is the value at year zero, which is meaningless and often huge. Subtract the first year from every x so the series reads 0, 1, 2 and so on: the slope stays the same and the intercept becomes the fitted value in your first year. What kind of data do you usually fit, and how many points do you have?