rmultireg {rpud}R Documentation

Draw from the Posterior of a Multivariate Regression

Description

rmultireg draws from the posterior of a Multivariate Regression model with a natural conjugate prior.

Usage

rmultireg(Y, X, Bbar, A, nu, V, rep)

Arguments

Y

n x m matrix of observations on m dep vars

X

n x k matrix of observations on indep vars (supply intercept)

Bbar

k x m matrix of prior mean of regression coefficients

A

k x k Prior precision matrix

nu

d.f. parameter for Sigma

V

m x m pdf location parameter for prior on Sigma

rep

number of posterior sample draws

Details

Model: Y=XB+U. cov(u_i) = Sigma. B is k x m matrix of coefficients. Sigma is m x m covariance.

Priors: beta given Sigma \sim N(betabar,Sigma (x) A^{-1}). betabar=vec(Bbar); beta = vec(B)
Sigma \sim IW(nu,V).

Value

A list of the components of draws from the posterior

betadraw

draws of regression coefficient matrix

Sigmadraw

draws of Sigma

Author(s)

Chi Yau (based on R doc of rmultireg in bayesm by Peter Rossi)
chi.yau@r-tutor.com

References

Rossi, Allenby and McCulloch:
Bayesian Statistics and Marketing Ch 2
http://www.perossi.org/home/bsm-1

Examples

## Not run: 
library(rpud)

data.path <- file.path(path.package(package="rpud"), "runit/data")

# sample X
X <- read.table(
        file.path(data.path, "rmultireg-n100x2-x.txt"), 
        header=FALSE)
X <- as.matrix(X)

# sample Y
Y <- read.table(
        file.path(data.path, "rmultireg-n100x2-y.txt"), 
        header=FALSE)
Y <- as.matrix(Y)

# parameters
n <- nrow(X)
k <- ncol(X)
m <- ncol(Y)

Bbar <- matrix(c(1, 0, -1, 1),nrow=k,ncol=m)    # prior conjugate (normal) mean of B
A <- matrix(c(0.1, -0.05, -0.05, 0.1),nrow=k)   # prior conjugate (normal) precision of B
nu <- 3; V <- nu*diag(m)                        # prior Wishart params of Sigma

# mcmc params
R <- 2000

set.seed(66)
out <- rpud::rmultireg(Y, X, Bbar, A, nu, V, rep=R)

# true params
B <- matrix(c(1,2,-1,3),ncol=m)
Sigma <- matrix(c(1,.5,.5,1),ncol=m)

cat(" Beta draws ",fill=TRUE)
mat <- apply(out$betadraw,2,quantile,probs=c(.01,.05,.5,.95,.99))
mat <- rbind(as.vector(B),mat); rownames(mat)[1]="beta"
print(mat)

cat(" Sigma draws",fill=TRUE)
mat <- apply(out$Sigmadraw,2,quantile,probs=c(.01,.05,.5,.95,.99))
mat <- rbind(as.vector(Sigma),mat); rownames(mat)[1]="Sigma"
print(mat)

## End(Not run)

[Package rpud version 0.7.2 Index]