Bernoulli Distribution

SAS Bernoulli Distribution trial PMF Code ExampleThe Bernoulli distribution is probably the simplest of the common, discrete distributions. It has only two outcomes, 1 and 0. Here, I will introduce the distribution by code example from a SAS point of view. If a stochastic variable X is Bernoulli distributed, it takes the value 1 with probability p and the value zero with probability q = 1-p. Consequently, the Probability Mass Function is

    \begin{equation*} P(X = k) = \begin{cases} p \text{ for } k = 1 \\ q \text{ for } k = 0 \end{cases} \end{equation*}

The Bernoulli distribution is a special case of the Binomial Distribution, which models the number ¬†successes in a series of Binomial trials. In a Bernoulli trial, k=1 usually represents “Success” and k=0 represents “Failure”. A Trial of size N can be interpreted as tossing a coin N times and counting the number of heads and tails of the outcome. If p=0.5, there is an equal probability of success and failure. In the coin toss example, that means a fair coin. If p \ne 0.5, the coin is unfair.

Bernoulli Distribution SAS Code Example

Lets us look at a small example of a Bernoulli trial. Suppose we toss a fair coin 10 times and record the number of heads and tails of the outcome. We define heads as “Success” and tails as “Failure, though reversing this definition will make no difference. Below, I have written the SAS code to perform this trial.

%let p=.5;
%let N=10;
data Bernoulli_Trial;
   call streaminit(555);
   do i=1 to &N;
      x=rand('Bernoulli', &p);

If you are not at all familiar with the Bernoulli, watch this basic introduction at Khan Academy. Another natural extension to the Bernoulli distribution in SAS is the Table Distribution. The Table distribution lets you sample from more than two outcomes and specify the associated probabilities. Basically, this is a Bernoulli with more than two outcomes. This is a very important extension and I encourage you to get to know it.

You can download the entire code with the Bernoulli trial here.