2D Correlation and Covariance Visualizer

Explore how paired data, covariance, Pearson correlation, rank correlation, regression, and residuals describe relationships between two variables.

What to compare

Covariance keeps the original units and tells direction. Pearson r standardizes covariance into a value from -1 to 1. Spearman rho uses ranks, so it is less tied to straight-line scale.

Covariance: signed joint movement Pearson r: standardized linear strength Regression: fitted line Residuals: vertical errors Ellipse: covariance shape Ranks: monotonic relationship

Mathematical Background

Covariance

Covariance averages the products of each point's deviations from the x and y means. Positive covariance means points often sit in the same-side mean quadrants. Negative covariance means points often sit in opposite-side quadrants.

cov(x,y) = sum((x_i - mean(x))(y_i - mean(y))) / (n - 1)

Pearson Correlation

Pearson r divides covariance by the two sample standard deviations. This removes units and makes the result easier to compare across datasets.

r = cov(x,y) / (std(x) std(y))

Regression and Residuals

The least-squares line minimizes the sum of squared vertical residuals. Strong linear correlation usually produces smaller residual spread, but outliers can strongly influence the fitted line.

Rank Correlation

Spearman rho computes Pearson correlation on ranks instead of raw values. It responds to monotonic order even when the relationship is not well described by a straight line.