Calculating the absolute minimum (average) deviation If a set of numbers were: $\{0;1;2\}$ the mean would be equal to $1$ and so the absolute average deviation would equals $1$: $\frac {(1-0)+(1-1)+(2-1)}3=1$
But if the set of numbers were: $\{0;2;2\}$ the mean would be $1.333\dots$ and so the absolute average deviation would equals $0.888\dots$: $\frac {(1.333\dots-0)+(2-1.333\dots)+(2-1.333\dots)}3=0.888\dots$
But this does not equal the absolute minimum possible average deviation.
If you don't use the mean and use the value $2$ instead of the minimum absolute average deviation would equal $0.666\dots$ which is even smaller: $\frac{(2-0)+(2-2)+(2-2)}3=0.666\dots$
What is the formula to work out this deviation? I want to find the value that is used instead of mean.
 A: So you are calculating the deviation of $\bar a$ from $a_1, \ldots, a_n$ via 
$$ \def\dev{\mathop{\rm dev}}\dev(\bar a) = \frac 1n \sum_{i=1}^n \def\abs#1{\left|#1\right|} \abs{\bar a - a_i} $$
Let's suppose the $a_i$ are ordered via $a_1 \le a_2 \le \cdots \le a_n$. If we have $\bar a$, $\bar a'$ with $a_j \le \bar a, \bar a' \le a_{j+1}$, then
for each $i\le j$
$$ 
 \abs{\bar a - a_i} = \bar a - a_i = \bar a' - a_i + \bar a - \bar a'
         = \abs{\bar a' - a_i} +\bar a - \bar a' $$
and for $i > j$
$$  \abs{\bar a - a_i} =  a_i-\bar a = a_i - \bar a' - \bar a + \bar a'
         = \abs{\bar a' - a_i} -\bar a + \bar a' $$
That is 
$$
\dev \bar a = \dev \bar a' + \frac 1n\bigl(j(\bar a - \bar a') + (n-j)(\bar a' - \bar a)\bigr) = \dev a' + \frac{n - 2j}n(\bar a' - \bar a)$$
That is, if $j < \frac n2$, we can decrease the deviation by increasing $\bar a$ to some larger $\bar a'$, if $j > \frac n2$, we can decrease the deviation by decreasing the "average" value.
That is, we have a minimum, when $j = \frac n2$, that is when the same number of values $a_i$ lies to the left of $\bar a$ as to the right, that is, the mean has to be replaced by the median.
