Learn R Programming

bayesm (version 1.1-2)

runireg: Draw from Posterior for Univariate Regression

Description

runireg draws from posterior for univariate regression with a natural conjugate prior.

Usage

runireg(y, X, betabar, A, nu, ssq)

Arguments

y
n x 1 dep var
X
n x k Design matrix
betabar
prior mean
A
k x k pds prior precision matrix
nu
d.f. parameter for sigma-sq prior
ssq
scale parameter for sigma-sq prior

Value

  • a list with one draw from posterior
  • betabeta draw
  • sigmasqsigmasq draw

concept

  • bayes
  • regression
  • simulation

Warning

This routine is a utility routine that does not check the input arguments for proper dimensions and type.

Details

Model: $y = Xbeta + e$. $e$ $\sim$ $N(0,sigmasq)$. Priors: beta given sigmasq $\sim$ $N(betabar,sigmasq*A^{-1})$. $sigmasq$ $\sim$ eqn{(nu*ssq)}/$\chi^2_{nu}$.

References

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

See Also

runiregGibbs

Examples

Run this code
if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=1000} else {R=10}
set.seed(66)
n=100
X=cbind(rep(1,n),runif(n)); beta=c(1,2); sigsq=.25
y=X%*%beta+rnorm(n,sd=sqrt(sigsq))

A=diag(c(.05,.05)); betabar=c(0,0)
nu=3; ssq=1.0

betadraw=matrix(double(R*2),ncol=2)
sigsqdraw=double(R)
for (rep in 1:R) 
   {out=runireg(y,X,betabar,A,nu,ssq);betadraw[rep,]=out$beta
    sigsqdraw[rep]=out$sigmasq}

cat("Betadraws ",fill=TRUE)
mat=apply(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(sigsqdraw,probs=c(.01,.05,.5,.95,.99)))

Run the code above in your browser using DataLab