Mathematics
Linear regression and correlation calculator
Fit a least-squares line with an intercept, inspect Pearson correlation and R², and see every fitted value and residual.
The example values can be changed. Press Calculate to update the result; you can download it as TXT or CSV and collect scenarios in this tab. JSON, HTML and TXT downloads keep your inputs, the statistical result and the calculation steps shown. Automatic recalculation after editing is off unless you switch it on. Nothing is saved, imported or sent automatically. For straight-line interpolation, enter exactly two x:y pairs with different x values. Use x for evaluation of the fitted line between the two x values; outside that interval the same calculation is extrapolation. Example: points=0:0;10:100 and x=2.5 gives y=25 under the straight-line assumption. Keep both x values in the same units and both y values in the same units. With more than two pairs this tool fits a least-squares line.
Result
Formula / calculation:
Enter pairs as x:y separated by semicolons, for example 0:1;1:3;2:5. At least two pairs, up to 100 observations and 400 input characters; absolute numeric values at most 1e12. Decimal points in UK, decimal commas in DE; no grouping separators or silently discarded entries. All x values equal makes the slope undefined and is refused. If y is constant, r and R² are undefined rather than zero. Values use floating-point arithmetic with centered sums and compensated summation. The fitted value at your chosen x is algebraic evaluation, not a forecast or uncertainty interval. Correlation does not establish causation; nonlinear relationships can have low linear correlation. Current result TXT/CSV and all-component CSV require explicit clicks; no saving or sending automatically. Nonzero intermediate squares or variance that underflow are refused. Own chart SVG: original component data, up to 100 observations. Regression shows circles and the fitted line only over observed x; variance shows10equal-width count bins, final bin includes maximum, constant data use a symmetric expanded range. Tick labels use5significantdigits, SVGgeometry6decimals; full values remain in the record. No causation, prediction, density or normality proof.
Decimal results are approximate. Inputs stay in this browser tab.
How it works
Centered sums, compensated summation and explicit variance divisor or least-squares fit; floating-point components are shown below. Enter pairs as x:y separated by semicolons, for example 0:1;1:3;2:5. At least two pairs, up to 100 observations and 400 input characters; absolute numeric values at most 1e12. Decimal points in UK, decimal commas in DE; no grouping separators or silently discarded entries. All x values equal makes the slope undefined and is refused. If y is constant, r and R² are undefined rather than zero. Values use floating-point arithmetic with centered sums and compensated summation. The fitted value at your chosen x is algebraic evaluation, not a forecast or uncertainty interval. Correlation does not establish causation; nonlinear relationships can have low linear correlation. Current result TXT/CSV and all-component CSV require explicit clicks; no saving or sending automatically. Nonzero intermediate squares or variance that underflow are refused.
Worked example
With these example values the calculator gives the result below. You can change any value in the form above.
Inputs
- Pairs x:y; separate pairs with semicolons (up to 400 characters)
- 0:1;1:3;2:5
- x for evaluation of the fitted line
- 3
Result
- Observation count
- 3
- Mean x
- 1
- Mean y
- 3
- Centered sum of x squares
- 2
- Centered sum of y squares
- 8
- Centered sum of products
- 4
- Line slope a
- 2
- Line intercept b
- 1
- Pearson correlation r
- 1
- R squared
- 1
- Sum of squared residuals
- 0
- Chosen evaluation x
- 3
Frequently asked questions
How do I calculate a least-squares line?
Enter pairs as x:y separated by semicolons, for example 0:1;1:3;2:5. The tool fits a least-squares line with an intercept and shows every fitted value and residual.
How many data points can I enter?
At least two pairs, up to 100 observations and 400 input characters, with absolute values at most 1e12.
Which correlation does it report?
Pearson correlation r and R². If y is constant, r and R² are undefined rather than zero.
What if all x values are equal?
The slope is undefined and the input is refused.
Can I use it for straight-line interpolation?
Yes. Enter exactly two x:y pairs with different x values. Points 0:0;10:100 with x = 2.5 give y = 25.
Does correlation show causation?
No. Correlation does not establish causation, and nonlinear relationships can have low linear correlation. The fitted value is not a forecast or uncertainty interval.
What decimal format applies?
Decimal points in the UK, decimal commas in DE, with no grouping separators.