# PDF of sum of (1/(1+uniform distribution)) and a normal distribution

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]

• 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?
– kglr
Commented May 11, 2021 at 14:04
• No luck I'm afraid, still does not run. Thank you for trying! Commented May 11, 2021 at 14:21
• Cross-posted at math.stackexchange.com/questions/4134911/….
– JimB
Commented May 11, 2021 at 18:41

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]


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]]


• 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.) :-) Commented May 11, 2021 at 18:04
• @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!
– JimB
Commented May 11, 2021 at 18:10
• 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? Commented May 12, 2021 at 7:39
• For anyone interested, I also have a post on math.stackexchange on finding the PDF of the same equation math.stackexchange.com/questions/4134911/… Commented May 12, 2021 at 7:45
• The integral resembles OwenT, but I was unable to massage the integrand to express it in terms of it. Commented May 12, 2021 at 15:40