Explore how paired data, covariance, Pearson correlation, rank correlation, regression, and residuals describe relationships between two variables.
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 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 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))
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.
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.