2
$\begingroup$

Context

In Mathematica one is able to directly calculate the marginal and conditional probability distributions of a discrete joint distribution (abstracting over the specific details) like so:

enter image description here

Represent joint distribution

dist = EmpiricalDistribution[{0.37,0.17, 0.14, 0.02, 0.24, 0.05} -> {
     {0, 0}, {0, 1}
   , {1, 0}, {1, 1}
   , {2, 0}, {2, 1}
 }];

get Marginal

marginal1= PDF[MarginalDistribution[dist, 1] , X]//Simplify

get Conditional

conditional = Probability[X == x \[Conditioned] Y ==y, {X,Y} \[Distributed] dist]//Simplify

Plot them

joint = PDF[dist, {x, y}];
marginal1 = PDF[MarginalDistribution[dist, 1], x];
marginal2 = PDF[MarginalDistribution[dist, 2], y];
conditional = Probability[X == x \[Conditioned] Y == y, {X, Y} \[Distributed] dist] // Simplify;


GraphicsGrid[{{DiscretePlot3D[joint, {x, 0, 2}, {y,0, 1}, ExtentSize -> Full, ViewPoint -> {2, -2, 2}, PlotLabel -> "P[X==x,Y==y]"],DiscretePlot3D[joint, {x, 0, 2}, {y, 0, 1},ExtentSize -> Full, ViewPoint -> {2, -2, 2},PlotLabel -> "P[X==x\[Conditioned]Y==y]"]},{DiscretePlot[marginal1, {x, 0, 2}, ExtentSize -> Full, PlotLabel -> "P[X==x]"],DiscretePlot[marginal2, {y, 0, 1},ExtentSize -> Full, PlotLabel -> "P[Y==y]"]}}] 

enter image description here


Question:

I want to know how to calculate the conditional pdf of a continuous joint distribution, in a simple intuitive way like for the discrete case above.


Here is my attempt

represent Joint distribution

for instance: uniform distribution over the unit disk:

dist = ProbabilityDistribution[Piecewise[{{1/\[Pi], 0 <= Sqrt[x^2 + y^2] <= 1}}],{x, -1, 1}, {y, -1, 1}];

enter image description here

get Marginal

marginal1 = PDF[MarginalDistribution[dist, 1], x] //Simplify

enter image description here

get Conditional

?

What is an idiomatic way to obtain a conditional density function from a continuous joint distribution?

I know I could divide the Marginal into the Joint, but this does not seem very idiomatic. The master user should not have to waste cognitive power thinking about underlying math. Surely there is some built-in functionality to do this in Mathematica like there is for Marginal? Preferably this functionality should take advantage of Conditional.

Likelihood and TransformedDistributionlooks like promising alternatives to Probability for continuous distributions.

If this desired function does not exist then my questions is: Define this function.

$\endgroup$
4
$\begingroup$

The OP considers the Uniform distribution over the unit disc

i.e. $(X,Y)$ have joint pdf $f(x,y)$:

enter image description here

Then, the Marginal and Conditional functions from the mathStatica package for Mathematica do what you seek.

The marginal pdf of $Y$ is:

enter image description here

The conditional pdf of $Y$ given $X = x$ is:

enter image description here

$\endgroup$
  • $\begingroup$ hahaha! +1 for being wise master user $\endgroup$ – Conor Cosnett Aug 5 at 16:07
2
$\begingroup$

Apparently Mathematica provides syntax for extracting conditional CDFs from a continuous joint distribution:

This syntax can be used as an intermediate stepping stone to deriving the desired conditional PDF.

dist = ProbabilityDistribution[Piecewise[{{1/\[Pi], 0 <= Sqrt[x^2 + y^2] <= 1}}], {x, -1,1}, {y, -1, 1}];
cdf = Probability[X <= x \[Conditioned] Y == y, {X, Y} \[Distributed] dist];
conditionalDensityFunction = PDF[ProbabilityDistribution[{"CDF", cdf}, {x, -1, 1}], x] 

enter image description here


enter image description here


update

The comments underneath this answer to a similar question suggests that we are still waiting for this functionality:

enter image description here

$\endgroup$
  • 1
    $\begingroup$ I think there's something not quite right about the resulting conditional density function. One gets 0 everywhere when $y=1$ and the area under the density is less that 1. Don't you want to use D[cdf, x] or conditionalDensityFunction = FullSimplify[ PDF[ProbabilityDistribution[{"CDF", cdf}, {x, -1, 1}, Assumptions -> -1 < y < 1], x]] for the conditional density? $\endgroup$ – JimB Aug 3 at 17:05
  • $\begingroup$ yes, I think your right, I will try and fix it, or replace it with an alternative $\endgroup$ – Conor Cosnett Aug 3 at 19:48
  • 2
    $\begingroup$ Not to make excuses for Mathematica but the domains get more complex, too, besides the form of the density function. So I can see how it might be difficult to have a general function the spits out conditional densities. $\endgroup$ – JimB Aug 3 at 20:15

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.