rmultireg: Draw from the Posterior of a Multivariate Regression In bayesm: Bayesian Inference for Marketing/Micro-Econometrics

Description

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

Usage

 `1` ```rmultireg(Y, X, Bbar, A, nu, V) ```

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

Details

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

Priors:
β | Σ ~ N(betabar, Σ(x) A^{-1})
betabar = vec(Bbar); β = vec(B)
Σ ~ IW(nu, V)

Value

A list of the components of a draw from the posterior

 `B ` draw of regression coefficient matrix `Sigma ` draw of Sigma

Warning

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

Author(s)

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

References

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

Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37``` ```if(nchar(Sys.getenv("LONG_TEST")) != 0) {R=2000} else {R=10} set.seed(66) n =200 m = 2 X = cbind(rep(1,n),runif(n)) k = ncol(X) B = matrix(c(1,2,-1,3), ncol=m) Sigma = matrix(c(1, 0.5, 0.5, 1), ncol=m) RSigma = chol(Sigma) Y = X%*%B + matrix(rnorm(m*n),ncol=m)%*%RSigma betabar = rep(0,k*m) Bbar = matrix(betabar, ncol=m) A = diag(rep(0.01,k)) nu = 3 V = nu*diag(m) betadraw = matrix(double(R*k*m), ncol=k*m) Sigmadraw = matrix(double(R*m*m), ncol=m*m) for (rep in 1:R) { out = rmultireg(Y, X, Bbar, A, nu, V) betadraw[rep,] = out\$B Sigmadraw[rep,] = out\$Sigma } cat(" Betadraws ", fill=TRUE) mat = apply(betadraw, 2, quantile, probs=c(0.01, 0.05, 0.5, 0.95, 0.99)) mat = rbind(as.vector(B),mat) rownames(mat)[1] = "beta" print(mat) cat(" Sigma draws", fill=TRUE) mat = apply(Sigmadraw, 2 ,quantile, probs=c(0.01, 0.05, 0.5, 0.95, 0.99)) mat = rbind(as.vector(Sigma),mat); rownames(mat)[1]="Sigma" print(mat) ```

Example output

``` Betadraws
[,1]     [,2]       [,3]     [,4]
beta 1.0000000 2.000000 -1.0000000 3.000000
1%   0.8935809 1.661419 -1.2027068 2.629172
5%   0.9188952 1.685108 -1.1443588 2.665079
50%  1.0258584 2.071904 -0.9345797 3.167549
95%  1.2922225 2.450720 -0.6758421 3.539084
99%  1.3162992 2.475153 -0.6736775 3.685967
Sigma draws
[,1]      [,2]      [,3]      [,4]
Sigma 1.0000000 0.5000000 0.5000000 1.0000000
1%    0.8671183 0.4611315 0.4611315 0.8108963
5%    0.8694217 0.4665847 0.4665847 0.8346087
50%   0.9615998 0.5242548 0.5242548 0.9472345
95%   1.0561278 0.6926645 0.6926645 1.2994628
99%   1.0700665 0.6974689 0.6974689 1.3800294
```

bayesm documentation built on Dec. 21, 2018, 9:04 a.m.