binodp                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 _d_i_s_c_r_e_t_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 and a
     discrete prior on pi

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

     binodp(x,n, pi = NULL, pi.prior = NULL, n.pi = 10, 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.

      pi: a vector of possibilities for the probability of success in a
          single trial. if 'pi' is 'NULL' then a discrete uniform prior
          for pi will be used.

pi.prior: the associated prior probability mass.

    n.pi: the number of possible pi values in the prior

     ret: if true then 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 vector of possible pi values used in the prior

pi.prior: the associated probability mass for the values in pi

likelihood: the scaled likelihood function for pi given x and n

posterior: the posterior probability of pi given x and n

  f.cond: the conditional distribution of x given pi and n

 f.joint: the joint distribution of x and pi given n

  f.marg: the marginal distribution of x

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

     'binobp' 'binogcp'

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

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

     ## same as previous example but with more possibilities for pi
     binodp(6,8,n.pi=100)

     ## 6 successes, 8 trials and a non-uniform discrete prior
     pi<-seq(0,1,by=0.01)
     pi.prior<-runif(101)
     pi.prior<-sort(pi.prior/sum(pi.prior))
     binodp(6,8,pi,pi.prior)

     ## 5 successes, 6 trials, non-uniform prior
     pi<-c(0.3,0.4,0.5)
     pi.prior<-c(0.2,0.3,0.5)
     results<-binodp(5,6,pi,pi.prior,ret=TRUE)

     ## plot the results from the previous example using a side-by-side barplot
     results.matrix<-rbind(results$pi.prior,results$posterior)
     colnames(results.matrix)<-pi
     barplot(results.matrix,col=c("red","blue"),beside=TRUE
             ,xlab=expression(pi),ylab=expression(Probability(pin)))
     box()
     legend(1,0.65,legend=c("Prior","Posterior"),fill=c("red","blue"))

