# Writing median rather than mean

I have some code to calculate the mean bias between two arrays.

$$mean_{bias}=\frac{\sum_{i=1}^{n}a_i-b_i}{n}$$

and was hoping to represent the median instead:

$$median_{bias}=Median(a-b)$$

Does something like this hold true? But it's not sorted so index will not be the middle:

$$median_{bias}=\sum_{i=n/2}^{n/2+1}a_i-b_i$$

How can I represent this?

Thanks

• This question does not concern mathematics and would be better suited for TeX - LaTeX Stackexchange. – Brian Mar 28 at 1:08
• I tried there first and was suggested to ask here instead. – Ocean Scientist Mar 28 at 1:14
• I don't understand the question – Jorge Fernández Hidalgo Mar 28 at 1:14
• You can write median bias = median a - median b – Jorge Fernández Hidalgo Mar 28 at 1:15
• The formula only, I can convert it into Tex myself. – Ocean Scientist Mar 28 at 1:18

## 1 Answer

You might be able to write something like this:

$$\begin{gather} bias_{\text{median}} = \frac12\left(\max_i\left\{a_i-b_i \mid \left\lvert\left\{j\mid a_i-b_i > a_j-b_j\right\}\right\rvert < \tfrac n2\right\} \\ \qquad\qquad\qquad\qquad\qquad + \min_i\left\{a_i-b_i \mid \left\lvert\left\{j\mid a_i-b_i < a_j-b_j\right\}\right\rvert < \tfrac n2\right\} \right) \end{gather}$$

This is a way of saying that if $$n$$ is odd, you take the value $$a_i - b_i$$ that partitions the list of values $$a_j - b_j$$ (excluding $$a_i - b_i$$ itself) into two equal sets, one of values less than $$a_i - b_i$$ and one of values greater; and if $$n$$ is even you take the mean of the two values $$a_i - b_i$$ and $$a_{i'} - b_{i'}$$ that partition the list of values $$a_j - b_j$$ (excluding those two values) into two equal sets.

But I think this is a rather horrible expression.

A better way is probably to define some notation of your own, for example,

The notation $$\text{median}(S)$$ represents the median of the set $$S$$,

followed at some later time by an expression such as

$$\text{median} \{a_i - b_i \mid 1 \leq i \leq n\}.$$

• So there isn't a nice way of doing it. Interesting. I agree that the first one does the job, but it's a bit much! I think I will just define that median means median like your suggestion 2. Thanks very much! – Ocean Scientist Mar 28 at 4:12