Binomial
The Binomial Distribution

Description

Calculates density, cumulative probability, quantile, and generate random sample for the binomial distribution (discrete).

Usage

dbinom(x, size, prob, log = FALSE) # density
pbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE) # probability
qbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE) # quantile
rbinom(n, size, prob) # random

Arguments

x, q numeric vectors in the range [0, size] that specify the quantiles.
p a numeric vector in the range [0, 1] that specifies the probabilities.
n an integer value in the range [0, Inf) that specifies the number of random samples requested. If the input value is not an integer, it is truncated. If length(n) is greater than 1, the random function returns length(n) random samples.
size an integer vector in the range [0, Inf) that specifies the number of Bernoulli trials (success/failure).
prob a numeric vector in the range [0, 1] that specifies the probability of a success in a Bernoulli trial.
log a logical value. If FALSE (default), the density function returns the density itself. If TRUE, it returns the log of the density.
lower.tail a logical value. If TRUE (default), the probability supplied to the quantile function or returned by the probability function is P[X <= x]. If FALSE, it is P[X > x].
log.p a logical value. If FALSE (default), the probability supplied to the quantile function or returned by the probability function is the probability itself. If TRUE, it is the log of the probability.

Details

The distribution parameter(s) are replicated cyclically to be the same length as the input x, q, p, or the number of random samples requested.
Missing values (NAs) in the input or the distribution parameter(s) will cause the corresponding elements of the result to be missing.
Value
returns density (dbinom), cumulative probability (pbinom), quantile (qbinom), or random sample (rbinom) for the binomial distribution with parameters size and prob. The quantile is defined as the smallest value q such that Pr(binomial random variate <= q) >= p.
Side Effects
If the .Random.seed dataset exists, the random sample function updates its value. The random sample function creates the .Random.seed dataset if it does not exist.
Background
The binomial distribution is the discrete probability distribution of the number of successes in a sequence of size independent experiments, each of which has only two possible outcomes (yes/no) (i.e., a Bernoulli trial) and yields success with probability prob. It has support on the integer set {0, 1, 2, …, size}.
For more information about the implementation of the uniform random number generator, see set.seed.
References
Hoel, P., Port, S. and Stone, C. (1971). Introduction to Probability Theory. Houghton-Mifflin, Boston, MA.
Johnson, N. L. and Kotz, S. (1970). Discrete Univariate Distributions, vol. 2. Houghton-Mifflin, Boston, MA.
See Also
NegBinomial, Hypergeometric, set.seed
Examples
rbinom(20, 10, 0.5)      # sample of size 20 with mean 10*0.5 = 5
rbinom(11, 10, 0:10/10)  # different values of prob
rbinom(10, 1:10, .5)     # different values of size
Package stats version 6.0.0-69
Package Index