binobp                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 _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 and a
     continous beta(a,b) prior.

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

     binobp(x, n, a = 1, b = 1, 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.

       a: parameter for the beta prior - must be greater than zero

       b: parameter for the beta prior - must be greater than zero

     ret: if true then the prior 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: 

posterior: the posterior density of pi given x and n - i.e. the
          beta(a+x,b+n-x) density

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

   prior: the prior density of pi, i.e. the beta(a,b) density

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

    mean: the posterior mean

     var: the posterior variance

      sd: the posterior std. deviation

quantiles: a set of quantiles from the posterior

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

     'binodp' 'binogcp'

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

     ## simplest call with 6 successes observed in 8 trials and a beta(1,1) uniform 
     ## prior
     binobp(6,8)

     ## 6 successes observed in 8 trials and a non-uniform beta(0.5,6) prior
     binobp(6,8,0.5,6)

     ## 4 successes observed in 12 trials with a non uniform beta(3,3) prior
     ## plot the stored prior, likelihood and posterior
     results<-binobp(4,12,3,3,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,ylim=c(0,0.25),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")

