normnp                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 _n_o_r_m_a_l _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 normal prior on mu

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

     normnp(x, m.x = 0, s.x = 1, sigma.x = NULL, n.mu = 100, 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.

     m.x: the mean of the normal prior

     s.x: the standard deviation of the normal prior

 sigma.x: the population std. deviation of the normal distribution. If
          this value is NULL, which is is by default, then a flat prior
          is used and m.x and s.x are ignored

    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

    mean: the posterior mean

      sd: the posterior standard deviation

    qtls: a selection of quantiles from the posterior density

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

     'normdp' '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 N(0,1) prior on mu
     normnp(x,sigma=1)

     ## find the posterior density with N(0.5,3) prior on mu
     normnp(x,0.5,3,1)

     ## Find the posterior density for mu, given a random sample of 4 
     ## observations from N(mu,sigma^2=1), y = [2.99, 5.56, 2.83, 3.47], 
     ## and a N(3,sd=2)$ prior for mu
     y<-c(2.99,5.56,2.83,3.47)
     normnp(y,3,2,1)

