Binomial package:stats R Documentation _T_h_e _B_i_n_o_m_i_a_l _D_i_s_t_r_i_b_u_t_i_o_n _D_e_s_c_r_i_p_t_i_o_n: Density, distribution function, quantile function and random generation for the binomial distribution with parameters 'size' and 'prob'. _U_s_a_g_e: 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) _A_r_g_u_m_e_n_t_s: 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. size: number of trials (zero or more). 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 <= x], otherwise, P[X > x]. _D_e_t_a_i_l_s: The binomial distribution with 'size' = n and 'prob' = p has density p(x) = choose(n,x) p^x (1-p)^(n-x) for x = 0, ..., n. If an element of 'x' is not integer, the result of 'dbinom' is zero, with 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) >= p, where F is the distribution function. _V_a_l_u_e: '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. _S_o_u_r_c_e: For 'dbinom' a saddle-point expansion is used: see Catherine Loader (2000). _Fast and Accurate Computation of Binomial Probabilities_; available from . 'pbinom' uses 'pbeta'. 'qbinom' uses the Cornish-Fisher Expansion to include a skewness correction to a normal approximation, followed by a search. 'rbinom' (for 'size < .Machine$integer.max') is based on Kachitvichyanukul, V. and Schmeiser, B. W. (1988) Binomial random variate generation. _Communications of the ACM_, *31*, 216-222. _S_e_e _A_l_s_o: 'dnbinom' for the negative binomial, and 'dpois' for the Poisson distribution. _E_x_a_m_p_l_e_s: 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)