# On the hspec argument to DensityHistogram

Below I show three groups of possible settings for the third (optional) argument to the DensityHistogram function, hspec.

1. "Count", "Probability", "Intensity", "PDF"
2. "CumulativeCount", "CDF"
3. "SurvivalCount", "SF"

I have not been able to find any difference (beyond numerical error) in the results produced by different hspec settings from the same group.

Suppose that hspec1 and hspec2 are two different hspec settings belonging to the same group above, and let

dh1 = DensityHistogram[data, bspec, hspec1]
dh2 = DensityHistogram[data, bspec, hspec2]


My question is, briefly stated:

For what arguments data and bspec will dh1 and dh2 be different?

I need to spell out what "different" means here. Since dh1 and dh2 convey their information through 2-dimensional arrangements colored rectangles, I would consider them different only if the number, placement, or coloring of these rectangles differed between them.

I assume that fixing data and bspec ensures that dh1 and dh2 will feature the same number and placement of these rectangles.

So any difference between dh1 and dh2 must come from differences in the colors of corresponding rectangles.

Since the coloring of the rectangles in dh1 and dh2 is determined by the same color function, the previous conclusion can be rephrased as: any difference between dh1 and dh2 must come from differences in the arguments passed to the color function for the corresponding rectangles.

By this criterion, I have not been able to find values for data and bspec that will produce different dh1 and dh2 when hspec1 and hspec2 come from the same groups.

Actually, in some cases dh1 and dh2 differed due to floating-point numerical error. This detail suggests that two hspec settings from the same group may lead to different execution paths, even though they produce mathematically (even if not numerically) identical results.

Below I give the details of how I arrived at the groupings above.

First I defined the following helper functions:

With[{core = ColorData["M10DefaultDensityGradient", "ColorFunction"]},
colorFunction[z_] := (Sow[z]; core[z])
]

With[{data = BlockRandom[RandomSeed[0];
RandomReal[NormalDistribution[0, 1], {100, 2}]],
bspec = 3},

probe[hspec_:Automatic] :=
Last @ Reap @
DensityHistogram[data, bspec, hspec, ColorFunction -> colorFunction]

]


colorFunction is just a pass-through wrapper that Sows its argument before passing it along to the default color function.

probe[hspec] just invokes

DensityHistogram[data, bspec, hspec, ColorFunction -> colorFunction]


...for fixed values of data and bspec, and then returns the arguments Sowed by colorFunction.

Then I just evaluated

GroupBy[{probe[#], #} & /@
{Automatic, "Count", "CumulativeCount", "SurvivalCount", "Probability",
"Intensity", "PDF", "CDF", "SF", "HF", "CHF"},
First -> Last]


Closer inspection of the last result's keys revealed some spurious differences resulting from using floating-point values as keys, so then I evaluated

GroupBy[{probe[#], #} & /@
{Automatic, "Count", "CumulativeCount", "SurvivalCount", "Probability",
"Intensity", "PDF", "CDF", "SF", "HF", "CHF"},
Round[First[#], 10.^-10]& -> Last]


...and obtained the grouping of hspec settings shown at the beginning of this post.

(Incidentally, Automatic falls in the first group.)

• The difference between "count" and "probability" should just be the values of the vertical axis -- the count being a whole number indicating how mny of each kind occur and the probability being normalized to one. – bill s May 5 '17 at 22:51
• @bills: in principle, yes, but in fact there's no actual perceptible difference in the outputs generated by those two options; the density histograms look the same. – kjo May 5 '17 at 22:59

The difference between "count" and "probability" is the values of the vertical axis -- the count being a whole number indicating how many of each kind occur and the probability being normalized to one. For example:

data = RandomVariate[BinormalDistribution[.5], 100];
{DensityHistogram[data, Automatic, "PDF", ChartLegends -> Automatic],
DensityHistogram[data, Automatic, "Count", ChartLegends -> Automatic]}


You can see the difference in the legend, though of course the histograms themselves look the same. You will also see the different values as popups if you pass the mouse over the data points.

"Count" and "Intensity" will look different when the bins aren't all the same size. Otherwise they values will be proportional and have the same colors. The same applies to "Probability" and "PDF":

data = RandomVariate[NormalDistribution[], {500, 2}];

inequalbins = {{{-3, -3/2, -1, -1/2, 0, 1/2, 1, 3/2,
3}}, {{-3, -3/2, -1, -1/2, 0, 1/2, 1, 3/2, 3}}};

DensityHistogram[data, inequalbins, #] & /@ {"Count", "Intensity"}


• Brilliant. I wish I could accept this one too... – kjo May 6 '17 at 12:59