0
$\begingroup$

I have attempted to plot the Cumulative Distribution Function of a simple piecewise probability mass function, but the code:

Plot3D[CDF[p[x, y], {x, y}], {x, -3, 3}, {y, -3, 3}]

where p[x_, y_] is the function Piecewise[...]. This yields an empty plot - why is this so? Do I have to make p of probability distribution type?

$\endgroup$
6
  • $\begingroup$ Please provide a minimal non-working example of p[x,y] $\endgroup$ Oct 30, 2019 at 23:02
  • $\begingroup$ The first argument of CDF should be a distribution rather than a probability mass function or probability density function. To convert a pdf to a distribution see ProbabilityDistribution $\endgroup$
    – Bob Hanlon
    Oct 30, 2019 at 23:46
  • $\begingroup$ @BobHanlon yes I realized that the ProbabilityDistribution function takes in Probability Density Function as parameter, but since I do not have the PDF and only the have the probability mass distribution on an x-y plane, I was wondering whether it would be possible to get the CDF from this? $\endgroup$
    – user68199
    Oct 31, 2019 at 1:03
  • $\begingroup$ Look at the documentation for ProbabilityDistribution again. It will take your pmf/pdf (p[x, y]) and assumptions/constraints as inputs and define the distribution that can be used as an input to CDF $\endgroup$
    – Bob Hanlon
    Oct 31, 2019 at 1:09
  • $\begingroup$ Thanks for the response @BobHanlon even from reading the documentation it is still not apparent to me that the ProbabilityDistribution function takes pmf ? Would you mind pointing out where exactly this information is? $\endgroup$
    – user68199
    Oct 31, 2019 at 1:38

1 Answer 1

2
$\begingroup$
Clear["Global`*"];

You have a user-defined pmf (pdf in Mathematica terms), p[x, y], For example,

p[x_, y_] = Piecewise[{
    {1/8, x == 0 && y == 0},
    {1/4, x == 0 && y == 1},
    {1/4, x == 1 && y == 0},
    {3/8, x == 1 && y == 1}}];

ProbabilityDistribution is used to define the associated distribution

enter image description here

distXY = ProbabilityDistribution[p[x, y], {x, 0, 1, 1}, {y, 0, 1, 1}];

The distribution is used to define the CDF

CDF[distXY, {x, y}]

enter image description here

Plot3D[CDF[distXY, {x, y}], {x, -1, 2}, {y, -1, 2}]

enter image description here

$\endgroup$

Your Answer

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

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