4
$\begingroup$

If, for example, I am given the probability mass function of a discrete random variable $X$, $P(X=0)=0.5$, $P(X=1)=0.3$ and $P(X=2)=0.2$, then how do I make a probability mass function out of it so that I can apply DiscretePlot to it?

$\endgroup$
5
$\begingroup$
dist = ProbabilityDistribution[
   Piecewise[{{1/2, x == 0}, {3/10, x == 1}, {2/10, x == 2}}], {x, 0, 2, 1}];

Simplify@PDF[dist, x] // TeXForm

$$\begin{cases} \frac{1}{5} & x=2 \\ \frac{3}{10} & x=1 \\ \frac{1}{2} & x=0 \end{cases}$$

DiscretePlot[PDF[dist, x], {x, 0, 3}, PlotStyle -> Thickness[.02], Frame -> True]

enter image description here

| improve this answer | |
$\endgroup$
5
$\begingroup$

A compact way is to use EmpiricalDistribution[]:

emp = EmpiricalDistribution[{0.5, 0.3, 0.2} -> {0, 1, 2}];

Verify its properties:

Table[Probability[z == k, z \[Distributed] emp], {k, 0, 2}]
   {0.5, 0.3, 0.2}

Plot:

DiscretePlot[PDF[emp, k], {k, 0, 3}, PlotLegends -> None, PlotTheme -> "Detailed"]

plot of PMF

| improve this answer | |
$\endgroup$
  • $\begingroup$ Oh good, I can also use mathematica's "Probability" function on it. Thanks $\endgroup$ – tighten Mar 13 '18 at 9:56

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.