runiregGibbs: Gibbs Sampler for Univariate Regression

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/runireggibbs_rcpp.r

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 and Priors

y = Xβ + e with e ~ N(0, σ^2)

β ~ N(betabar, A^{-1})
σ^2 ~ (nu*ssq)/χ^2_{nu}

Argument Details

Data = list(y, X)

y: n x 1 vector of observations
X: n x k design matrix

Prior = list(betabar, A, nu, ssq) [optional]

betabar: k x 1 prior mean (def: 0)
A: k x k prior precision matrix (def: 0.01*I)
nu: d.f. parameter for Inverted Chi-square prior (def: 3)
ssq: scale parameter for Inverted Chi-square prior (def: var(y))

Mcmc = list(sigmasq, R, keep, nprint) [only R required]

sigmasq: value for σ^2 for first Gibbs sampler draw of β|σ^2
R: number of MCMC draws
keep: MCMC thinning parameter -- keep every keepth 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

R x k matrix of betadraws

sigmasqdraw

R x 1 vector of sigma-sq draws

Author(s)

Peter Rossi, Anderson School, UCLA, [email protected].

References

For further discussion, see Chapter 3, Bayesian Statistics and Marketing by Rossi, Allenby, and McCulloch.
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
if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=1000} else {R=10}
set.seed(66)

n = 200
X = cbind(rep(1,n), runif(n))
beta = c(1,2)
sigsq = 0.25
y = X%*%beta + rnorm(n,sd=sqrt(sigsq))

out = runiregGibbs(Data=list(y=y, X=X), Mcmc=list(R=R))

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

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

Example output

 
Starting Gibbs Sampler for Univariate Regression Model
  with  200  observations
 
Prior Parms: 
betabar
[1] 0 0
A
     [,1] [,2]
[1,] 0.01 0.00
[2,] 0.00 0.01
nu =  3  ssq=  0.5721252
 
MCMC parms: 
R=  10  keep=  1  nprint=  100
 
 MCMC Iteration (est time to end - min) 
 Total Time Elapsed: 0.00 
Summary of beta and Sigmasq draws
fewer than 100 draws submitted 
fewer than 100 draws submitted 

bayesm documentation built on July 21, 2017, 7:18 p.m.