# Mode

When dealing with sparse data or data that is distributed towards the edges (U-Shaped sample), finding the Arithmetic Mean or Medium can provide wrong information about the data distribution. A way to calculate the average in such scenarios is to find where the data peaks exist. This method is called Mode.

$$Mode \stackrel{\text{def}}{=} \{ x | x \in S \wedge \forall y \in S : count(y) \leq count(x) \}$$

The mathematical formula above with the sample examples can be found implemented in 5 different programming languages in our Github repository.

## Examples

### Example 1:

Consider the following simple set $S = \{1, 2, 3, 4, 5, 6, 7, 8, 9\}$. Using the formula above, as shown below in 3 simple steps we find the Mode for the sample $S$.

1. For each unique value in the set, count the number of occurances $$\begin{array}{c|c} \bold{Point} & \bold{Count} \\ \hline 1 & 1 \\ \hline 2 & 1 \\ \hline 3 & 1 \\ \hline 4 & 1 \\ \hline 5 & 1 \\ \hline 6 & 1 \\ \hline 7 & 1 \\ \hline 8 & 1 \\ \hline 9 & 1 \\ \hline \end{array}$$
2. Find the maximum occurrence $$maxima = 1$$
3. Return the set with the sample values with the maximum occurrence $$Mode = \{1, 2, 3, 4, 5, 6, 7, 8, 9\}$$

### Example 2

$S = \left\{\begin{matrix}51,97,43,20,48,48,96,63,10,35,16,\\4,42,80,18,1,67,75,46,92,38,44,\\87,69,54,91,6,8,60,64,53,23,86\end{matrix}\right\}$

Workings:

1. For each unique value in the set, count the number of occurances $$\begin{array}{c|c} \bold{Point} & \bold{Count} \\ \hline 51 & 1 \\ \hline 97 & 1 \\ \hline 43 & 1 \\ \hline 20 & 1 \\ \hline 48 & 2 \\ \hline 96 & 1 \\ \hline 63 & 1 \\ \hline 10 & 1 \\ \hline 35 & 1 \\ \hline 16 & 1 \\ \hline 4 & 1 \\ \hline 42 & 1 \\ \hline 80 & 1 \\ \hline 18 & 1 \\ \hline 1 & 1 \\ \hline 67 & 1 \\ \hline 75 & 1 \\ \hline 46 & 1 \\ \hline 92 & 1 \\ \hline 38 & 1 \\ \hline 44 & 1 \\ \hline 87 & 1 \\ \hline 69 & 1 \\ \hline 54 & 1 \\ \hline 91 & 1 \\ \hline 6 & 1 \\ \hline 8 & 1 \\ \hline 60 & 1 \\ \hline 64 & 1 \\ \hline 53 & 1 \\ \hline 23 & 1 \\ \hline 86 & 1 \\ \hline \end{array}$$
2. Find the maximum occurrence $$maxima = 2$$
3. Return the set with the sample values with the maximum occurrence $$Mode = \{48\}$$