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 theta, the
     probability of a success in a Bernoulli trial, with binomial
     sampling and a discrete prior on theta

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

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

 uniform: if true then a discrete uniform prior for theta will be used.

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

   theta: a vector of possibilities for the probability of success in a
          single trial.

theta.prior: the associated prior probability mass.

     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: 

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

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

  f.marg: the marginal distribution of x

likelihood: the scaled likelihood function of x given theta and n

posterior: the posterior probability of theta given x and n

   theta: the vector of possible theta values used in the prior

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

_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 theta
     binodp(6,8,n.theta=100)

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

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

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

