Linear Regression Calculator
Fit a straight line to paired X and Y data using ordinary least squares. Enter two equal-length lists and the tool returns the slope, the intercept, and the R-squared value that measures how well the line fits.
What this calculator does
The Linear Regression Calculator estimates your result instantly from the values you enter, using standard statistics formulas. Fit a straight line to paired X and Y data using ordinary least squares. Enter two equal-length lists and the tool returns the slope, the intercept, and the R-squared value that measures how well the line fits. Calculations run in your browser, so nothing you type is sent to a server, and the output is an estimate rather than a certified or official figure.
Result
About Linear Regression Calculator
Paste a list of X values and an equal-length list of Y values, and this calculator fits the best straight line y = mx + b by ordinary least squares. It builds the slope from nΣxy − ΣxΣy over nΣx² − (Σx)², then derives the intercept, and computes the correlation coefficient r to report R².
The two lists must be the same length and contain at least two points, and the X values must vary (a flat X column has no line to fit).
Formula & Mathematical Calculation
Calculation Method
- Compute } d=n × sx2-sx × sx
- Compute } m=(n × sxy-sx × sy) ÷ d, b=(sy-m × sx) ÷ n
- Compute den=Math.sqrt((n × sx2-sx × sx) × (n × sy2-sy × sy)), r=den===0?0:(n × sxy-sx × sy) ÷ den
Calculation Example
Enter X = 1, 2, 3, 4 and Y = 2, 4, 5, 8:
- Slope (m) = 1.9
- Intercept (b) = 0
- R² = 0.9627
The best-fit line reported is y = 1.9x + 0, with R² = 0.9627.
Key Benefits
- Fits the least-squares line and returns slope, intercept, and R-squared together in one step
- Reports R-squared so you can judge how closely the line follows your points
- Checks that the X and Y lists are equal in length and have at least two points before fitting
- Flags data with no variation in X, which has no defined slope; free and browser-based
How to Use this Calculator
-
Enter the X values
Type your independent-variable values into the X values field, comma-separated, e.g. 1, 2, 3, 4. -
Enter the Y values
Type the matching dependent-variable values into the Y values field, keeping the same count and order. -
Calculate
Press Calculate to fit the line. -
Read slope, intercept, and fit
Read the Slope (m), Intercept (b), and R-squared boxes, and the equation shown below them.
Assumptions & Limitations
What the calculation assumes
- Every value you enter is treated as an exact, known amount.
- Any rate or interval you enter is assumed to hold for the whole period unless the form asks for it separately.
- Results use standard published formulas and account only for the values entered above.
- Rounding is applied for display; the underlying calculation uses your full precision.
- Results are returned in the same units you enter, unless the tool states the output unit.
What it does not cover
- Linear Regression Calculator produces a calculated result for reference and learning, not a certified or official measurement.
- Real-world outcomes differ when tolerances, rounding rules or local standards apply.
- Definitions and standards vary by region and change over time; verify the convention that applies to your case.
- Figures are only as accurate as the inputs you supply — check them before acting on the result.
- For work where the result carries real consequences, confirm it against an authoritative source.
Frequently Asked Questions
Free to use, no account needed. Calculations run in your browser, so nothing you type is sent to a server. Results are estimates — how we build and check our calculators.