Why does the following command return an empty plot?

Plot[PDF[TransformedDistribution[(2 Z - 1) X, 
{Distributed[X, ExponentialDistribution[1]], 
Distributed[Z, BernoulliDistribution[0.5]]}], t], {t, -1, 1}]

Yet RandomVariate works just fine:

SmoothHistogram@RandomVariate[TransformedDistribution[(2 Z - 1) Abs[X], 
{Distributed[X, ExponentialDistribution[1]], 
Distributed[Z, BernoulliDistribution[0.5]]}], 1.*^5]

I merely give a particular example; don't focus unduly on it, I want to generalize.

  • 2
    $\begingroup$ Have you checked that the function PDF[...] actually returns values ? $\endgroup$ – b.gates.you.know.what Apr 26 '12 at 8:24
  • $\begingroup$ TransformedDistribution doesn't seem to like products of distributions, or the mixture of Exponential and Bernoulli, $\endgroup$ – image_doctor Apr 26 '12 at 10:16
  • 4
    $\begingroup$ This is a continuous distribution (the Laplace or Double Exponential), so that's not the problem. A little testing with simpler expressions suggests TransformedDistribution isn't anything more than a toy at this point: it can take a large amount of computation to obtain simple sums (such as adding an Exponential to a Gamma variate), if it succeeds at all, and simply fails quietly when evaluating most multivariate expressions. $\endgroup$ – whuber Apr 26 '12 at 14:52
  • $\begingroup$ My answer is no longer an answer to your question since your edits, so I have deleted it. $\endgroup$ – Verbeia Apr 26 '12 at 23:14

TransformedDistribution contains a collection of identities known to it, like that of sum of normals being equal in distribution to another normal random variable, and a general machinery to work out properties of the functions of random variables.

Most of the time the computation will be done by the general machinery, which relies on solvers, like Expectation and Probability. Hence TransformedDistribution will be as strong as those are.

The major strength of TransformedDistribution, in my opinion, is that it allows for easy and efficient sampling. It is generally expensive to work out other properties of the random variable from this representation.

In this particular example of $(2 Z-1) X \stackrel{d}{=} -(-1)^Z X$ the underlying solvers did not know how to handle the mixed case of discrete and continuous distribution:

In[11]:= di = 
  TransformedDistribution[(2 z - 1) x, {z \[Distributed] 
    x \[Distributed] ExponentialDistribution[1]}];

In[12]:= CDF[di, z]

Out[12]= CDF[
 TransformedDistribution[(-1 + 
     2 \[FormalX]1) \[FormalX]2, {\[FormalX]1 \[Distributed] 
    BernoulliDistribution[1/2], \[FormalX]2 \[Distributed] 
    ExponentialDistribution[1]}], z]

As it is often the case, one can work out the answer in an alternative way:

In[13]:= CharacteristicFunction[di, t] // Simplify

Out[13]= 1/(1 + t^2)

In[14]:= pdf = 
 InverseFourierTransform[%, t, x, FourierParameters -> {1, 1}]

Out[14]= 1/2 E^-Abs[x]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.