[Math] Create a Data Set Given Median and Mean

linear algebramedianstatistics

Its a very simple problem to a homework question that I can easily solve, but if time-willing I like to go about it a more elegant way.

So lets say you need to create a set of 5 numbers whose median is m, and whose mean is n. I have specific values, but I'm looking for a general way to do this.

I'm trying to accomplish this by putting it into matrix form and use linear algebra to solve this. Is it possible?

Answer:

median 10, mean 7, 5 numbers. I left 10 out because it was known. And took away from the elegance.

$ \\
\begin{bmatrix}
2 & 1 & 11 & 11 \\
1 & 2 & 11 & 11 \\
1 & 1 & 12 & 11 \\
1 & 1 & 11 & 12
\end{bmatrix}
\begin{bmatrix}
1 \\
1 \\
1 \\
1
\end{bmatrix}
=
\begin{bmatrix}
x_1 \\
x_2 \\
x_3 \\
x_4
\end{bmatrix}$

$
7 = \frac{x_1 + x_2 + 10 + x_3 + x_4}{5} \\
35 = x_1 + x_2 + 10 + x_3 + x_4 \\
25 = x_1 + x_2 + x_3 + x_4 \\
2 \leq x_1+x_2 \leq 3 \\
22 \leq x_3 + x_4 \leq 23
$

Best Answer

An approach could be linear programming. $A x \leq b$

Typical $A$ matrix would be defined by constraints such as $x_1 \leq x_2 \leq x_3 = m \leq x_4 \leq x_5$ and $ \sum x_i / 5 = n$

There are some methods to convert such requirements to elements of $A$, I hope you know them, because it is a bit too much to explain. E.q. $x_1 \leq x_2 $ would be $x_1 - x_2 \leq 0$ and as such a row in $A$ of [1 -1 0 0 0] and an element in $b$ of 0.

Related Question