NegBinomial               package:base               R Documentation

_T_h_e _N_e_g_a_t_i_v_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 negative binomial distribution with parameters
     `size' and `prob'.

_U_s_a_g_e:

     dnbinom(x, size, prob, log = FALSE)
     pnbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE)
     qnbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE)
     rnbinom(n, size, prob)

_A_r_g_u_m_e_n_t_s:

    x, q: vector of quantiles representing the number of failures which
          occur in a sequence of Bernoulli trials before a target
          number of successes is reached, or alternately the
          probability distribution of a compound Poisson process whose
          intensity is distributed as a gamma (`pgamma') distribution
          with scale parameter `(1-prob)/prob' and shape parameter
          `size' (this definition allows non-integer values of `size').

       x: vector of (non-negative integer) quantiles.

       q: vector of quantiles.

       p: vector of probabilities.

       n: number of observations to generate.

    size: target for number of successful trials, or shape parameter of
          gamma distribution.

    prob: probability of success in each trial, or scale of gamma
          distribution (`prob' = `scale/(1+scale)').

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 negative binomial distribution with `size' = n and `prob' = p
     has density

             p(x) = Gamma(x+n)/(Gamma(n) x!) p^n (1-p)^x

     for x = 0, 1, 2, ...

     If an element of `x' is not integer, the result of `dnbinom' is
     zero, with a warning.

     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:

     `dnbinom' gives the density, `pnbinom' gives the distribution
     function, `qnbinom' gives the quantile function, and `rnbinom'
     generates random deviates.

_S_e_e _A_l_s_o:

     `dbinom' for the binomial, `dpois' for the Poisson and `dgeom' for
     the geometric distribution, which is a special case of the
     negative binomial.

_E_x_a_m_p_l_e_s:

     x <- 0:11
     dnbinom(x, size = 1, prob = 1/2) * 2^(1 + x) # == 1
     126 /  dnbinom(0:8, size  = 2, prob  = 1/2) #- theoretically integer

     ## Cumulative ('p') = Sum of discrete prob.s ('d');  Relative error :
     summary(1 - cumsum(dnbinom(x, size = 2, prob = 1/2)) /
                       pnbinom(x, size  = 2, prob = 1/2))

     x <- 0:15
     size <- (1:20)/4
     persp(x,size, dnb <- outer(x,size,function(x,s)dnbinom(x,s, pr= 0.4)),
           xlab = "x", ylab = "s", zlab="density", theta = 150)
     title(tit <- "negative binomial density(x,s, pr = 0.4)  vs.  x & s")

     image  (x,size, log10(dnb), main= paste("log [",tit,"]"))
     contour(x,size, log10(dnb),add=TRUE)

