Gibbs Sampler for Univariate Regression

Description

runiregGibbs implements a Gibbs Sampler to draw from posterior of a univariate regression with a conditionally conjugate prior.

Usage

1
runiregGibbs(Data, Prior, Mcmc)

Arguments

Data

list(y,X)

Prior

list(betabar,A, nu, ssq)

Mcmc

list(sigmasq,R,keep,nprint)

Details

Model: y = Xβ + e. e ~ N(0,σ^2).

Priors: β ~ N(betabar,A^{-1}). σ^2 ~ (nu*ssq)/χ^2_{nu}. List arguments contain

  • Xn x k Design Matrix

  • yn x 1 vector of observations

  • betabark x 1 prior mean (def: 0)

  • Ak x k prior precision matrix (def: .01I)

  • nu d.f. parm for Inverted Chi-square prior (def: 3)

  • ssq scale parm for Inverted Chi-square prior (def:var(y))

  • R number of MCMC draws

  • keep thinning parameter - keep every keepth draw

  • nprint print the estimated time remaining for every nprint'th draw (def: 100)

Value

list of MCMC draws

betadraw

R x k array of betadraws

sigmasqdraw

R vector of sigma-sq draws

Author(s)

Peter Rossi, Anderson School, UCLA, perossichi@gmail.com.

References

For further discussion, see Bayesian Statistics and Marketing by Rossi, Allenby and McCulloch, Chapter 3.
http://www.perossi.org/home/bsm-1

See Also

runireg

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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))

Data1=list(y=y,X=X); Mcmc1=list(R=R) 

out=runiregGibbs(Data=Data1,Mcmc=Mcmc1)

cat("Summary of beta and Sigma draws",fill=TRUE)
summary(out$betadraw,tvalues=beta)
summary(out$sigmasqdraw,tvalues=sigsq)

if(0){
## plotting examples
plot(out$betadraw)
}

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.