1
$\begingroup$

I have a continuous uniform random variable $P∼U(0,1)$ and a normal random variable $X∼N(0,σ)$. If $Z$ is given by $Z=\frac{1}{1+P}+X$ where $X$ and $P$ are independent variables, how can I calculate the PDF of $Z$ in Mathematica?

This fails to run:

pdf3 = PDF[
  TransformedDistribution[(1/(1 + z1)) + 
    z2, {z1 \[Distributed] UniformDistribution[{0, 1}], 
    z2 \[Distributed] NormalDistribution[0, s]}], x]

However, if I look only at $Z = \frac{1}{1+P}$ using a similar approach, my code runs OK:

pdf2 = PDF[
  TransformedDistribution[(1/(1 + z1)), {z1 \[Distributed] 
     UniformDistribution[{0, 1}]}], x]
$\endgroup$
3
  • 1
    $\begingroup$ try td1 = TransformedDistribution[(1/(1 + z1)), {z1 \[Distributed] UniformDistribution[{0, 1}]}]; pmd = ParameterMixtureDistribution[NormalDistribution[m1, s], m1 \[Distributed] td1, Assumptions -> s > 0]; PDF[pmd]@x? $\endgroup$
    – kglr
    Commented May 11, 2021 at 14:04
  • $\begingroup$ No luck I'm afraid, still does not run. Thank you for trying! $\endgroup$ Commented May 11, 2021 at 14:21
  • $\begingroup$ Cross-posted at math.stackexchange.com/questions/4134911/…. $\endgroup$
    – JimB
    Commented May 11, 2021 at 18:41

1 Answer 1

3
$\begingroup$

I know you want an explicit formula for the pdf but I'm not sure that exists. Here's why:

Your pdf2 is

pdf2 = PDF[TransformedDistribution[(1/(1 + z1)), 
  {z1 \[Distributed] UniformDistribution[{0, 1}]}], z2]

pdf of 1/(1-p)

So the brute force approach would be to get the pdf of $Z$ as follows:

Integrate[(1/z1^2) PDF[NormalDistribution[0, s], z - z1], {z1, 1/2, 1}, Assumptions -> s > 0]

But the input is just returned and even using Rubi doesn't get an explicit solution. A numerical approach might be what you have to do.

dist = TransformedDistribution[(1/(1 + z1)) + 
    z2, {z1 \[Distributed] UniformDistribution[{0, 1}], 
    z2 \[Distributed] NormalDistribution[0, s]}];

pdf[z_, s_] := NIntegrate[(1/z2^2) PDF[NormalDistribution[0, s], z - z2], {z2, 1/2, 1}]

s0 = 1/80;
n = 100000;
SeedRandom[12345];
zz = RandomVariate[dist /. s -> s0, n];
Show[Histogram[zz, "FreedmanDiaconis", "PDF"], 
 Plot[pdf[z, s0], {z, 0.4, 1.1}, PlotRange -> All, PlotStyle -> Red]]

Histogram and estimated density

$\endgroup$
5
  • 1
    $\begingroup$ Should that be a z1 rather than a u in the normal distribution PDF in your second code block? (If not, it's a pretty easy integral.) :-) $\endgroup$ Commented May 11, 2021 at 18:04
  • $\begingroup$ @MichaelSeifert. You're right. I changed the notation and then didn't run it again which would have caught that error. I'll fix it. Thanks! $\endgroup$
    – JimB
    Commented May 11, 2021 at 18:10
  • $\begingroup$ Thank you for the great answer. I feared that there might not be a way to get an explicit solution with Mathematica. Do you think this is a limitation of the software or something about the function itself that prevents the convolution of the PDFs? $\endgroup$ Commented May 12, 2021 at 7:39
  • $\begingroup$ For anyone interested, I also have a post on math.stackexchange on finding the PDF of the same equation math.stackexchange.com/questions/4134911/… $\endgroup$ Commented May 12, 2021 at 7:45
  • 1
    $\begingroup$ The integral resembles OwenT, but I was unable to massage the integrand to express it in terms of it. $\endgroup$
    – Greg Hurst
    Commented May 12, 2021 at 15:40

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.