Posbinom                package:VGAM                R Documentation

_P_o_s_i_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 positive-binomial distribution.

_U_s_a_g_e:

     dposbinom(x, size, prob, log = FALSE)
     pposbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE)
     qposbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE)
     rposbinom(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. Must be a single positive integer. 

    size: number of trials. It is the N symbol in the formula given in
          'posbinomial'. 

    prob: probability of success on each trial. 

log, log.p, lower.tail: Arguments that are passed on to 'pbinom' etc.

_D_e_t_a_i_l_s:

     The positive-binomial distribution is a binomial distribution but
     with the probability of a zero being zero. The other probabilities
     are scaled to add to unity. The mean therefore is

                          mu / (1-(1-mu)^N)

     where mu is the argument 'prob' above. As mu increases, the
     positive-binomial and binomial distributions become more similar.
     Unlike similar functions for the binomial distribution, a zero
     value of 'prob' is not permitted here.

_V_a_l_u_e:

     'dposbinom' gives the density, 'pposbinom' gives the distribution
     function, 'qposbinom' gives the quantile function, and 'rposbinom'
     generates random deviates.

_N_o_t_e:

     For 'rposbinom', the arguments of the function are fed into
     'rbinom' until n positive values are obtained.  This may take a
     long time if 'prob' has values close to 0.

     The family function 'posbinomial' estimates the parameters by
     maximum likelihood estimation.

_A_u_t_h_o_r(_s):

     T. W. Yee

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

     'posbinomial', 'rbinom'.

_E_x_a_m_p_l_e_s:

     prob = 0.2
     size = 10
     y = rposbinom(n=1000, size, prob)
     table(y)
     mean(y)  # Sample mean
     prob / (1-(1-prob)^size) # Population mean

     (i = dposbinom(0:size, size, prob))
     cumsum(i) - pposbinom(0:size, size, prob)  # Should be 0s
     table(rposbinom(100, size, prob))

     table(qposbinom(runif(1000), size, prob))
     round(dposbinom(1:10, size, prob) * 1000) # Should be similar

     ## Not run: 
     x = 0:size
     plot(x, dposbinom(x, size, prob), type="h", ylab="Probability",
          main=paste("Positive-binomial(", size, ",", prob, ") (blue) vs",
          " Binomial(", size, ",", prob, ") (red and shifted slightly)", sep=""),
          lwd=2, col="blue", las=1)
     lines(x+0.05, dbinom(x, size, prob), type="h", lwd=2, col="red")
     ## End(Not run)

