If I know the distributional parameter of a distribution (lognormal, in this case) I can plot the density function. If I want to convert the density into a histogram, I should calculate the "height" of the bars associated with different intervals under the curve (i.e.,$ 0-99.9; 100-199.9$ and so on). How can I calculate the values of the density associated with each bin so that I can obtain the histogram associated with the distribution?


1 Answer 1


Say that you have $n-1$ bins in form $(t_{k-1}, t_k]$, with boundaries $t_1, t_2,\dots,t_n$, then if you want to "histogrammize" your density function, simply take probabilities of $X$ belonging to $B_k = (t_{k-1}, t_k]$ bins

$$ p_k = \Pr(X \in B_k) = \int_{t_{k-1}}^{t_k} f(t)\, dt = F(t_k) - F(t_{k-1}) $$

where $f$ is a density function and $F$ is a cumulative distribution function, and divide them by the bin widths

$$ \hat f(x) = \frac{p_k}{t_k - t_{k-1}} \qquad \text{for } x \in (t_{k-1}, t_k] $$

for it to be consistent with the definition of histogram (Scott, 1992):

$$ \hat f(x) = \frac{1}{nh} \sum_{i=1}^n I_{(t_{k-1}, t_k]}(x \in B_k) $$

Similar approach is used to discretize the continuous distributions, to get their discrete analogs as described in the Implementing a discrete analogue to Gaussian function thread.

Scott, D.W. (1992). Multivariate Density Estimation: Theory, Practice, and Visualization. Wiley.

  • $\begingroup$ Brilliant. Thanks. Do you know if there is a way to do so in excel or stata? So that i can just plug in the values of distributional parameters and the bins' width and extract those values? $\endgroup$
    – user165855
    Aug 7, 2017 at 12:34
  • $\begingroup$ @a.russoIT you simply need to evaluate the CDF's on the endpoints of the bins, I believe both of the software can do it. $\endgroup$
    – Tim
    Aug 7, 2017 at 12:35
  • $\begingroup$ It helps a lot. I need to find a code to solve those integrals. My x goes from 0 to 250000. Assuming bins' width of 100 i should calculate 2500 integrals and it's not feasible. Any help for codes and software? $\endgroup$
    – user165855
    Aug 7, 2017 at 13:43
  • $\begingroup$ @a.russoIT but you do not need to solve the integrals! You need only the CDF's, i.e. in Excel =LOGNORM.DIST(x_max; mean; sd; TRUE) - LOGNORM.DIST(x_min; mean; sd; TRUE) $\endgroup$
    – Tim
    Aug 7, 2017 at 13:46
  • 1
    $\begingroup$ @whuber you are right, I corrected it. $\endgroup$
    – Tim
    Aug 7, 2017 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy