50% off | Unlimited Data & AI Learning

Last chance! 50% off unlimited learning

Sale ends in


distributional (version 0.3.2)

dist_bernoulli: The Bernoulli distribution

Description

[Stable]

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

dist_bernoulli(prob)

Arguments

prob

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

Details

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=1p, or use π 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=1p is the probability of flipping a tail.

Support: {0,1}

Mean: p

Variance: p(1p)=pq

Probability mass function (p.m.f):

P(X=x)=px(1p)1x=pxq1x

Cumulative distribution function (c.d.f):

P(Xx)={0x<01p0x<11x1

Moment generating function (m.g.f):

E(etX)=(1p)+pet

Examples

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

dist
mean(dist)
variance(dist)
skewness(dist)
kurtosis(dist)

generate(dist, 10)

density(dist, 2)
density(dist, 2, log = TRUE)

cdf(dist, 4)

quantile(dist, 0.7)

Run the code above in your browser using DataLab