Dirichlet               package:mixAK               R Documentation

_D_i_r_i_c_h_l_e_t _d_i_s_t_r_i_b_u_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     Random number generation for the Dirichlet distribution
     D(alpha[1],...,alpha[K]).

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

     rDirichlet(n, alpha=c(1, 1))

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

       n: number of observations to be sampled.

   alpha: parameters of the Dirichlet distribution (`prior sample
          sizes').

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

     Some objects.

_V_a_l_u_e _f_o_r _r_D_i_r_i_c_h_l_e_t:

     A matrix with sampled values.

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

     Arno&#353t Kom&#225rek arnost.komarek[AT]mff.cuni.cz

_R_e_f_e_r_e_n_c_e_s:

     Devroye, L. (1986). _Non-Uniform Random Variate Generation_. New
     York: Springer-Verlag, Chap. XI.

     Gelman, A., Carlin, J. B., Stern, H. S., and Rubin, D. B. (2004).
     _Bayesian Data Analysis. Second Edition_. Boca Raton: Chapman and
     Hall/CRC, pp. 576, 582.

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

     'rbeta'.

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

     set.seed(1977)

     alpha <- c(1, 2, 3)
     Mean <- alpha/sum(alpha)
     Var <- -(alpha %*% t(alpha))
     diag(Var) <- diag(Var) + alpha*sum(alpha)
     Var <- Var/(sum(alpha)^2*(1+sum(alpha)))
     x <- rDirichlet(1000, alpha=alpha)
     x[1:5,]

     apply(x, 1, sum)[1:5]           ### should be all ones
     rbind(Mean, apply(x, 2, mean))

     var(x)
     print(Var)

