Learn R Programming

Rlab (version 1.1)

Bernoulli: The Bernoulli Distribution

Description

Density, distribution function, quantile function and random generation for the Bernoulli distribution with parameter prob.

Usage

dbern(x, prob, log = FALSE)
pbern(q, prob, lower.tail = TRUE, log.p = FALSE)
qbern(p, prob, lower.tail = TRUE, log.p = FALSE)
rbern(n, prob)

Arguments

x, q
vector of quantiles.
p
vector of probabilities.
n
number of observations. If length(n) > 1, the length is taken to be the number required.
prob
probability of success on each trial.
log, log.p
logical; if TRUE, probabilities p are given as log(p).
lower.tail
logical; if TRUE (default), probabilities are $P[X \le x]$, otherwise, $P[X > x]$.

Value

  • dbern gives the density, pbern gives the distribution function, qbern gives the quantile function and rbern generates random deviates.

Details

The Bernoulli distribution with prob $= p$ has density $$p(x) = {p}^{x} {(1-p)}^{1-x}$$ for $x = 0 or 1$. If an element of x is not 0 or 1, the result of dbern is zero, without a warning. $p(x)$ is computed using Loader's algorithm, see the reference below. The quantile is defined as the smallest value $x$ such that $F(x) \ge p$, where $F$ is the distribution function.

References

Catherine Loader (2000). Fast and Accurate Computation of Binomial Probabilities; manuscript available from http://cm.bell-labs.com/cm/ms/departments/sia/catherine/dbinom

See Also

dbinom for the binomial (Bernoulli is a special case of the binomial), and dpois for the Poisson distribution.

Examples

Run this code
# Compute P(X=1) for X Bernoulli(0.7)
dbern(1, 0.7)

Run the code above in your browser using DataLab