# SmoothHistogram binning and "Intensity"

I'm having trouble with the way SmoothHistogram handles bins. At the end of the day, I want to express the vertical axis ticks in terms of the normalized values of the bin counts. This can easily be done with Histogram using "Probability" as the binning function, but this is not an option usable for SmoothHistogram. I have tried the following as a workaround:

rdata = RandomReal[{0, 1}, 1000];
bw = 0.01;
bins = BinCounts[rdata, bw];
maxBinCount = Max[bins];
SmoothHistogram[rdata, bw, "Intensity",
PlotRange -> {{0, 1}, Automatic}, Frame -> True,
FrameTicks -> {{Automatic, {{0, "0"}, {maxBinCount, "1"}}}, {Automatic, None}},
LabelStyle -> {Bold, 18}]
ListPlot[bins, Joined -> True]


Clearly, the second plot shows that the actual bin counts are not the things recorded by the "Intensity" binning function. How would I make the RHS ticks scale appropriately from 0 to 1 on the vertical plot space?

Using "PDF" (with maxBinCount replaced by 1 in the ticks) instead of "Intensity" gets closer, but since "PDF" isn't the actual overall probability as "Probability" would have been, this isn't quite right: • What do you mean by "normalized values of the bin counts" ? And how does using PDF get you "closer" ? Why isn't it close enough? I'm just not understanding what is the desired output.
– JimB
Apr 16 '18 at 17:45
• @JimB The data should be represented in a vertical range between the values of zero and one. Apr 16 '18 at 18:08

I'm guessing that because the distribution in question is bounded by 0 and 1 and "smooth histograms" don't usually produce desired results when there are such bounds. Using the Bounded option of SmoothKernelDistribution will probably get you the desired (and appropriate) output. (I would also suggest using the default bandwidth as 0.01 is way too small).

SeedRandom;
rdata = RandomReal[{0, 1}, 1000];
skd = SmoothKernelDistribution[rdata, Automatic, {"Bounded", {0, 1}, "Epanechnikov"}];
Plot[PDF[skd, x], {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1.2}}, Frame -> True] • This still doesn't do the job, since the value of the function exceeds unity. The trivial example Histogram[rdata,1,"Probability"] (histogram with one bin) shows the maximum value to be one, as desired. Increasing the bin count, I would like the tallest bin to still be valued at one, except displayed as a smooth plot instead of individual bins. Apr 16 '18 at 18:25
• Why do you feel the need to have the maximum at 1? Unless all values are exactly 1.0, the area under the curve won't be 1.0. If you want the maximum to be 1.0, what kind of interpretation of the vertical axis do you envision? I'm not sure what that would be but if you really need that, just divide PDF[skd, x] by its maximum value.
– JimB
Apr 16 '18 at 18:37
• I need the maximum at one such that the scale of the function be related to relative probabilities. Your proposed method can indeed work to show this. Alternatively, one can use ListPlot[bins/maxBinCount,PlotRange->All,Joined->True]. This preserves the chosen bin size, desired scaling, and relative smoothness for a sufficiently large data set with sufficiently many bins. I'll mark this as answered. Thanks for the assist. Apr 16 '18 at 18:41
• I think you should wait for another answer. Maybe someone else isn't as confused as me. (I also don't know what a "relative probability" is.)
– JimB
Apr 16 '18 at 18:46