| rivGibbs {bayesm} | R Documentation |
rivGibbs is a Gibbs Sampler for a linear structural equation with an arbitrary number of instruments.
rivGibbs(Data, Prior, Mcmc)
Data |
list(z,w,x,y) |
Prior |
list(md,Ad,mbg,Abg,nu,V) (optional) |
Mcmc |
list(R,keep) (R required) |
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:
zyxwmdAdmbgAbgnuVRkeepa 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 |
Rob McCulloch and Peter Rossi, Graduate School of Business, University of Chicago, Peter.Rossi@ChicagoGsb.edu.
For further discussion, see Bayesian Statistics and Marketing
by Rossi, Allenby and McCulloch, Chapter 5.
http://faculty.chicagogsb.edu/peter.rossi/research/bsm.html
##
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)
}