Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

breg

Posterior Draws from a Univariate Regression with Unit Error Variance


Description

breg makes one draw from the posterior of a univariate regression (scalar dependent variable) given the error variance = 1.0. A natural conjugate (normal) prior is used.

Usage

breg(y, X, betabar, A)

Arguments

y

n x 1 vector of values of dep variable

X

n x k design matrix

betabar

k x 1 vector for the prior mean of the regression coefficients

A

k x k prior precision matrix

Details

model: y = X'β + e with e ~ N(0,1).
prior: β ~ N(betabar, A^{-1}).

Value

k x 1 vector containing a draw from the posterior distribution

Warning

This routine is a utility routine that does not check theinput arguments for proper dimensions and type. In particular, X must be a matrix. If you have a vector for X, coerce itinto a matrix with one column.

Author(s)

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

References

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

Examples

if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=1000} else {R=10}

## simulate data
set.seed(66)
n = 100
X = cbind(rep(1,n), runif(n)); beta = c(1,2)
y = X %*% beta + rnorm(n)

## set prior
betabar = c(0,0)
A = diag(c(0.05, 0.05))

## make draws from posterior
betadraw = matrix(double(R*2), ncol = 2)
for (rep in 1:R) {betadraw[rep,] = breg(y,X,betabar,A)}

## summarize draws
mat = apply(betadraw, 2, quantile, probs=c(0.01, 0.05, 0.50, 0.95, 0.99))
mat = rbind(beta,mat); rownames(mat)[1] = "beta"
print(mat)

bayesm

Bayesian Inference for Marketing/Micro-Econometrics

v3.1-4
GPL (>= 2)
Authors
Peter Rossi <perossichi@gmail.com>
Initial release
2019-10-14

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.