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)
length(n) > 1
, the length
is taken to be the number required.dbern
gives the density, pbern
gives the distribution
function, qbern
gives the quantile function and rbern
generates random deviates.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.dbinom
for the binomial (Bernoulli is a special case
of the binomial), and dpois
for the Poisson distribution.# Compute P(X=1) for X Bernoulli(0.7)
dbern(1, 0.7)
Run the code above in your browser using DataLab