I am analyzing some variates from a steeply falling power-law distribution (approximately with a power index -4) using

Histogram[data, Automatic, "PDF"]

While the option ScalingFunctions->{"Log", "Log"} helps a lot in keeping the results in perspective, I cannot really see small deviations from the power law since the dominant trend in the log-log view will be a linear function with approximate slope -4. The usual trick in such studies is to scale the resulting pdf by dividing it with the approximate trend, i.e. for the bin entries I want something like

ScalingFunctions->{"Log", Function[{count, center}, Log[center^4 count]]}

instead of only Function[x, Log[x]] which I get with the "Log" option. Unfortunately Histogram seems to call this function with only one argument which is the corresponding bin count (or pdf value in my case), unlike e.g. Plot which calls RegionFunction with all the coordinates and similarly other plotting functions in Mathematica.

Is there a way to convince Mathematica to call the scaling functions not only with the bin value but also with the bin center or location of bin edges?


1 Answer 1


There is nice 3-rd argument in Histogram

data = RandomReal[1.0, 1000000]^(-1/3);

Histogram[data, 100, #2/(-Subtract @@@ #)/ Total[#2] (Mean /@ #)^4 &,
 ScalingFunctions -> {"Log", "Log"}]

enter image description here

Pure #2/(-Subtract @@@ #)/Total[#2] & is equivalent to "PDF".

Results are better with log-scaled bins

Histogram[data, {"Log", 20}, #2/(-Subtract @@@ #)/Total[#2] (Mean /@ #)^4 &, 
 ScalingFunctions -> {"Log", "Log"}]

enter image description here

P.S. Why I chose RandomReal[1.0, 1000000]^(-1/3) for power-law distribution with a power index -4?


PDF@TransformedDistribution[x^(-1/3), x \[Distributed] UniformDistribution[]]

enter image description here

  • $\begingroup$ Great, that's it! But is berried really deep down in the documentation... $\endgroup$ Commented Sep 26, 2013 at 18:08
  • $\begingroup$ @DarkoVeberic A lot of interesting things buried in the Details&Options section :) Note that I correct one mistake and update the answer. $\endgroup$
    – ybeltukov
    Commented Sep 26, 2013 at 18:13
  • $\begingroup$ Can you guess which fh function is equivalent to the "PDF" option? $\endgroup$ Commented Sep 26, 2013 at 18:18
  • $\begingroup$ Ah, great, you've answered it while I was typing the question... $\endgroup$ Commented Sep 26, 2013 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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