Bernoulli: Create a Bernoulli distribution

View source: R/Bernoulli.R

BernoulliR Documentation

Create a Bernoulli distribution

Description

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.

Usage

Bernoulli(p = 0.5)

Arguments

p

The success probability for the distribution. p can be any value in ⁠[0, 1]⁠, and defaults to 0.5.

Details

We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.

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

Value

A Bernoulli object.

See Also

Other discrete distributions: Binomial(), Categorical(), Geometric(), HurdleNegativeBinomial(), HurdlePoisson(), HyperGeometric(), Multinomial(), NegativeBinomial(), Poisson(), PoissonBinomial(), ZINegativeBinomial(), ZIPoisson(), ZTNegativeBinomial(), ZTPoisson()

Examples


set.seed(27)

X <- Bernoulli(0.7)
X

mean(X)
variance(X)
skewness(X)
kurtosis(X)

random(X, 10)
pdf(X, 1)
log_pdf(X, 1)
cdf(X, 0)
quantile(X, 0.7)

cdf(X, quantile(X, 0.7))
quantile(X, cdf(X, 0.7))

distributions3 documentation built on Sept. 30, 2024, 9:37 a.m.