

NegBinomial {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_:

     These functions provide information about the negative
     binomial distribution with parameters `size' and
     `prob'.  `dnbinom' gives the density, `pnbinom' gives
     the distribution function, `qnbinom' gives the quantile
     function and `rnbinom' generates random deviates.

_U_s_a_g_e_:

     dnbinom(x, size, prob)
     pnbinom(q, size, prob)
     qnbinom(p, size, prob)
     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 distribu-
          tion 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-inte-
          ger 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 /
          shape parameter of gamma distribution.

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

_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 left continuous: `qnbinom(q, ...)' is
     the largest integer x such that P(X <= x) < q.

_S_e_e _A_l_s_o_:

     `dbinom' for the binomial, `dpois' for the Poisson and
     `dgeom' for the geometric distribution, which is a spe-
     cial 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)))
     title(tit <- "negative binomial density(x,s, pr = 0.4)  vs.  x & s")
     ## if persp() only could label axes ....

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

