Lably
Skip to content

Mode (statistics)

Value that appears most often in a set of data

  • 7 min read
  • 4 chapters
  • 6 labs on Lably

Learn it on Lably

Like the statistical mean and median, the mode is a summary statistic about the central tendency of a random variable or a population. The numerical value of the mode is the same as that of the mean and median in a normal distribution, but it may be very different in highly skewed distributions.

The mode is not necessarily unique in a given discrete distribution since the probability mass function may take the same maximum value at several points x1, x2, etc. The most extreme case occurs in uniform distributions, where all values occur equally frequently.

A mode of a continuous probability distribution is often considered to be any value x at which its probability density function has a locally maximum value. When the probability density function of a continuous distribution has multiple local maxima it is common to refer to all of the local maxima as modes of the distribution, so any peak is a mode. Such a continuous distribution is called multimodal (as opposed to unimodal).

In symmetric unimodal distributions, such as the normal distribution, the mean (if defined), median and mode all coincide. For samples, if it is known that they are drawn from a symmetric unimodal distribution, the sample mean can be used as an estimate of the population mode.

Mode of a sample

The mode of a sample is the element that occurs most often in the collection. For example, the mode of the sample [1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17] is 6. Given the list of data [1, 1, 2, 4, 4] its mode is not unique. A dataset, in such a case, is said to be bimodal, while a set with more than two modes may be described as multimodal.

For a sample from a continuous distribution, such as [0.935..., 1.211..., 2.430..., 3.668..., 3.874...], the concept is unusable in its raw form, since no two values will be exactly the same, so each value will occur precisely once. In order to estimate the mode of the underlying distribution, the usual practice is to discretize the data by assigning frequency values to intervals of equal distance, as for making a histogram, effectively replacing the values by the midpoints of the intervals they are assigned to. The mode is then the value where the histogram reaches its peak. For small or middle-sized samples the outcome of this procedure is sensitive to the choice of interval width if chosen too narrow or too wide; typically one should have a sizable fraction of the data concentrated in a relatively small number of intervals (5 to 10), while the fraction of the data falling outside these intervals is also sizable. An alternate approach is kernel density estimation, which essentially blurs point samples to produce a continuous estimate of the probability density function which can provide an estimate of the mode.

The following MATLAB (or Octave) code example computes the mode of a sample:

<span id="mwRQ"></span><span class="n" id="mwRg">X</span><span class="w" id="mwRw"> </span><span class="p" id="mwSA">=</span><span class="w" id="mwSQ"> </span><span class="nb" id="mwSg">sort</span><span class="p" id="mwSw">(</span><span class="n" id="mwTA">x</span><span class="p" id="mwTQ">);</span><span class="w" id="mwTg"> </span><span class="c" id="mwTw">% x is a column vector dataset</span> <span class="n" id="mwUA">indices</span><span class="w" id="mwUQ"> </span><span class="p" id="mwUg">=</span><span class="w" id="mwUw"> </span><span class="nb" id="mwVA">find</span><span class="p" id="mwVQ">(</span><span class="nb" id="mwVg">diff</span><span class="p" id="mwVw">([</span><span class="n" id="mwWA">X</span><span class="p" id="mwWQ">,</span><span class="w" id="mwWg"> </span><span class="nb" id="mwWw">realmax</span><span class="p" id="mwXA">])</span><span class="w" id="mwXQ"> </span><span class="o" id="mwXg">></span><span class="w" id="mwXw"> </span><span class="mi" id="mwYA">0</span><span class="p" id="mwYQ">);</span><span class="w" id="mwYg"> </span><span class="c" id="mwYw">% indices where repeated values change</span> <span class="p" id="mwZA">[</span><span class="n" id="mwZQ">modeL</span><span class="p" id="mwZg">,</span><span class="nb" id="mwZw">i</span><span class="p" id="mwaA">]</span><span class="w" id="mwaQ"> </span><span class="p" id="mwag">=</span><span class="w" id="mwaw"> </span><span class="nb" id="mwbA">max</span><span class="w" id="mwbQ"> </span><span class="p" id="mwbg">(</span><span class="nb" id="mwbw">diff</span><span class="p" id="mwcA">([</span><span class="mi" id="mwcQ">0</span><span class="p" id="mwcg">,</span><span class="w" id="mwcw"> </span><span class="n" id="mwdA">indices</span><span class="p" id="mwdQ">]));</span><span class="w" id="mwdg"> </span><span class="c" id="mwdw">% longest persistence length of repeated values</span> <span class="nb" id="mweA">mode</span><span class="w" id="mweQ"> </span><span class="p" id="mweg">=</span><span class="w" id="mwew"> </span><span class="n" id="mwfA">X</span><span class="p" id="mwfQ">(</span><span class="n" id="mwfg">indices</span><span class="p" id="mwfw">(</span><span class="nb" id="mwgA">i</span><span class="p" id="mwgQ">));</span>

The algorithm requires as a first step to sort the sample in ascending order. It then computes the discrete derivative of the sorted list and finds the indices where this derivative is positive. Next it computes the discrete derivative of this set of indices, locating the maximum of this derivative of indices, and finally evaluates the sorted sample at the point where that maximum occurs, which corresponds to the last member of the stretch of repeated values.

Sign in to keep reading

3 more chapters are free with a Lably account.

More in Statistics and probability