normdp                package:Bolstad                R Documentation

_B_a_y_e_s_i_a_n _i_n_f_e_r_e_n_c_e _o_n _a _n_o_r_m_a_l _m_e_a_n _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 mu, the mean of a
     normal distribution, with a discrete prior on mu

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

     normdp(x, sigma.x = NULL, mu = NULL, mu.prior = NULL, n.mu = 50,
             ret = FALSE)

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

       x: a vector of observations from a normal distribution with
          unknown mean and known std. deviation.

 sigma.x: the population std. deviation of the normal distribution

      mu: a vector of possibilities for the probability of success in a
          single trial. If mu is NULL then a uniform prior is used.

mu.prior: the associated prior probability mass.

    n.mu: the number of possible mu 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: 

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

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

likelihood: the scaled likelihood function for mu given x and sigma.x

posterior: the posterior probability of mu given x and sigma.x

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

     'normnp' 'normgcp'

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

     ## generate a sample of 20 observations from a N(-0.5,1) population
     x<-rnorm(20,-0.5,1)

     ## find the posterior density with a uniform prior on mu
     normdp(x,1)

     ## find the posterior density with a non-uniform prior on mu
     mu<-seq(-3,3,by=0.1)
     mu.prior<-runif(length(mu))
     mu.prior<-sort(mu.prior/sum(mu.prior))
     normdp(x,1,mu,mu.prior)

     ## Let mu have the discrete distribution with 5 possible
     ## values, 2, 2.5, 3, 3.5 and 4, and associated prior probability of
     ## 0.1, 0.2, 0.4, 0.2, 0.1 respectively. Find the posterior 
     ## distribution after a drawing random sample of n = 5 observations 
     ## from a N(mu,1) distribution y = [1.52, 0.02, 3.35, 3.49, 1.82]
     mu<-seq(2,4,by=0.5)
     mu.prior<-c(0.1,0.2,0.4,0.2,0.1)
     y<-c(1.52,0.02,3.35,3.49,1.82)
     normdp(y,1,mu,mu.prior)

