# TransformedDistribution

I am trying to perform some calculations on a random variable that is the sum of a normal distribution and a truncated normal distribution. My understanding is that using TransformedDistribution is recommended over Convolve. For starters, I would like to plot the PDF of this distribution. My attempt was the following

Plot[PDF[TransformedDistribution[
x1 + x2, {x1 \[Distributed]
TruncatedDistribution[{1, Infinity}, NormalDistribution[]],
x2 \[Distributed] NormalDistribution[1, 1]}],
x], {x, -5, 5}]


This didn't return a result within an hour, so I think there must be a more efficient way to proceed.

• This is a well-known result, see e.g. Nelson, "The sum of values from a normal and a truncated normal distribution." Using that, your example has PDF Erfc[1 + (1 - t)/2]/(2*E^((1 - t)^2/4)*Sqrt[Pi]*Erfc[1/Sqrt[2]]). Here's the PDF in red, compared to histogram in orange of 10^7 RV from your transformed distribution. If time permits, I'll post as answer with explanations, but that paper will get you what you want. – ciao Aug 6 '19 at 3:41
• I chose this example specifically because it has a closed form solution, but Mathematica doesn't seem to take advantage of this. This suggests there's something about TransformedDistribution that is the source of the disconnect. Maybe some implicit assumption that is being made? – Shffl Aug 6 '19 at 22:57

I'm assuming you want some Mathematica commands to obtain the desired result as opposed to just finding out the desired result. Here's one way to do that:

pdf1 = PDF[TruncatedDistribution[{1, ∞}, NormalDistribution[0, 1]], x1][[1, 1, 1]]


pdf2 = CDF[NormalDistribution[1, 1], y - x1]


density = D[Integrate[pdf1*pdf2, {x1, 1, ∞}], y]


(* Estimate density with a large random sample *)
n = 1000000;
xx2 = RandomVariate[NormalDistribution[1, 1], n];
xx1 = RandomVariate[TruncatedDistribution[{1, ∞}, NormalDistribution[0, 1]], n];
sum = xx1 + xx2;
sdk = SmoothKernelDistribution[sum];

(* Plot both *)
Plot[{PDF[sdk, y], density}, {y, -2, 8},
PlotStyle -> {{Thickness[0.03], LightGray}, {Thickness[0.001], Red}},
PlotLegends -> {"Smooth kernel density", "True density"}]


• Can you provide some intuition as to why having it integrate the distribution directly works, whereas using TransformedDistribution does not? – Shffl Aug 6 '19 at 22:55
• Not sure if this is what you want: Integrate[pdf1*pdf2, {x1, 1, \[Infinity]}] is the cumulative distribution function of $Y$: $\text{Pr}(Y\leq y)$. Then the density is just the derivative of that with respect to $y$. So while there is a closed-form for the density, it doesn't appear that Mathematica can find a closed-form for the cdf. – JimB Aug 7 '19 at 2:24

In this specific case of a truncated normal convoluted with a normal distribution, the answer can be adapted from https://stats.stackexchange.com/questions/121899/sum-of-truncated-normal-with-two-normal-distributions. However, I would still like to know how to proceed in general.