rivGibbs {bayesm} | R Documentation

## 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) (R required)

### Details

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
`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)

### 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

### Author(s)

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

### References

For further discussion, see Bayesian Statistics and Marketing by Rossi, Allenby and McCulloch, Chapter 5.
http://gsbwww.uchicago.edu/fac/peter.rossi/research/bsm.html

### Examples

    ##
    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)

[Package bayesm version 2.0-8 Index]