Covariance & regression 2.0
About this app
Rebuild 2.0 (preview): covariance as rectangle areas around the centroid, switchable units, least squares as real squares, both regression lines.
Least squares and units
The regression line ŷ = a + b·x is the line with the smallest sum of squared vertical distances Σeᵢ², where eᵢ = yᵢ − ŷᵢ. The solution is b = sₓᵧ / sₓ² and a = ȳ − b·x̄. Covariance and slope carry units: converting power from horsepower to kW changes their values, but not the relationship itself. The correlation r and the coefficient of determination R² = r² are unit-free. In z-scores, with sₓ = sᵧ = 1, both covariance and slope equal r.
Three views
The covariance view shows the rectangle areas (xᵢ − x̄)(yᵢ − ȳ) around the centroid and works out the balance of same-sign and opposite-sign contributions. In the least squares view you pull on a line yourself; the errors appear as actual squares and the app reports how far your sum is above the minimum. The two-lines view shows the regression of y on x, the regression of x on y and the SD line. Six data sets are available, including engine data, “No trend” and a leverage point.
What to look for
In the least squares view, start with the horizontal line at ȳ and try to shrink the squares by hand before snapping to the minimum. Switch the units from rpm · PS to 1000 rpm · kW and to z-scores: the picture stays the same, covariance and slope change their values, r and R² do not. The two-lines view shows regression to the mean: the y-on-x line rises only r·sᵧ per sₓ, flatter than the SD line.
Frequently asked questions
- What does least squares minimise?
- Least squares minimises the sum of squared vertical distances between the data points and the line, Σ(yᵢ − ŷᵢ)². The solution has slope b = sₓᵧ / sₓ² and passes through the centroid (x̄, ȳ). Any other line has a larger sum of squared errors.
- Why are there two regression lines?
- Regressing y on x minimises vertical distances, regressing x on y minimises horizontal ones. This gives two different lines, both passing through the centroid. They only coincide when all points lie on one line, that is when |r| = 1.
- Does correlation change when you convert units?
- No. If a variable is converted linearly to another unit, covariance and slope change because they carry units. The correlation r divides by sₓ · sᵧ and therefore stays the same, as does the coefficient of determination R².
- What can I try in this app?
- You switch between the covariance, least squares and two-lines views, pick one of six data sets, and add or delete points. Units can be toggled between original values, converted values and z-scores. The app is a rebuild of the covariance app and is available as a preview.
Subject: Probability & statistics
More from Probability & statistics
- Curve-fitting playground
- Galton board
- Covariance & Regression
- Coin flips: law of large numbers
- Spray a Point Cloud
- Regression & R²
- Monty Hall problem
A VisuApp by heyprof: interactive, free in your browser, no sign-up. What is a VisuApp? · All apps