Density, distribution function, quantile function and random
generation for the Bernoulli distribution with parameter prob
.
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)
vector of quantiles.
vector of probabilities.
number of observations. If length(n) > 1
, the length
is taken to be the number required.
probability of success on each trial.
logical; if TRUE, probabilities p are given as log(p).
logical; if TRUE (default), probabilities are \(P[X \le x]\), otherwise, \(P[X > x]\).
dbern
gives the density, pbern
gives the distribution
function, qbern
gives the quantile function and rbern
generates random deviates.
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.
Catherine Loader (2000). Fast and Accurate Computation of Binomial Probabilities; manuscript available from http://cm.bell-labs.com/cm/ms/departments/sia/catherine/dbinom
dbinom
for the binomial (Bernoulli is a special case
of the binomial), and dpois
for the Poisson distribution.
# NOT RUN {
# Compute P(X=1) for X Bernoulli(0.7)
dbern(1, 0.7)
# }
Run the code above in your browser using DataLab