Learn R Programming

bayesm (version 3.0-2)

rivGibbs: Gibbs Sampler for Linear "IV" Model

Description

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

Usage

rivGibbs(Data, Prior, Mcmc)

Arguments

Data

list(z,w,x,y)

Prior

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

Mcmc

list(R,keep,nprint) (R required)

Value

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

Details

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

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

Priors: \(\delta\) \(\sim\) \(N(md,Ad^{-1})\). \(vec(\beta,\gamma)\) \(\sim\) \(N(mbg,Abg^{-1})\) \(\Sigma\) \(\sim\) 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

  • md prior mean of delta (def: 0)

  • Ad pds prior prec for prior on delta (def: .01I)

  • mbg prior mean vector for prior on beta,gamma (def: 0)

  • Abg pds prior prec for prior on beta,gamma (def: .01I)

  • nu 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

  • keep MCMC thinning parm: keep every keepth draw (def: 1)

  • nprint print the estimated time remaining for every nprint'th draw (def: 100)

References

For further discussion, see Bayesian Statistics and Marketing by Rossi, Allenby and McCulloch, Chapter 5. http://www.perossi.org/home/bsm-1

Examples

Run this code
##
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)

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

cat("Summary of Beta draws",fill=TRUE)
summary(out$betadraw,tvalues=beta)
cat("Summary of Sigma draws",fill=TRUE)
summary(out$Sigmadraw,tvalues=as.vector(Sigma[upper.tri(Sigma,diag=TRUE)]))

if(0){
## plotting examples
plot(out$betadraw)
}

Run the code above in your browser using DataLab