rsurGibbs {bayesm} | R Documentation |
Gibbs Sampler for Seemingly Unrelated Regressions (SUR)
Description
rsurGibbs
implements a Gibbs Sampler to draw from the posterior of the Seemingly Unrelated Regression (SUR) Model of Zellner.
Usage
rsurGibbs(Data, Prior, Mcmc)
Arguments
Data |
list(regdata) |
Prior |
list(betabar, A, nu, V) |
Mcmc |
list(R, keep) |
Details
Model and Priors
with
for
regressions
()'
with
Can be written as a stacked model:
where
is a
vector and
=
length(beta)
= sum(length(beta_i))
Note: must have the same number of observations () in each equation but can have a different number of
variables (
) for each equation where
.
Argument Details
Data = list(regdata)
regdata: | list of lists, regdata[[i]] = list(y=y_i, X=X_i) , where y_i is and X_i is
|
Prior = list(betabar, A, nu, V)
[optional]
betabar: | prior mean (def: 0) |
A: | prior precision matrix (def: 0.01*I) |
nu: | d.f. parameter for Inverted Wishart prior (def: m+3) |
V: | scale parameter for Inverted Wishart prior (def: nu*I)
|
Mcmc = list(R, keep)
[only R
required]
R: | number of MCMC draws |
keep: | MCMC thinning parameter -- keep every keep th draw (def: 1) |
nprint: | print the estimated time remaining for every nprint 'th draw (def: 100, set to 0 for no print)
|
Value
A list containing:
betadraw |
|
Sigmadraw |
|
Author(s)
Peter Rossi, Anderson School, UCLA, perossichi@gmail.com.
References
For further discussion, see Chapter 3, Bayesian Statistics and Marketing by Rossi, Allenby, and McCulloch.
See Also
Examples
if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=1000} else {R=10}
set.seed(66)
## simulate data from SUR
beta1 = c(1,2)
beta2 = c(1,-1,-2)
nobs = 100
nreg = 2
iota = c(rep(1, nobs))
X1 = cbind(iota, runif(nobs))
X2 = cbind(iota, runif(nobs), runif(nobs))
Sigma = matrix(c(0.5, 0.2, 0.2, 0.5), ncol=2)
U = chol(Sigma)
E = matrix(rnorm(2*nobs),ncol=2)%*%U
y1 = X1%*%beta1 + E[,1]
y2 = X2%*%beta2 + E[,2]
## run Gibbs Sampler
regdata = NULL
regdata[[1]] = list(y=y1, X=X1)
regdata[[2]] = list(y=y2, X=X2)
out = rsurGibbs(Data=list(regdata=regdata), Mcmc=list(R=R))
cat("Summary of beta draws", fill=TRUE)
summary(out$betadraw, tvalues=c(beta1,beta2))
cat("Summary of Sigmadraws", fill=TRUE)
summary(out$Sigmadraw, tvalues=as.vector(Sigma[upper.tri(Sigma,diag=TRUE)]))
## plotting examples
if(0){plot(out$betadraw, tvalues=c(beta1,beta2))}