1
$\begingroup$

I have

$$X_1=T + W$$ $$X_2=2 T + 3 W$$

where

$$W \sim N(3,5) \,\text{;}\,\, T \sim N(1,2)$$ and $$P(X=X_1)=P(X=X_2)=\tfrac{1}{2}$$

which I have awkwardly expressed as

X2 = TransformedDistribution[
  2 T + 3 W, {W \[Distributed] NormalDistribution[3, Sqrt[5]], 
   T \[Distributed] NormalDistribution[1, Sqrt[2]]}]

X1 = TransformedDistribution[
  T + W, {W \[Distributed] NormalDistribution[3, Sqrt[5]], 
   T \[Distributed] NormalDistribution[1, Sqrt[2]]}]

XX = TransformedDistribution[
  i a + (1 - i) b, {a \[Distributed] X1, b \[Distributed] X2, 
   i \[Distributed] BernoulliDistribution[0.5]}]

This serves fine for generating RandomVariates and for calculating Mean, Variance, etc.; but I would like to plot the PDF of $T$ vs $X$ and am struggling with how to correctly construct the joint PDF to do this.

How should I go about constructing these distributions so that the joint PDF, $f_{X,T}(x,t)$, can be plotted using, for example with ContourPlot or Plot3D?

$\endgroup$
4
  • $\begingroup$ I don't know how probability distributions work in Mathematica. Does Mathematica know that the T and W in the definitions of X1 and X2 are the same? Otherwise you won't get the right correlations. For example, consider y = TransformedDistribution[x, x \[Distributed] NormalDistribution[]]; z = TransformedDistribution[x, x \[Distributed] NormalDistribution[]]; are y and z independent? $\endgroup$
    – user484
    Apr 23, 2014 at 22:42
  • $\begingroup$ @RahulNarain: Does that matter here, where I'm just looking at $X$, which is either $X_1$ or $X_2$? $\endgroup$
    – orome
    Apr 23, 2014 at 23:00
  • $\begingroup$ Hmm... probably not, you're right. $\endgroup$
    – user484
    Apr 23, 2014 at 23:05
  • $\begingroup$ @RahulNarain: Good catch though, for the general case (i not limited to $\{0, 1\}$). $\endgroup$
    – orome
    Apr 23, 2014 at 23:36

1 Answer 1

2
$\begingroup$

As a warm up, let's find the PDF of XX. Now if we just do PDF[XX, x], Mathematica will seemingly spin forever, which one might think is caused by Integrate. Let's see if that's correct.

First let's Print each time we Integrate:

Block[{Integrate},
  Integrate[e__] /; (Print[{e}]; False) := Null;
  PDF[XX, x]
]

Ok so there is one integral, and notice we can simplify it by realizing x3 is either 0 or 1 as seen in the Assumptions option above. Making our own custom integrator for this case we get an answer for the PDF of XX:

With[{X = \[FormalX]3},
  Internal`InheritedBlock[{Integrate},
    Unprotect[Integrate];
    Integrate[e__] /; !FreeQ[{e}, X] := 
      Piecewise[{{Integrate @@ ({e} /. X->0), X==0}, {Integrate @@ ({e} /. X->1), X==1}}];

    PDF[XX, x]
  ]
]
(* 0.0273995 E^(-(1/106) (-11+x)^2)+0.075393 E^(-(1/14) (-4+x)^2) *)

Plot[0.0273995 E^(-(1/106) (-11+x)^2)+0.075393 E^(-(1/14) (-4+x)^2), {x, -10, 30}]

Now I'm a little fuzzy on how to compute a joint PDF but perhaps it can be computed in a similar fashion. (Let me know if this is the wrong way to find the joint pdf!):

With[{X=\[FormalX]3},
  Internal`InheritedBlock[{Integrate},
    Unprotect[Integrate];
    Integrate[e__] /; !FreeQ[{e}, X] := 
      Piecewise[{{Integrate @@ ({e} /. X->0), X==0}, {Integrate @@ ({e} /. X->1), X==1}}];

    jcdf = Probability[
      X <= x && T <= t, 
      {X\[Distributed]XX, T\[Distributed]NormalDistribution[1,Sqrt[2]]}
    ];

    jpdf = D[jcdf, x, t]
  ]
]
(* 0.0705237 E^(-0.25 (-1.+t)^2) (0.109598 E^(-0.00943396 (-11.+x)^2)+0.301572 E^(-0.0714286 (-4.+x)^2)) *)

Plot3D[jpdf, {x, -10, 30}, {t, -10, 10}, PlotRange -> All, 
  PlotPoints -> 50, AxesLabel -> {x, t}]

Edit:

I feel this is wrong because Probability thinks X and T are independent... and I'm pretty sure they're dependent, is that correct?

$\endgroup$
1
  • $\begingroup$ My Mathematica formulation may not be the correct way to capture the mathematical formulation (which is definitive) at the start of the question. It works for some applications (see my comment) but not generally, and perhaps not here. $\endgroup$
    – orome
    Apr 23, 2014 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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