Regression & Scatter Plot
Fit a line or curve to data using least squares. See R², correlation coefficient, and residuals update in real time. Drag points to explore how data shape affects the fit.
Regression
Drag points to change the data
Properties
| n (points) | -- |
| Equation | -- |
| Slope | -- |
| Intercept | -- |
| R² | -- |
| r | -- |
The Math Behind It
Least Squares
- Goal: minimize the sum of squared residuals — Σ(yi − ŷi)²
- Slope: m = Σ(xi − x̄)(yi − ȳ) / Σ(xi − x̄)²
- Intercept: b = ȳ − m·x̄
- The least squares line passes through (x̄, ȳ)
- Quadratic fit solves a 3×3 normal equation system
Goodness of Fit
- R² = 1 − SSres/SStot — proportion of variance explained
- R² = 1 means a perfect fit; R² = 0 means no linear relationship
- Correlation coefficient: r = ±√R² — sign matches the slope
- Residual = observed − predicted — vertical distance from point to line
- Residuals should be randomly scattered for a good fit
You're crushing it!