Bernoulli distribution


Story

The result \(y\) of a single Bernoulli trial is Bernoulli distributed.


Example

Check to see if a given bacterium is competent, given that it has probability \(\theta\) of being competent.


Parameter

The Bernoulli distribution is parametrized by a single value, \(\theta\), the probability that the trial is successful.


Support

The Bernoulli distribution may be nonzero only for \(y = 0\) and \(y = 1\).


Probability mass function

\[\begin{split}\begin{align} f(y;\theta) = \left\{ \begin{array}{ccc} 1-\theta & & y = 0 \\[0.5em] \theta & & y = 1. \end{array} \right. \end{align}\end{split}\]

Cumulative distribution function

\[\begin{split}\begin{align} f(y;\theta) = \left\{ \begin{array}{ccc} 0 & & y < 0 \\[0.5em] 1 - \theta & & 0 \le y < 1 \\[0.5em] 1 & & y \ge 1. \end{array} \right. \end{align}\end{split}\]

Moments

Mean: \(\theta\)

Variance: \(\theta(1-\theta)\)


Usage

Package

Syntax

NumPy

rng.choice([0, 1], p=[1 - theta, theta])

SciPy

scipy.stats.bernoulli(theta)

Distributions.jl

Bernoulli(theta)

Stan

bernoulli(theta)



PMF and CDF plots