Values are sorted along both sides. Each square is the gap between two values. Darker squares are bigger gaps. The mean absolute difference is the average square.
small → large gap
Every pair on the number line
Each arc links two values. Taller arcs are wider gaps. Arcs wider than the mean absolute difference are orange.
Step-by-step working
How the mean absolute difference is calculated with your numbers.
Pair
xᵢ
xⱼ
|xᵢ − xⱼ|
How mean absolute difference calculator works
The mean absolute difference calculator works in 4 steps: it lists every pair of values, measures the gap |xᵢ − xⱼ| of each pair, adds the gaps and divides the total by the number of pairs. The result is the mean absolute difference (MD), the average distance between 2 values drawn from the data set, with no center such as the mean or median involved.
PairMatch every value with every other value: n(n − 1) ordered pairs.
GapMeasure |xᵢ − xⱼ| for each pair.
AddSum all gaps.
DivideDivide by n(n − 1), or by n² to include self-pairs.
The calculator reports 7 results: MD, the number of values, the number of pairs, the relative mean difference (RMD), the Gini coefficient, the largest gap and the mean absolute deviation (MAD) from the mean. The example data set 2, 4, 7, 11 has 6 distinct pairs and MD = 5.
Each arc joins 2 values and carries the gap between them: 2, 5, 9, 3, 7, 4. The gaps add to 30, and each gap counts twice in the ordered-pair formula.
Mean absolute difference calculator formula
The mean absolute difference calculator formula is MD = ΣᵢΣⱼ|xᵢ − xⱼ| ÷ n(n − 1): the sum of the gaps over all ordered pairs of distinct values, divided by the number of those pairs.
MD=ΣᵢΣⱼ|xᵢ − xⱼ|n(n − 1)
MD: mean absolute difference, the average gap between 2 values.
ΣᵢΣⱼ: a double sum over every i and every j, with i ≠ j.
| |: absolute value. The gap from 7 to 2 and from 2 to 7 both count as 5.
xᵢ: the first value of the pair.
xⱼ: the second value of the pair.
n(n − 1): the number of ordered pairs of distinct values, 12 for n = 4.
The mean absolute difference measures spread between values. The mean absolute deviation measures spread around the arithmetic mean (x̄ = 6 for the example). Both describe statistical dispersion in the units of the data.
Mean absolute difference calculator technique
The fastest mean absolute difference calculator technique is the sorted-weights shortcut: sort the values, multiply the i-th smallest value by 2i − n − 1, and add the products to get the sum of gaps over all unordered pairs. The shortcut needs n multiplications instead of n(n − 1) ÷ 2 subtractions.
i
x₍ᵢ₎
2i − n − 1
(2i − n − 1) × x₍ᵢ₎
1
2
-3
-6
2
4
-1
-4
3
7
1
7
4
11
3
33
Σ
30 → MD = 2 × 30 ÷ 12 = 5
For 1,000 values the shortcut takes 1,000 multiplications, while the pair-by-pair method takes 499,500 subtractions.
The pair grid
Row value minus column value, without the sign. The diagonal holds the 4 self-pairs (gap 0). The other 12 cells add to 60, and 60 ÷ 12 = 5.
1 check that catches mistakes
MAD ≤ MD (all pairs) ≤ MD (distinct pairs) ≤ 2 × MAD holds for every data set. The example gives 3 ≤ 3.75 ≤ 5 ≤ 6.
A mean absolute difference outside the MAD to 2 × MAD range signals an arithmetic error.
Frequently asked questions
How do you calculate the mean absolute difference?
Calculate the mean absolute difference by finding the gap |xᵢ − xⱼ| for every pair of values and averaging the gaps: MD = ΣᵢΣⱼ|xᵢ − xⱼ| ÷ n(n − 1). For 2, 4, 7, 11, the 6 gaps are 2, 5, 9, 3, 7 and 4, they add to 30, and MD = 2 × 30 ÷ 12 = 5.
What is the mean absolute difference of 2, 4, 7, 11?
The mean absolute difference of 2, 4, 7, 11 is 5 for distinct pairs and 3.75 for all pairs including self-pairs. The 12 ordered gaps add to 60. 60 ÷ 12 = 5, and 60 ÷ 16 = 3.75. The mean absolute deviation of the same data is 3.
Can the mean absolute difference be larger than the range?
No, the mean absolute difference is never larger than the range. Every pairwise gap is at most the largest value minus the smallest value, so the average gap is at most the range. The data set 2, 4, 7, 11 has a range of 9 and a mean absolute difference of 5.
How do you get the Gini coefficient from the mean absolute difference?
Get the Gini coefficient by dividing the all-pairs mean absolute difference by twice the mean: G = MD ÷ (2 × x̄). For 2, 4, 7, 11, MD (all pairs) = 3.75 and the mean is 6, so G = 3.75 ÷ 12 = 0.3125. A Gini coefficient of 0 means perfect equality.
Is mean absolute difference the same as mean absolute deviation?
No, the mean absolute difference is not the same as the mean absolute deviation. Mean absolute deviation measures how far each value sits from the mean. Mean absolute difference measures how far apart the values sit from each other, pair by pair, with no center involved.
Should I count pairs with replacement or without?
Count pairs without replacement, n × (n − 1) pairs, for a sample, and count pairs with replacement, n² pairs, to match the Gini coefficient formula. Pairs with replacement include each value compared with itself. Those zero gaps give a smaller result: 3.75 instead of 5 for 2, 4, 7, 11.
How is the mean absolute difference related to the Gini coefficient?
The Gini coefficient equals half the relative mean difference: G = MD ÷ (2 × x̄), with MD counted over all pairs including self-pairs. The calculator shows the Gini coefficient when all values are 0 or positive and the mean is above 0.
How does the mean absolute difference compare with the MAD?
The mean absolute difference always lands between 1× and 2× the MAD measured from the mean. The gap between 2 values never exceeds the sum of their distances from the mean, which caps the ratio at 2×. A data set of 2 values gives exactly 2×, and normally distributed data gives about 1.4×.