3
$\begingroup$

Bug introduced in 11.0.1 or earlier and persisting through 11.3.0 or later

I try to get a Log transformed histogram data I get from a different program

examplefile = 
     {{0., 70.110492289066920}, {20., 6.80630499020644475}, {40.,
       8.42161}, {60., 15.06519919414850448}, {80., 
      8.2318220556770346}, {100., 87.478685125810497}, {120., 
      4161.7690039964691}, {140., 84754.765836040083}, {160., 
      532571.989049240777}, {180., 857574.30987846023}, {200., 
      299164.78794849526}, {220., 21296.4007456827975}, {240., 
      324.610011732739988}}

I convert this to a distribution by:

 \[ScriptCapitalD]exmp = HistogramDistribution[
   WeightedData[examplefile[[;; , 1]], examplefile[[;; , 2]]], {20}];

And do a Log transform:

\[ScriptCapitalD]log = TransformedDistribution[Log[x], 
     x \[Distributed] \[ScriptCapitalD]exmp]

Now RandomVariate is working fine:

Histogram[RandomVariate[\[ScriptCapitalD]log, 10000]]

enter image description here

But PDF is showing nothing:

Plot[PDF[\[ScriptCapitalD]log, y], {y, 0, 10}]

enter image description here

Do I do something wrong, or can I just not use PDF?

$\endgroup$
5
  • $\begingroup$ try Plot[Evaluate@PDF[\[ScriptCapitalD]log, y], {y, 0, 10}]? $\endgroup$
    – kglr
    Commented Jul 9, 2018 at 13:51
  • $\begingroup$ @kglr, thanks. I get the same resulting plot $\endgroup$
    – Ruud3.1415
    Commented Jul 9, 2018 at 13:53
  • 1
    $\begingroup$ this must be version/os related. Plot[Evaluate@PDF[\[ScriptCapitalD]log, y], {y, 0, 10}] works in version 9 (windows 10) but not in version 11 (wolfram cloud). $\endgroup$
    – kglr
    Commented Jul 9, 2018 at 13:57
  • $\begingroup$ The PDF looks really weird in Mathematica 11.3. Look here i.sstatic.net/2G8QM.png $\endgroup$
    – halirutan
    Commented Jul 9, 2018 at 14:06
  • $\begingroup$ Please add the standard bug header instead of changing the title mathematica.meta.stackexchange.com/a/1611/12 $\endgroup$
    – Szabolcs
    Commented Jul 12, 2018 at 9:09

1 Answer 1

4
$\begingroup$

In version 9,

Plot[Evaluate@PDF[\[ScriptCapitalD]log, y], {y, 0, 10}] (* and *)
Plot[PDF[\[ScriptCapitalD]log, y], {y, 0, 10}, Evaluated -> True]

give

enter image description here

In version 11.3, there seems to be a bug in computation of the PDF

PDF[\[ScriptCapitalD]log, y] 

enter image description here

The issue is that Boole[{...} <= E^y <{...}] doesn't thread.

The fix is easy: simply modify the piecewise expression by explicitly Threading the argument of Boole:

pdf = Function[y, PDF[\[ScriptCapitalD]log, y] /. Boole[a_] :> Boole[Thread[a]]];

Plot[Evaluate@pdf[ y], {y, 0, 10}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Plot[pdf[y], {y, Log[#[[1]]], Log[#[[2]]]}, PlotRange -> All, ImageSize -> Medium] & /@ {{1, 120}, {120, 260}} // Column shows additional data $\endgroup$
    – Bob Hanlon
    Commented Jul 9, 2018 at 15:22
  • $\begingroup$ Do we agree that a bug tag is applicable? $\endgroup$
    – Ruud3.1415
    Commented Jul 11, 2018 at 10:07
  • $\begingroup$ @Ruud3.1415, I think so. I suggest you report this to Wolfram. $\endgroup$
    – kglr
    Commented Jul 11, 2018 at 10:13

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.