MCnormalnormal           package:MCMCpack           R Documentation

_M_o_n_t_e _C_a_r_l_o _S_i_m_u_l_a_t_i_o_n _f_r_o_m _a _N_o_r_m_a_l _L_i_k_e_l_i_h_o_o_d (_w_i_t_h _k_n_o_w_n _v_a_r_i_a_n_c_e) _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:

     This function generates a sample from the posterior distribution
     of a Normal likelihood (with known variance) with a Normal prior.

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

     MCnormalnormal(y, sigma2, mu0, tau20, mc=1000, ...)

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

       y: The data.

  sigma2: The known variance of y.

     mu0: The prior mean of mu.

   tau20: The prior variance of mu.

      mc: The number of Monte Carlo draws to make.

     ...: further arguments to be passed

_D_e_t_a_i_l_s:

     'MCnormalnormal' directly simulates from the posterior
     distribution.  This model is designed primarily for instructional
     use.  mu is the parameter of interest of the Normal distribution.
     We assume a conjugate normal prior:

                          mu ~ N(mu0, tau20)

     y is a vector of observed data.

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

     An mcmc object that contains the posterior sample.  This  object
     can be summarized by functions provided by the coda package.

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

     'plot.mcmc', 'summary.mcmc'

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

     ## Not run: 
     y <- c(2.65, 1.80, 2.29, 2.11, 2.27, 2.61, 2.49, 0.96, 1.72, 2.40)
     posterior <- MCMCpack:::MCnormalnormal(y, 1, 0, 1, 5000)
     summary(posterior)
     plot(posterior)
     grid <- seq(-3,3,0.01)
     plot(grid, dnorm(grid, 0, 1), type="l", col="red", lwd=3, ylim=c(0,1.4),
        xlab="mu", ylab="density")
     lines(density(posterior), col="blue", lwd=3)
     legend(-3, 1.4, c("prior", "posterior"), lwd=3, col=c("red", "blue"))
     ## End(Not run)

