binomixp               package:Bolstad               R Documentation

_B_i_n_o_m_i_a_l _s_a_m_p_l_i_n_g _w_i_t_h _a _b_e_t_a _m_i_x_t_u_r_e _p_r_i_o_r

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

     Evaluates and plots the posterior density for pi, the probability
     of a success in a Bernoulli trial, with binomial sampling when the
     prior density for pi is a mixture of two beta distributions,
     beta(a_0,b_0) and beta(a_1,b_1).

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

     binomixp(x, n, alpha0=c(1,1), alpha1=c(1,1), p=0.5, ret = FALSE)

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

       x: the number of observed successes in the binomial experiment.

       n: the number of trials in the binomial experiment.

  alpha0: a vector of length two containing the parameters, a0 and b0,
          for the first component beta prior - must be greater than
          zero. By default the elements of alpha0 are set to 1.

  alpha1: a vector of length two containing the parameters, a1 and b1,
          for the second component beta prior - must be greater than
          zero. By default the elements of alpha1 are set to 1.

       p: The prior mixing proportion for the two component beta
          priors. That is the prior is p*beta(a0,b0)+(1-p)*beta(a1,b1).
          p is set to 0.5 by default

     ret: if TRUE then the prior, the likelihood and posterior are
          returned as a list.

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

     If ret is true, then a list will be returned with the following
     components: 

      pi: the values of pi for which the posterior density was
          evaluated

posterior: the posterior density of pi given n and x

likelihood: the likelihood function for pi given x and n, i.e. the
          binomial(n,pi) density

   prior: the prior density of pi density

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

     'binodp' 'binogcp' 'normmixp'

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

     ## simplest call with 6 successes observed in 8 trials and a 50:50 mix
     ## of two beta(1,1) uniform priors
     binomixp(6,8)

     ## 6 successes observed in 8 trials and a 20:80 mix of a non-uniform
     ## beta(0.5,6) prior and a uniform beta(1,1) prior
     binomixp(6,8,alpha0=c(0.5,6),alpha1=c(1,1),p=0.2)

     ## 4 successes observed in 12 trials with a 90:10 non uniform beta(3,3) prior
     ## and a non uniform beta(4,12).
     ## Plot the stored prior, likelihood and posterior
     results<-binomixp(4,12,c(3,3),c(4,12),0.9,ret=TRUE)

     par(mfrow=c(3,1))
     y.lims<-c(0,1.1*max(results$posterior,results$prior))

     plot(results$pi,results$prior,ylim=y.lims,type="l"
             ,xlab=expression(pi),ylab="Density",main="Prior")
     polygon(results$pi,results$prior,col="red")

     plot(results$pi,results$likelihood,type="l"
             ,xlab=expression(pi),ylab="Density",main="Likelihood")
     polygon(results$pi,results$likelihood,col="green")

     plot(results$pi,results$posterior,ylim=y.lims,type="l"
             ,xlab=expression(pi),ylab="Density",main="Posterior")
     polygon(results$pi,results$posterior,col="blue")

