Last chance! 50% off unlimited learning
Sale ends in
Density, distribution function, quantile function and random
generation for the binomial distribution with parameters size
and prob.
This is conventionally interpreted as the number of ‘successes’
in size trials.
dbinom(x, size, prob, log = FALSE)
pbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE)
qbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE)
rbinom(n, size, prob)vector of quantiles.
vector of probabilities.
number of observations. If length(n) > 1, the length
is taken to be the number required.
number of trials (zero or more).
probability of success on each trial.
logical; if TRUE, probabilities p are given as log(p).
logical; if TRUE (default), probabilities are
dbinom gives the density, pbinom gives the distribution
function, qbinom gives the quantile function and rbinom
generates random deviates.
If size is not an integer, NaN is returned.
The length of the result is determined by n for
rbinom, and is the maximum of the lengths of the
numerical arguments for the other functions.
The numerical arguments other than n are recycled to the
length of the result. Only the first elements of the logical
arguments are used.
The binomial distribution with size prob choose in R.
If an element of x is not integer, the result of dbinom
is zero, with a warning.
The quantile is defined as the smallest value
Distributions for other standard distributions, including
dnbinom for the negative binomial, and
dpois for the Poisson distribution.
# NOT RUN {
require(graphics)
# Compute P(45 < X < 55) for X Binomial(100,0.5)
sum(dbinom(46:54, 100, 0.5))
## Using "log = TRUE" for an extended range :
n <- 2000
k <- seq(0, n, by = 20)
plot (k, dbinom(k, n, pi/10, log = TRUE), type = "l", ylab = "log density",
main = "dbinom(*, log=TRUE) is better than log(dbinom(*))")
lines(k, log(dbinom(k, n, pi/10)), col = "red", lwd = 2)
## extreme points are omitted since dbinom gives 0.
mtext("dbinom(k, log=TRUE)", adj = 0)
mtext("extended range", adj = 0, line = -1, font = 4)
mtext("log(dbinom(k))", col = "red", adj = 1)
# }
Run the code above in your browser using DataLab