Math calculator

Distance Correlation Calculator

Dependence of any shape.

Any dependence

Forty-four days of daily mean temperature and building energy use. Pearson’s r is −0.000147 — zero to four decimal places, the sort of result that ends an investigation. Distance correlation is 0.490532 with a permutation p-value of 0.0010. The relationship is a U: heating below the comfort band, cooling above it, least energy in the middle. Every coefficient built on a straight line is blind to this, and the plot below makes the reason visible immediately.

44 pairs · 2,000 permutations

Distance correlation 0.490532, Pearson -0.000147

A correlation coefficient finds nothing here and this does: p = 0.0010 against the permutation null. The dependence is real and it is not linear, which is the one situation where the two measures have to be read differently.

Distance correlation

0.490532

0 only under independence

Pearson r

-0.000147

linear relationships only

Permutation p

0.0010

2,000 shuffles

Distance covariance

7.26414

dVar 6.6530 and 32.9624

The scatter

1502002500102030temperature °Cenergy kWh

Plotting the data is the cheapest version of this test and should always come first. Distance correlation is what to reach for when there are more pairs than you can plot, or when a number is needed rather than a picture.

Distance correlation is zero if and only if the two variables are independent — a property no correlation coefficient has. It is also unchanged by shifting or rescaling either variable, which the verification suite asserts on sixty generated pairs alongside symmetry in the two arguments.

The sample statistic is biased upward and never reaches zero at a finite sample size, so a value near 0.2 on a few dozen points means nothing on its own. Read the p-value, not the coefficient.

Sees any dependence Zero only under independence Pearson shown alongside Says nothing about shape

What this tool shows

On the shipped preset Pearson’s r is −0.000147 — zero to four decimal places — and the distance correlation is 0.490532 with a permutation p-value of 0.0010. The relationship is a U: heating below the comfort band, cooling above it. A correlation coefficient measures how well a straight line fits, so a perfect symmetric curve scores zero. Distance correlation is zero if and only if the two variables are independent, which no correlation coefficient can say.

  • Distance correlation and distance covariance, computed from the doubly centred distance matrices
  • A permutation test, because there is no usable closed-form null distribution
  • Pearson’s r on the same data, so the gap between them is the output rather than a footnote
  • A scatter plot of the pairs, which is the cheapest version of the same check
  • Presets covering a curve, a straight line, genuine independence, and dependence that lives in the spread
  • Why the sample statistic never reaches zero, and why that makes the p-value the thing to read
Any dependence Zero only under independence Pearson alongside Permutation tested

It detects dependence. It does not describe its shape.

Updated 13 September 2026 · Works in any browser, no installation

Distance correlation measures dependence of any kind between two variables, and it is zero if and only if they are independent. Pearson’s r measures how well a straight line fits, so it is zero for a perfect curve and zero for a relationship that lives in the spread rather than the average. Both numbers are correct about different things, and reporting only the first is how a real relationship gets written off.

At a glance

Formula shown
Build the n×n matrix of pairwise distances for each variable, doubly centre both by subtracting row means, column means and adding back the grand mean, then take the average of their elementwise product. That is the squared distance covariance. Divide by the square root of the product of the two distance variances to get dCor, which lies in 0 to 1. Zero occurs if and only if the variables are independent — a property no correlation coefficient has.
Scenario support
Screening for relationships before choosing a model, checking whether a variable dismissed by a correlation matrix deserves a second look, detecting heteroscedasticity in forecast errors or residuals, and feature selection where non-linear predictors would otherwise be discarded.
Educational estimate
Planning support from the values you enter — not professional advice.

The correlation is not wrong, it is answering a different question

The shipped preset is chosen so the two numbers are as far apart as they can get, which makes the distinction legible in a way a worked definition does not.

Pearson’s r is −0.000147. Four decimal places of nothing. In a correlation matrix that cell would end the investigation.

Distance correlation is 0.490532, p = 0.0010. Same forty-four pairs, same two columns.

Both are correct. The relationship really does have no linear component — energy falls then rises, and the two halves cancel exactly. Pearson reports that faithfully.

The mistake is reading “no linear relationship” as “no relationship”, which is what a correlation matrix full of near-zero cells quietly invites.

Dependence in the spread, not in the average

The curved case is the famous one. The fourth preset is the version that shows up far more often in real data and is far easier to miss.

Forty orders with their forecast errors. Pearson is −0.007635. Errors are centred on zero at every order size, so there is no bias to find.

Distance correlation is 0.462498, p = 0.0065. The spread of the errors grows with order size: big orders are not forecast too high or too low, they are forecast badly.

A correlation measures a relationship in the mean. It has no machinery for a relationship in the variance, and reports the correct answer to a question nobody asked.

Which makes this a practical residual check. Run it on fitted values against residuals and a significant result means the constant-variance assumption is wrong, without needing to guess the form beforehand.

Zero if and only if independent

This is the property that makes the measure worth the computational cost, and it is stronger than it first sounds.

Pearson’s r is zero under independence. The converse fails: r can be zero when the variables are as dependent as it is possible to be.

Distance correlation is zero only under independence. A non-zero population value means the variables are dependent somehow, whatever the shape.

So a distance correlation of zero rules out every relationship, not merely the straight ones — which is a stronger negative result than anything a correlation matrix can give.

The price is that it says nothing about shape or direction. There is no such thing as a negative distance correlation, and 0.49 does not tell you the relationship was a U rather than a funnel. That is what the plot is for.

The statistic never reaches zero

The third preset is genuinely independent data, and the number it produces is the reason this page prints a p-value rather than a verdict.

Two unrelated variables over thirty-six observations give 0.213023. Not 0.02. Not 0.005.

The sample statistic is biased upward, because the doubly centred distance matrices retain a positive expected product even under independence.

The bias shrinks with sample size but never vanishes, so there is no fixed threshold that separates dependence from noise at every n.

The permutation test is what makes the number readable. Shuffle one variable against the other, recompute, and see how often chance beats the observed value: 0.8586 here, which is as unremarkable as it gets.

What it costs to compute

The reason distance correlation is not simply the default is arithmetic, and it is worth knowing before reaching for it on a large table.

It builds two n by n distance matrices. That is O(n²) in both time and memory, against O(n) for a correlation coefficient.

The permutation test multiplies that by the number of shuffles. Two thousand permutations on a thousand points is two billion distance operations.

A few thousand points is the practical ceiling in a browser, which is why the permutation count is a control on this page rather than a fixed value.

For a first pass, plot the data. A scatter plot finds every one of these cases for free. Distance correlation earns its cost when there are more pairs than anyone will plot, or when a defensible number is needed rather than a picture.

On linear data it agrees, which is the practical argument

An objection to computing a second measure is that it introduces a second answer. On linear data it does not.

The straight-line preset gives Pearson 0.997091 and distance correlation 0.997138. A difference in the fifth decimal place.

The two are not equal in general, and for bivariate normal data the distance correlation is slightly the smaller of the two by a known function of r — but they agree closely enough that nothing is lost.

So running both is not a choice between answers. It is a check that costs nothing when the correlation was right and pays for itself when it was not.

The gap between them is the diagnostic. Close together means linear; far apart means look at the plot.

Reporting a distance correlation

Four items, and the first is the one that makes the number mean anything at all.

Give the permutation p-value and the number of permutations. The coefficient alone cannot be read against a fixed scale, because its baseline moves with n.

Give Pearson’s r beside it. The gap between the two is the finding; either number alone is half a sentence.

Give the sample size. A distance correlation of 0.3 on forty points and one on four thousand are not comparable quantities.

And describe the shape from the plot, not from the coefficient. Distance correlation detects dependence and says nothing about what kind, which is a limitation rather than a technicality.

Sources and methodology

References for the measure and its test.

Method. The distance matrices are doubly centred and combined exactly as defined, with no approximation and no subsampling, so the statistic is the population definition evaluated on the sample rather than an estimate of it. The permutation test shuffles one variable against the other with a seeded generator, which makes the p-value reproducible: the same data gives the same answer on every run. The verification suite asserts the properties that characterise the measure rather than transcribing values — it stays in 0 to 1, it is symmetric in its two arguments, and shifting or rescaling either variable leaves it unchanged, each on sixty generated pairs. It also asserts the two cases that separate this from a correlation: a perfect line gives exactly 1, and y = x² over a symmetric range gives a Pearson r of exactly zero with a distance correlation near 0.49 and a permutation p-value below 0.01. That engine is verified on every change against 90 assertions. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

Correlation CoefficientReports Pearson, Spearman and Kendall together with the scatter plot, and ships Anscombe's quartet built in — four datasets with an identical r of 0.816 that Spearman tells apart.
Spearman CorrelationComputes rho correctly as Pearson on the midranks, and beside it the 6Σd²/(n(n²−1)) shortcut every textbook teaches — which is exact only when no two values tie, and overstates the correlation when they do.
Partial CorrelationPartial and semi-partial correlation with any number of controls, computed from residuals, with the raw correlation and the share each control already explains.
Multiple CorrelationMultiple R with adjusted R-squared, an F test, and a per-predictor table of simple, partial and unique contributions beside the variance inflation factors.
Covariance MatrixSample covariance and correlation matrices with eigenvalues, determinant and condition number, so redundancy spread across several variables cannot hide from a pairwise scan.
Linear RegressionThe least-squares line with r and r² — and the regression of x on y beside it, because those are two different lines rather than one line rearranged.

More in Math, or browse all calculators.

Educational use disclaimer

An educational tool. Distance correlation detects dependence without describing it — there is no sign, no direction, and no indication of shape, so the plot remains necessary. The sample statistic is biased upward and never reaches zero, so a small value on a small sample is the baseline rather than weak evidence; the permutation p-value is what makes it readable.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (5 updates)

Published 13 September 2026

  1. Published distance correlation with a seeded permutation test and Pearson r on the same data.
  2. Shipped a U-shaped preset where Pearson is -0.000147 and the distance correlation is 0.490532.
  3. Added a preset where the dependence lives in the spread rather than the mean.
  4. Documented the upward bias that keeps the sample statistic away from zero under independence.
  5. Made the permutation count a visible control rather than a hidden default.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.