3
$\begingroup$

The below code executes. If I uncomment the Plot, it runs for a while and outputs nothing, not even the Mean and Variance.


new2 = TransformedDistribution[(x + y + z)/3, {x, y,z} \[Distributed] LogMultinormalDistribution[{0,1,0},{{1,0,0},{0,1,0},{0,0,1}}]];

lmdpdf = PDF[new2,x];

(* Plot[%, {x, 1, 8}, Filling -> Axis,PlotRange -> Automatic]  *)

Mean[new2]
Variance[new2]

========

Meanwhile, the below works fine.


new2a = TransformedDistribution[(x + y),
 {x\[Distributed] NormalDistribution[],
y \[Distributed] NormalDistribution[]} 
];

PDF[new2a, x];

Plot[%, {x, -6, 8}, Filling -> Axis,PlotRange -> Automatic]

Mean[new2a]
Variance[new2a]

===

ADDED in response to comment. The below runs fine, including plot. I think it is the same as a 2 variable version of my non-plotting Transform.

===

new2a = TransformedDistribution[(x + y),
 {x\[Distributed] LogNormalDistribution[0,1],
y \[Distributed] LogNormalDistribution[0,1]
} 
]

Added more: tried exactly two variable version, and it fails to plot. Sans Plot function, it returns the same Mean and Variance though, so I am even more confused. This is apparently not a Plot issue, but a closed/open form issue combined with a built-in-symbols question...

new2 = TransformedDistribution[(x + y + z), {x,y,z} \[Distributed] LogMultinormalDistribution[{0,1,0},{{1,0,0},{0,1,0},{0,0,1}}]];

dividing by 2 (see below) also causes code to fail, which doesn't feel like it is a closed/open form issue, but I have no idea what MMA is doing under the covers ...

new2a = TransformedDistribution[(x + y)/2,
 {x\[Distributed] LogNormalDistribution[0,1],
y \[Distributed] LogNormalDistribution[0,1]
} 
]

Function without closed form successfully plots

$\endgroup$
12
  • 1
    $\begingroup$ There is no closed-form for that pdf and it must be evaluated numerically. Hence, no plot. $\endgroup$
    – JimB
    Commented May 13 at 22:48
  • 3
    $\begingroup$ @DavidG.Stork No. The resulting distribution (new2) is a univariate distribution. $\endgroup$
    – JimB
    Commented May 13 at 22:55
  • 1
    $\begingroup$ It appears that putting in machine precision numbers (such as PDF[new2a, 3.5]) allows Mathematica to produce a density. PDF[new2a, 7/2] doesn't return a density. So maybe there's an underlying NPDF function (similar to NIntegrate). More to think about. $\endgroup$
    – JimB
    Commented May 14 at 23:34
  • 1
    $\begingroup$ My guess now is that when a machine precision number is given to PDF and Mathematica recognizes that the distribution is the sum of two independent random variables, numerical convolution is used. See en.wikipedia.org/wiki/Convolution_of_probability_distributions. But it doesn't do this for a sum of 3 or more independent random variables. Plot feeds PDF with machine precision numbers so it works. And there still isn't a closed-form solution. $\endgroup$
    – JimB
    Commented May 14 at 23:52
  • 1
    $\begingroup$ Looking at the documentation for PDF (which I should have done earlier) under "Possible Issues" shows an example where the closed-form does not exist (and not for a sum of 2 independent random variables) but evaluates the pdf numerically. So there are multiple circumstances where PDF can kick into numerical mode. $\endgroup$
    – JimB
    Commented May 15 at 14:12

1 Answer 1

6
$\begingroup$

If you just need a display of an approximation of the pdf, random sampling with a large sample and a SmoothHistogram works fine for your particular distribution.

x = RandomVariate[new2, 1000000];
SmoothHistogram[x, PlotRange -> {{0, 15}, {0, Automatic}}]

Smooth histogram of random sample

If you need a function that gives the approximate value of the pdf and more accurate than SmoothHistogram because we know that the pdf is bounded on the left by zero, then using random sampling with a large sample and SmoothKernelDistribution works:

skd = SmoothKernelDistribution[x, Automatic, {"Bounded", {0, ∞}, "Gaussian"},
  MaxMixtureKernels -> 1000, InterpolationPoints -> 1000];
Plot[PDF[skd, z], {z, 0, 15}]

Smooth kernel with bounded domain

If you and interested in a more direct numerical integration solution, then that should be added to your question.

$\endgroup$
1
  • $\begingroup$ Thank you. That has spawned new questions in two different directions. I will write them up and link them here. $\endgroup$ Commented May 14 at 11:48

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.