3
$\begingroup$

Consider $b>0$ and let $X \sim U[-b,b]$ (the continuous uniform distribution in $[-b,b]$ ). I want to do two computations in Mathematica.

First is to compute the density function of $X^2$, which I calculated (by hand) as being $f_{X^2}(x) = \frac{1}{2b\sqrt{x}}\cdot\textbf{I}_{(0,b^2]}(x)$. Then I used the following code to make Mathematica compute this density.

X = UniformDistribution[{-b, b}] ;
Z = TransformedDistribution[X^2,X \[Distributed] UniformDistribution[{-b, b}]];
PDF[Z, x]

1

This output is weird. First because it's different from my own calculation (which I think are correct), second because $\lim_{x\to b^2}\frac{1}{2b\sqrt{x}} = \frac{1}{2b^2} \neq \frac{1}{4b^2}$, where the last expression is the value of the density suggested by the Mathematica's output. This is a problem, for $f_{X^2}$ has to be a continuous function. Probably the problem is me, not Mathematica, but where is my reasoning wrong?

After this, I want to compute the joint density $f_{(X,X^2)}$ of the random vector $(X,X^2)$ and plot it. In this case I'm a bit lost how to proceed.

Thank you for you help.

$\endgroup$
  • 1
    $\begingroup$ The first line is in effect on a zero measure support $\endgroup$ – Dr. belisarius Jan 20 '16 at 18:40
  • $\begingroup$ @Dr.belisarius You are right, it won't affect the calculations. Still, it makes the density function not continuous. So, I think a continuous random variable not necessarily has a continuous density function, but a density function continuous almost everywhere. Is that it? $\endgroup$ – Integral Jan 20 '16 at 18:47
  • $\begingroup$ The joint density will be hard to plot because its support $\{(x,x^2):-b\le x\le b\}$ is a one-dimensional subset of the plane. $\endgroup$ – Rahul Jan 20 '16 at 19:26
  • 2
    $\begingroup$ Your weird output is due to re-using X rather than x (or another dummy variable) in your definition for Z, when you already set X equal to something in the previous line. If you replace X with something else in that line, it gives the expected result. $\endgroup$ – Michael Seifert Jan 20 '16 at 21:10
  • 1
    $\begingroup$ @MichaelSeifert You are totally right, I don't even need that first line. Thank you! $\endgroup$ – Integral Jan 20 '16 at 22:46
4
$\begingroup$

Explicitly telling Mathematica that b is real and positive seems to help.

Assuming[b > 0,
 X = UniformDistribution[{-b, b}];
 Z = TransformedDistribution[X^2, X \[Distributed] UniformDistribution[{-b, b}]];
 PDF[Z, x]
 ]

Mathematica graphics

Assuming[b > 0,
 XZ = ProductDistribution[X, Z];
 pdf = PDF[XZ, {x, z}]
 ]

Mathematica graphics

Block[{b = 1},
 Plot3D[pdf, {x, -1, 1}, {z, -1, 1}]]  (* or {z, 0, 1} *)

Mathematica graphics

AFAICT, the ProductDistribution is the joint distribution as described in the documentation, assuming the component distributions are independent (maybe that's not what the OP meant); it is not the Product Distribution described on Wikipedia.

$\endgroup$
3
$\begingroup$

Since the joint distribution function is singular (proportional to $\delta(y - x^2)$ or something like that), you'll have to be creative about plotting it. Here's an attempt that's kludgey as hell, but it does give something:

b = 1;
ListPointPlot3D[Table[{x, x^2, PDF[Z, x] PDF[X, x]}, {x, -2 b, 2 b, b/100}],
   RegionFunction -> Function[{x, y, z}, z > 0], 
   PlotRange -> {{-2 b, 2 b}, Automatic, Automatic}, Filling -> Bottom]
Clear[b]

enter image description here

(Method cribbed from the answers here.) I didn't want to use ParametricPlot3D because it didn't really convey that this was a function of $x$ and $y$ that happened to be zero except along a line; you can judge for yourself whether my code does that any better.

$\endgroup$
  • $\begingroup$ Isn't there a way to explicitly compute the joint density of $(X, X^2)$ ? The plot would follow easily from that. $\endgroup$ – Integral Jan 21 '16 at 0:03
1
$\begingroup$

If you start with $b = 1$ (for instance), you get (Mathematica version 10.3):

$\begin{cases} \text{Indeterminate} & x=0\lor x=1 \\ \frac{1}{2 \sqrt{x}} & 0<x<1 \end{cases}$

Which seems perfect.

Plot3D[ 1/(4 Sqrt[x]), {x, -1, 1}, {y, -1, 1}]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you for your response, but this question has two parts. In fact, the second is more important (the first is just a technical issue). Also, what is (v. 10.3) ? Thanks. $\endgroup$ – Integral Jan 20 '16 at 18:54
  • $\begingroup$ Are you sure this plot is the joint density function of $(X,X²)$ ? Just for reference: probabilitycourse.com/chapter5/5_2_1_joint_pdf.php $\endgroup$ – Integral Jan 20 '16 at 19:26

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.