dist_bernoulli(prob)

## Arguments

prob The probability of success on each trial, prob can be any value in [0, 1].

## Details

Bernoulli distributions are used to represent events like coin flips when there is single trial that is either successful or unsuccessful. The Bernoulli distribution is a special case of the Binomial() distribution with n = 1.

We recommend reading this documentation on https://pkg.mitchelloharawild.com/distributional/, where the math will render nicely.

In the following, let $$X$$ be a Bernoulli random variable with parameter p = $$p$$. Some textbooks also define $$q = 1 - p$$, or use $$\pi$$ instead of $$p$$.

The Bernoulli probability distribution is widely used to model binary variables, such as 'failure' and 'success'. The most typical example is the flip of a coin, when $$p$$ is thought as the probability of flipping a head, and $$q = 1 - p$$ is the probability of flipping a tail.

Support: $$\{0, 1\}$$

Mean: $$p$$

Variance: $$p \cdot (1 - p) = p \cdot q$$

Probability mass function (p.m.f):

$$P(X = x) = p^x (1 - p)^{1-x} = p^x q^{1-x}$$

Cumulative distribution function (c.d.f):

$$P(X \le x) = \left \{ \begin{array}{ll} 0 & x < 0 \\ 1 - p & 0 \leq x < 1 \\ 1 & x \geq 1 \end{array} \right.$$

Moment generating function (m.g.f):

$$E(e^{tX}) = (1 - p) + p e^t$$

## Examples

dist <- dist_bernoulli(prob = c(0.05, 0.5, 0.3, 0.9, 0.1))

dist
#> <distribution>
#>  Bernoulli(0.05) Bernoulli(0.5)  Bernoulli(0.3)  Bernoulli(0.9)
#>  Bernoulli(0.1) mean(dist)
#>  0.05 0.50 0.30 0.90 0.10variance(dist)
#>  0.0475 0.2500 0.2100 0.0900 0.0900skewness(dist)
#>   4.1294832  0.0000000  0.8728716 -2.6666667  2.6666667kurtosis(dist)
#>  15.052632 -2.000000 -1.238095  5.111111  5.111111
generate(dist, 10)
#> []
#>   0 0 0 0 0 0 0 0 0 0
#>
#> []
#>   1 0 0 0 0 0 0 0 0 1
#>
#> []
#>   0 0 1 0 1 1 0 0 0 0
#>
#> []
#>   1 1 1 1 1 1 1 0 1 1
#>
#> []
#>   0 0 0 0 0 0 0 1 1 0
#>
density(dist, 2)
#>  0 0 0 0 0density(dist, 2, log = TRUE)
#>  -Inf -Inf -Inf -Inf -Inf
cdf(dist, 4)
#>  1 1 1 1 1
quantile(dist, 0.7)
#>  0 1 0 1 0