# Finding the mode of a continuous distribution

I need to find the empirical mode of a sample of numbers taken from a continuous distribution (i.e. floating-point data).

I can think of using an histogram, but choosing an appropriate bin size does not seem so easy. I could also count the values in a sliding Parzen window, but again, which window size ? I could also compare the local densities (width of the intervals containing M consecutive values). But which M ?

My question: do you know a classical procedure to estimate the mode in such a case ? Alternatively, is there a robust answer to the "sizes" question ?

• Can you define what you mean by empirical mode? The obvious way is to store the numbers in a hashtable and count which number occurred most frequently in your sample (no histograms or bins). Does that violate some requirement you have? Are you implicitly making some assumptions about the shape/nature of the distribution?
– D.W.
Commented Jul 5, 2023 at 16:51
• @D.W.: this is true for discrete distributions. For continuous ones, the probability of equal values is zero.
– user16034
Commented Jul 5, 2023 at 16:59
• Without some assumptions about the shape of the distribution, the problem seems impossible to me, because there are too many distributions that are consistent with the observed data, and they won't all have the same mode. So can you specify the problem more precisely, e.g., in mathematical form?
– D.W.
Commented Jul 5, 2023 at 19:17
• @D.W.: the distribution is unknown. In practice it has one dominant mode and possibly a few minor ones. The sample is a list of $n$ values $x_i$. The empirical mode is where the points have the largest density.
– user16034
Commented Jul 5, 2023 at 19:37

I don't think the question is answerable without more context. If you observe a list of $$n$$ values $$x_i$$, there are multiple distributions that are consistent with the observed values, each with different modes. You would need to define what you mean by "the empirical mode" in this context.
My guess would be that, most likely, you have some prior on the possible distribution, and then a Bayesian analysis may be possible, but it's hard to know without knowing more specifics. A general approach to Bayesian analysis would be to model the (unknown) probability distribution as given by the pdf $$f_\theta(\cdot)$$ where $$\theta$$ is an unknown function, with some prior $$p(\theta)$$ on the distribution of the unknown parameter $$\theta$$. Let $$m$$ denote the mode and $$x=(x_1,\dots,x_n)$$ the denote the finite sample. Then our Bayesian estimate for the mode is
\begin{align*} \mathbb{E}[m|x] &= \int_\theta m(f_\theta) p(\theta|x) \; d\theta\\ &= {\int_\theta m(f_\theta) f_\theta(x_1) \cdots f_\theta(x_n) p(\theta) \; d\theta \over \int_\theta f_\theta(x_1) \cdots f_\theta(x_n) p(\theta) \; d\theta} \end{align*}
where $$m(f_\theta)$$ denotes the mode of the distribution with pdf $$f_\theta$$. Whether you can compute (or approximate) those integrals depends on the parametrization of possible continuous distributions for the samples and the prior on the parameters $$\theta$$.
A crude approximation to this Bayesian estimate is to find $$\theta^*$$ that maximizes the value of $$f_{\theta^*}(x_1) \cdots f_{\theta^*}(x_n) p(\theta^*)$$, and then use $$m(f_{\theta^*})$$ as your estimate of the mode. If you have a uniform prior on $$\theta$$, this basically amounts to asking for the maximum likelihood distribution. Whether you can solve this optimization problem and thus compute this approximation again depends on your parametrization and prior.