breg                 package:bayesm                 R Documentation

_P_o_s_t_e_r_i_o_r _D_r_a_w_s _f_r_o_m _a _U_n_i_v_a_r_i_a_t_e _R_e_g_r_e_s_s_i_o_n _w_i_t_h _U_n_i_t _E_r_r_o_r _V_a_r_i_a_n_c_e

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

     'breg' makes one draw from the posterior of a univariate
     regression (scalar dependent variable) given the error variance =
     1.0. A natural conjugate, normal prior is used.

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

     breg(y, X, betabar, A)

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

       y: vector of values of dep variable. 

       X: n (length(y)) x k Design matrix. 

 betabar: k x 1 vector. Prior mean of regression coefficients. 

       A: Prior precision matrix. 

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

     model: y=x'beta + e.   e ~ N(0,1).  

     prior: beta ~ N(betabar,A^{-1}).

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

     k x 1 vector containing a draw from the posterior distribution.

_W_a_r_n_i_n_g:

     This routine is a utility routine that does *not* check the input
     arguments for proper dimensions and type.

     In particular, X must be a matrix. If you have a vector for X,
     coerce it into a matrix with one column

_A_u_t_h_o_r(_s):

     Peter Rossi, Graduate School of Business, University of Chicago,
     Peter.Rossi@ChicagoGsb.edu.

_R_e_f_e_r_e_n_c_e_s:

     For further discussion, see _Bayesian Statistics and Marketing_ by
     Rossi,Allenby and McCulloch. 
      <URL:
     http://gsbwww.uchicago.edu/fac/peter.rossi/research/bsm.html>

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

     ##

     if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=1000} else {R=10}

     ## simulate data
     set.seed(66)
     n=100
     X=cbind(rep(1,n),runif(n)); beta=c(1,2)
     y=X%*%beta+rnorm(n)
     ##
     ## set prior
     A=diag(c(.05,.05)); betabar=c(0,0)
     ##
     ## make draws from posterior
     betadraw=matrix(double(R*2),ncol=2)
     for (rep in 1:R) {betadraw[rep,]=breg(y,X,betabar,A)}
     ##
     ## summarize draws
     mat=apply(betadraw,2,quantile,probs=c(.01,.05,.5,.95,.99))
     mat=rbind(beta,mat); rownames(mat)[1]="beta"; print(mat)

