poisgamp               package:Bolstad               R Documentation

_P_o_i_s_s_o_n _s_a_m_p_l_i_n_g _w_i_t_h _a _g_a_m_m_a _p_r_i_o_r

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

     Evaluates and plots the posterior density for mu, the mean rate of
     occurance in a Poisson process and a gamma prior on mu

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

     poisgamp(y, r, v, ret = FALSE)

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

       y: a random sample from a Poisson distribution.

       r: the shape parameter of the gamma prior.

       v: the rate parameter of the gamma prior. Note that the scale is
          1/v

     ret: if true then the prior, likelihood, posterior as well as the
          posterior values of r and v are returned as a list.

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

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

   prior: the prior density assigned to mu

likelihood: the scaled likelihood function for mu given y

posterior: the posterior probability of mu given y

       r: the shape parameter for the gamma posterior

       v: the rate parameter for the gamma posterior

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

     'poisdp' 'poisgcp'

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

     ## simplest call with an observation of 4 and a gamma(1,1), i.e. an exponential prior on the
     ## mu
     poisgamp(4,1,1)

     ##  Same as the previous example but a gamma(10,1) prior
     poisgamp(4,10,1)

     ##  Same as the previous example but an improper gamma(1,0) prior
     poisgamp(4,1,0)

     ## A random sample of 50 observations from a Poisson distribution with
     ## parameter mu = 3 and  gamma(6,3) prior
     y<-rpois(50,3)
     poisgamp(y,6,3)

     ## In this example we have a random sample from a Poisson distribution
     ## with an unknown mean. We will use a gamma(6,3) prior to obtain the
     ## posterior gamma distribution, and use the R function qgamma to get a
     ## 95% credible interval for mu
     y<-c(3,4,4,3,3,4,2,3,1,7)
     retval<-poisgamp(y,6,3,ret=TRUE)
     c.i.<-qgamma(c(0.025,0.975),retval$r, retval$v)
     cat(paste("95% credible interval for mu: [",round(c.i.[1],3), ",", round(c.i.[2],3)),"]\n") 

