Explore how paired data, covariance, Pearson correlation, rank correlation, regression, and residuals describe relationships between two variables.
Current dataset, worked by hand
The values below update with the points above. This tool treats the entered pairs as a sample, so variance and covariance use n − 1. Open the contribution table to inspect every term in the sums.
Covariance keeps the original units and tells direction. Pearson r measures linear association. Enable the optional measures to compare monotonic rank association or more general nonlinear dependence.
Start with the arithmetic means. A deviation records how far a value lies from its variable's center. Deviations above the mean are positive; deviations below it are negative.
\[\bar{x}=\frac{1}{n}\sum_{i=1}^{n}x_i,\qquad \bar{y}=\frac{1}{n}\sum_{i=1}^{n}y_i\]
\[d_{x,i}=x_i-\bar{x},\qquad d_{y,i}=y_i-\bar{y}\]
Multiply the two deviations for each pair. Same-sign deviations contribute positively; opposite-sign deviations contribute negatively. Their sum is divided by n − 1 because the displayed calculation estimates covariance from a sample.
\[\widehat{\sigma}_{xy}=\widehat{\operatorname{Cov}}(X,Y)=\frac{\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})}{n-1}\]
Covariance has compound units: if x is measured in hours and y in euros, covariance is measured in hour-euros. Its sign is directly interpretable, but its magnitude depends on both scales.
Sample standard deviations measure the separate spread of x and y. Dividing covariance by both spreads removes units. Pearson's r therefore always lies between −1 and 1 when both variables vary.
\[\widehat{\sigma}_x=\sqrt{\frac{\sum_{i=1}^{n}(x_i-\bar{x})^2}{n-1}},\qquad \widehat{\sigma}_y=\sqrt{\frac{\sum_{i=1}^{n}(y_i-\bar{y})^2}{n-1}}\]
\[r=\frac{\widehat{\sigma}_{xy}}{\widehat{\sigma}_x\widehat{\sigma}_y}=\frac{\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})}{\sqrt{\sum_{i=1}^{n}(x_i-\bar{x})^2\sum_{i=1}^{n}(y_i-\bar{y})^2}}\]
A value near zero means little linear association, not necessarily no relationship. The curved preset demonstrates that distinction.
The fitted line predicts y from x. Its slope is joint variation divided by x variation. Each residual is the observed y minus the fitted y; least squares chooses the line that minimizes their squared sum.
\[\hat{y}_i=b_0+b_1x_i,\qquad b_1=\frac{\widehat{\sigma}_{xy}}{\widehat{\sigma}_x^2}=\frac{\sum d_{x,i}d_{y,i}}{\sum d_{x,i}^2},\qquad b_0=\bar{y}-b_1\bar{x}\]
\[e_i=y_i-\hat{y}_i,\qquad \mathrm{SSE}=\sum_{i=1}^{n}e_i^2,\qquad R^2=1-\frac{\mathrm{SSE}}{\sum_{i=1}^{n}(y_i-\bar{y})^2}\]
Replace raw x and y values with their ranks, assigning tied observations their average rank, then apply the Pearson formula to those ranks. When enabled, the extra plot shows every observation at \((R_{x,i},R_{y,i})\), so the line belongs to rank space—not the original measurement scale. This measures monotonic ordering rather than specifically straight-line fit.
\[R_{x,i}=\operatorname{rank}(x_i),\qquad R_{y,i}=\operatorname{rank}(y_i),\qquad \bar R_x=\frac{1}{n}\sum_{i=1}^{n}R_{x,i},\quad \bar R_y=\frac{1}{n}\sum_{i=1}^{n}R_{y,i}\]
\[\rho_s=\frac{\sum_{i=1}^{n}(R_{x,i}-\bar R_x)(R_{y,i}-\bar R_y)}{\sqrt{\sum_{i=1}^{n}(R_{x,i}-\bar R_x)^2}\sqrt{\sum_{i=1}^{n}(R_{y,i}-\bar R_y)^2}}=\frac{\widehat{\sigma}_{R_xR_y}}{\widehat{\sigma}_{R_x}\widehat{\sigma}_{R_y}}\]
\[\text{For a tie occupying sorted positions }a,\ldots,b:\qquad R=\frac{a+b}{2}\]
\[\text{With no ties only:}\qquad d_i=R_{x,i}-R_{y,i},\qquad \rho_s=1-\frac{6\sum_{i=1}^{n}d_i^2}{n(n^2-1)}\]
Concrete difference: for \((1,1),(2,2),(100,3)\), Pearson sees the very large x-gap from 2 to 100 and gives \(r\approx0.87\). Spearman converts the coordinates to \((1,1),(2,2),(3,3)\), ignores that gap, and gives \(\rho_s=1\) because the ordering is perfectly increasing.
The rank plot can resemble the original scatter for an already straight, monotonic dataset. It changes for nonlinear monotonic patterns, uneven spacing, outliers, and ties. The familiar shortcut \(1-6\sum d_i^2/[n(n^2-1)]\) is exact only when there are no tied ranks, so the tool uses Pearson correlation of average ranks instead.
Compare every unordered pair of observations. A pair is concordant when x and y change in the same direction, discordant when they change in opposite directions, and tied when one coordinate does not change. Tau-b corrects the denominator for ties.
\[\tau_b=\frac{C-D}{\sqrt{(C+D+T_x)(C+D+T_y)}}\]
Here \(C\) and \(D\) are concordant and discordant pair counts; \(T_x\) and \(T_y\) count pairs tied only in x or only in y. Values range from −1 to 1.
Distance correlation starts from every pairwise distance, double-centers both distance matrices, and compares them. Unlike Pearson correlation, it can detect curved and other non-monotonic dependence.
\[A_{ij}=|x_i-x_j|-\bar{a}_{i\cdot}-\bar{a}_{\cdot j}+\bar{a}_{\cdot\cdot},\qquad B_{ij}=|y_i-y_j|-\bar{b}_{i\cdot}-\bar{b}_{\cdot j}+\bar{b}_{\cdot\cdot}\]
\[\mathcal{V}_n^2(X,Y)=\frac{1}{n^2}\sum_{i=1}^{n}\sum_{j=1}^{n}A_{ij}B_{ij},\qquad \mathcal{R}_n=\sqrt{\frac{\mathcal{V}_n^2(X,Y)}{\sqrt{\mathcal{V}_n^2(X,X)\mathcal{V}_n^2(Y,Y)}}}\]
The tool uses this non-negative, biased sample estimator. It ranges from 0 to 1 and does not encode a positive or negative direction.
Use the sample formulas above when the entered observations are a subset used to learn about a larger population. If the points are the entire population, covariance and variance instead divide by n:
\[\sigma_{xy}=\frac{1}{n}\sum_{i=1}^{n}(x_i-\mu_x)(y_i-\mu_y)\]
Pearson correlation is unchanged when covariance and both variances consistently use the same convention, because the common denominator cancels.
The covariance matrix collects both marginal variances and the shared covariance. Its eigenvectors point along the ellipse's principal directions, while its eigenvalues are the variances along those directions.
\[\widehat{\boldsymbol{\Sigma}}=\begin{bmatrix}\widehat{\sigma}_x^2&\widehat{\sigma}_{xy}\\\widehat{\sigma}_{xy}&\widehat{\sigma}_y^2\end{bmatrix},\qquad \widehat{\boldsymbol{\Sigma}}\mathbf{v}_j=\lambda_j\mathbf{v}_j\]
\[\text{two-standard-deviation semi-axes:}\qquad a=2\sqrt{\lambda_1},\quad b=2\sqrt{\lambda_2}\]
For a bivariate normal distribution, a two-standard-deviation covariance ellipse encloses about 86.5% of the distribution. A 95% probability ellipse requires scaling by \(\sqrt{\chi^2_{2,0.95}}\approx2.448\), not by 2.