# Different histograms for same data in R and Oracle Crystal Ball

I am analysing small sample size data:

>dput(dat.demand2050.unique)
c(79, 56, 69, 61, 53, 73, 72, 86, 75, 68, 74.2, 80, 65.6, 60, 54)


for which the histogram and density function look like this in R: http://db.tt/1uVSufat

But when I used the Oracle Crystal Ball Simulation tool (it is an Excel plugin, but I can't post the link due to low reputation) to get the probability distribution, it gives a different result: http://db.tt/ugrpn140

Does anyone have experience with this tool? I am pretty sure the "probability" shown on the Y-axis is the same as the "Density" for the plot obtained in R, but I could be wrong.

Another question is if the plotted quantities are indeed the same, what is the reason for the difference? Is it due to a difference in the algorithm?

• You need to find a possibility to adjust the breaks for the histogram in the Excel plugin. Jul 31, 2013 at 9:06

These graphs are showing different things.

The difference to bear in mind is that between probability and probability density, which are different beasts.

The "Crystal Ball" tool is treating your 15 values, which are all distinct, as 15 bins for each of which the probability is 1/15 $\approx$ .06666667.

The tool also seems to be purporting to tell you about the relative merits of different distributions, which is a real stretch for this sample size.

The tool is also showing you the fitted probability density for a uniform distribution over the range of the data.

It is pure coincidence that the numbers are even of the same order of magnitude, within a factor of 5 or so.

R is plotting probability density, and consistently. The probability density integrates to 1 over the whole distribution. As a ballpark check, we might approximate your data distribution by a rectangle with height 0.02 and width 50, so we do get 1. But the units of density are probability per unit of measurement, not probability.

Think that areas on a histogram drawn properly show probability, so that those areas are

height in probability/units of measurement $\times$ variable in units of measurement

so that the units of measurement cancel leaving you with pure probability for the area (but, as said, not the height).

I can't identify your units of measurement from your post, but it looks like something economic. If it were measured in dollars or rupees or whatever, the density would be probability per dollar or probability per rupee, and so forth.

There are several related posts on this site. I like this one Can a probability distribution value exceeding 1 be OK? for explaining what density is.

On this evidence, the histogram procedure in "Crystal Ball" is at least a bit sloppy by statistical standards, but I know no more about it than your example here, so I will not comment further.

• thanks for the explanation, gives me insight into how the two are constructed. some comments on your answer: 1. yes, the data is economic, energy to be precise, in units of petajoule. 2. if the area of each bin on the histogram shows probability, then the probability of finding a value between 50-55 is 0.03*5=0.15? 3. To get the same probability from the density curve, would one have to integrate it between 50 and 55?
– avg
Jul 31, 2013 at 12:43
• Correct. Integration here gives area under the curve, which can be approximated by measuring areas of rectangles. Jul 31, 2013 at 14:01

It seems the line in your screenshot is simply a fitted uniform distribution (you can apparently select others in the box on the right) so it is definitely not the same thing as the density curve in the R plot.

More generally, histograms and density curves are much more complex topics than it might seem at first sight. It is perfectly possible to obtain different histograms from the same data (and also wildly misleading histograms at that). Density curves address some of these problems, but not all and the curve you get from R is just the result of some reasonable default approach, not the only possible one.

One thing you can adjust is the amount of smoothing or the level of detail about peak and trough in the data (technically it's called the bandwidth), for example: The plot was created using the GGPlot2 package (but adjusting the bandwidth is most likely possible with any other graphics system), the relevant code is

geom_density(colour="red") +
geom_rug()


The first geom_density uses the default bandwidth, similar to the basic density function, geom_rug adds the little stripchart representing individual data point at the bottom of the plot.

• that was a good link, I was very trusting of histograms and density estimates before. In the plots you generated, is there a general rule for choosing a "good" bandwidth? can you please also post the code for the plot? thanks.
– avg
Jul 31, 2013 at 13:07
• I added a code snippet to my answer. Regarding the other question, there is a whole literature on it (with which I am in fact not very familiar) and I also came across some approach based on the idea of generating several curves and comparing them systematically. Mostly, what I do in practice is go with the default bandwidth but also look at the data directly (stripchart possibly with jitter or transparency to avoid overplotting, boxplots) to check if I might have missed something strange. The important thing is not to read too much into it, especially with small sample sizes.
– Gala
Jul 31, 2013 at 13:33
• thanks for the code. I know that my data have two regimes - high and low, so I think the default density estimate is suitable for my purposes. Also, I am accepting @NickCox's answer as it addresses my question directly.
– avg
Aug 4, 2013 at 17:12