5
$\begingroup$
(* This generates the data that illustrates the issue *)
pdf = MixtureDistribution[{0.54, 0.46}, {CauchyDistribution[0.47, 0.26], NormalDistribution[30.33, 12.04]}]
mock = RandomVariate[pdf, 70000];
mock2 = Select[mock, 0 < # < 50 &];

When I draw the Histogram and SmoothHistogram, the two distributions do not align:

Histogram[mock2, Automatic, "PDF", PlotRange -> {0, 0.025}];
SmoothHistogram[mock2, "Scott", PlotRange -> {0, 0.025}, PlotStyle -> Red, MaxExtraBandwidths -> {0, 0}];
Show[%%, %]

enter image description here

Based on the docs of SmoothHistogram (Properties & Relations) I'd expect an alignment.

Why is it poor, and how to make it better?

$\endgroup$
1
  • 3
    $\begingroup$ Removing the MaxExtraBandwidths option improves the matching considerably(this goes back to the default extra bandwidths, which is 12). $\endgroup$
    – MarcoB
    Sep 30 at 1:00
5
$\begingroup$

The distribution function specification in the SmoothHistogram should be "PDF"

Clear["Global`*"]

$Version

(* "12.3.1 for Mac OS X x86 (64-bit) (June 19, 2021)" *)

SeedRandom[1234];

dist = MixtureDistribution[{0.54, 0.46}, {CauchyDistribution[0.47, 0.26], 
    NormalDistribution[30.33, 12.04]}];
mock = RandomVariate[dist, 70000];
mock2 = Select[mock, 0 < # < 50 &];

Show[
 Histogram[mock2, Automatic, "PDF", PlotRange -> {0, 0.025}],
 SmoothHistogram[mock2, "Scott", "PDF",
  PlotStyle -> Red,
  PlotRange -> {0, 0.025}]]

enter image description here

$\endgroup$
1
  • 6
    $\begingroup$ Bob, plotting the PDF is already the default for SmoothHistogram. I think what made the difference is the fact that you removed the non-standard value for the MaxExtraBandwidths option that was in the original code. $\endgroup$
    – MarcoB
    Sep 30 at 1:47

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.