Betabin                 package:VGAM                 R Documentation

_T_h_e _B_e_t_a-_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, and random generation for the
     beta-binomial distribution.

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

     dbetabin(x, size, prob, rho, log=FALSE)
     pbetabin(q, size, prob, rho, log.p=FALSE)
     rbetabin(n, size, prob, rho)
     dbetabin.ab(x, size, shape1, shape2, log=FALSE)
     pbetabin.ab(q, size, shape1, shape2, log.p=FALSE)
     rbetabin.ab(n, size, shape1, shape2)

_A_r_g_u_m_e_n_t_s:

    x, q: vector of quantiles.

    size: number of trials.

       n: number of observations. Must be a positive integer of length
          1.

    prob: the probability of success mu. Must be in the unit open
          interval (0,1).

     rho: the correlation parameter rho. Must be in the unit open
          interval (0,1).

shape1, shape2: the two (positive) shape parameters of the standard
          beta distribution. They are called 'a' and 'b' in 'beta'
          respectively.

log, log.p: Logical. If 'TRUE' then all probabilities 'p' are given as
          'log(p)'.

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

     The beta-binomial distribution is a binomial distribution whose
     probability of success is not a constant but it is generated from
     a beta distribution with parameters 'shape1' and 'shape2'. Note
     that the mean of this beta distribution is
     'mu=shape1/(shape1+shape2)', which therefore is the mean or the
     probability of success.

     See 'betabinomial' and 'betabin.ab', the 'VGAM' family functions
     for estimating the parameters, for the formula of the probability
     density function and other details.

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

     'dbetabin' and 'dbetabin.ab' give the density, 'pbetabin' and
     'pbetabin.ab' give the distribution function, and 'rbetabin' and
     'rbetabin.ab' generate random deviates.

_N_o_t_e:

     'pbetabin' and 'pbetabin.ab' can be particularly slow. The
     functions here ending in '.ab' are called from those functions
     which don't. The simple transformations mu=alpha/(alpha+beta) and
     rho=1/(1+alpha+beta) are used, where alpha and beta are the two
     shape parameters.

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

     T. W. Yee

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

     'betabinomial', 'betabin.ab'.

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

     ## Not run: 
     N = 9; x = 0:N; s1=2; s2=3
     dy = dbetabin.ab(x, size=N, shape1=s1, shape2=s2)
     plot(x, dy, type="h", col="red", ylim=c(0,0.25), ylab="Probability",
          main=paste("Beta-binomial (size=",N,", shape1=",s1,
                     ", shape2=",s2,")", sep=""))
     lines(x+0.1, dbinom(x, size=N, prob=s1/(s1+s2)), type="h", col="blue")
     sum(dy*x) # Check expected values are equal
     sum(dbinom(x, size=N, prob=s1/(s1+s2))*x)
     cumsum(dy) -  pbetabin.ab(x, N, shape1=s1, shape2=s2)

     y = rbetabin.ab(n=10000, size=N, shape1=s1, shape2=s2)
     ty = table(y)
     lines(as.numeric(names(ty))+0.2, ty/sum(ty), type="h", col="green")
     legend(5, 0.25, leg=c("beta-binomial","binomial", "random generated"),
            col=c("red","blue","green"), lty=1)
     ## End(Not run)

