5
(* 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?

corey979
  • 23,947
  • 7
  • 58
  • 101
  • 3
    Removing the MaxExtraBandwidths option improves the matching considerably(this goes back to the default extra bandwidths, which is 12). – MarcoB Sep 30 '21 at 01:00

1 Answers1

5

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

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • 6
    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. – MarcoB Sep 30 '21 at 01:47