runireg {bayesm} | R Documentation |
runireg
implements an iid sampler to draw from the posterior of a univariate regression with a conjugate prior.
runireg(Data, Prior, Mcmc)
Data |
list(y,X) |
Prior |
list(betabar,A, nu, ssq) |
Mcmc |
list(R,keep) |
Model: y = Xbeta + e. e ~ N(0,sigmasq).
Priors: beta ~ N(betabar,sigmasq*A^{-1}). sigmasq ~ (nu*ssq)/chisq_{nu}. List arguments contain
X
y
betabar
A
nu
ssq
R
keep
list of iid draws
betadraw |
R x k array of betadraws |
sigmasqdraw |
R vector of sigma-sq draws |
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 2.
http://gsbwww.uchicago.edu/fac/peter.rossi/research/bsm.html
if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=2000} else {R=10} set.seed(66) n=200 X=cbind(rep(1,n),runif(n)); beta=c(1,2); sigsq=.25 y=X%*%beta+rnorm(n,sd=sqrt(sigsq)) out=runireg(Data=list(y=y,X=X),Mcmc=list(R=R)) cat(" betadraws ",fill=TRUE) mat=apply(out$betadraw,2,quantile,probs=c(.01,.05,.5,.95,.99)) mat=rbind(beta,mat); rownames(mat)[1]="beta"; print(mat) cat(" Sigma-sq draws",fill=TRUE) cat(" sigma-sq= ",sigsq,fill=TRUE) print(quantile(out$sigmasqdraw,probs=c(.01,.05,.5,.95,.99)))