rivGibbs               package:bayesm               R Documentation

_G_i_b_b_s _S_a_m_p_l_e_r _f_o_r _L_i_n_e_a_r "_I_V" _M_o_d_e_l

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

     'rivGibbs' is a Gibbs Sampler for a linear structural equation
     with an arbitrary number of instruments.

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

     rivGibbs(Data, Prior, Mcmc)

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

    Data: list(z,w,x,y) 

   Prior: list(md,Ad,mbg,Abg,nu,V) (optional) 

    Mcmc: list(R,keep) (R required) 

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

     Model:
      x=z'delta + e1. 
      y=beta*x + w'gamma + e2. 
      e1,e2 ~ N(0,Sigma). 

     Note: if intercepts are desired in either equation, include vector
     of ones in z or w

     Priors:
      delta ~ N(md,Ad^{-1}).  vec(beta,gamma) ~ N(mbg,Abg^{-1}) 
      Sigma ~ IW(nu,V)

     List arguments contain:

   '_z' matrix of obs on instruments

   '_y' vector of obs on lhs var in structural equation

   '_x' "endogenous" var in structural eqn

   '_w' matrix of obs on "exogenous" vars in the structural eqn

   '_m_d' prior mean of delta (def: 0)

   '_A_d' pds prior prec for prior on delta (def: .01I)

   '_m_b_g' prior mean vector for prior on beta,gamma (def: 0)

   '_A_b_g' pds prior prec  for prior on beta,gamma (def: .01I)

   '_n_u' d.f. parm for IW prior on Sigma (def: 5)

   '_V' pds location matrix for IW prior on Sigma (def: nuI)

   '_R' number of MCMC draws

   '_k_e_e_p' MCMC thinning parm: keep every keepth draw (def: 1) 

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

     a list containing: 

deltadraw: R/keep x dim(delta) array of delta draws

betadraw: R/keep x 1 vector of beta draws

gammadraw: R/keep x dim(gamma) array of gamma draws 

Sigmadraw: R/keep x 4 array of Sigma draws

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

     Rob McCulloch and 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, Chapter 5. 
      <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=2000} else {R=10}

     set.seed(66)
     simIV = function(delta,beta,Sigma,n,z,w,gamma) {
     eps = matrix(rnorm(2*n),ncol=2) %*% chol(Sigma)
     x = z %*% delta + eps[,1]; y = beta*x +  eps[,2] + w%*%gamma
     list(x=as.vector(x),y=as.vector(y)) }
     n = 200 ; p=1 # number of instruments
     z = cbind(rep(1,n),matrix(runif(n*p),ncol=p))
     w = matrix(1,n,1)
     rho=.8
     Sigma = matrix(c(1,rho,rho,1),ncol=2)
     delta = c(1,4); beta = .5; gamma = c(1)
     simiv = simIV(delta,beta,Sigma,n,z,w,gamma)

     Mcmc=list(); Prior=list(); Data = list()
     Data$z = z; Data$w=w; Data$x=simiv$x; Data$y=simiv$y
     Mcmc$R = R
     Mcmc$keep=1
     out=rivGibbs(Data=Data,Prior=Prior,Mcmc=Mcmc)

     cat(" deltadraws ",fill=TRUE)
     mat=apply(out$deltadraw,2,quantile,probs=c(.01,.05,.5,.95,.99))
     mat=rbind(delta,mat); rownames(mat)[1]="delta"; print(mat)
     cat(" betadraws ",fill=TRUE)
     qout=quantile(out$betadraw,probs=c(.01,.05,.5,.95,.99))
     mat=matrix(qout,ncol=1)
     mat=rbind(beta,mat); rownames(mat)=c("beta",names(qout)); print(mat)
     cat(" Sigma draws",fill=TRUE)
     mat=apply(out$Sigmadraw,2,quantile,probs=c(.01,.05,.5,.95,.99))
     mat=rbind(as.vector(Sigma),mat); rownames(mat)[1]="Sigma"; print(mat)

