# Make a probability mass function and plot it?

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?

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] 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"] • Oh good, I can also use mathematica's "Probability" function on it. Thanks – tighten Mar 13 '18 at 9:56