The MCMC Procedure

Usage of Multivariate Distributions

(View the complete code for this example.)

The following simple example illustrates the usage of the multivariate distributions in PROC MCMC. Suppose you are interested in estimating the mean and covariance of multivariate data using this multivariate normal model:

where

You can use the following independent prior on and :

The following IML procedure statements simulate 100 random multivariate normal samples:

title 'An Example that Uses Multivariate Distributions';
proc iml;
   N = 100;
   Mean = {1 2};
   Cov =  {2.4 3, 3 8.1};
   call randseed(1);
   x = RANDNORMAL( N, Mean, Cov );

   SampleMean = x[:,];
   n = nrow(x);
   y = x - repeat( SampleMean, n );
   SampleCov = y`*y / (n-1);
   print SampleMean Mean, SampleCov Cov;

   cname = {"x1", "x2"};
   create inputdata from x [colname = cname];
   append from x;
   close inputdata;
quit;

Figure 74.13 prints the sample mean and covariance of the simulated data, in addition to the true mean and covariance matrix.

Figure 74.13: Simulated Multivariate Normal Data

An Example that Uses Multivariate Distributions

SampleMean Mean 
0.99877512.11569312

SampleCov Cov 
2.82529753.71907042.43
3.71907049.291680538.1


The following PROC MCMC statements estimate the posterior mean and covariance of the multivariate normal data:

proc mcmc data=inputdata seed=17 nmc=3000 diag=none;
   ods select PostSumInt;
   array data[2] x1 x2;
   array mu[2];
   array Sigma[2,2];
   array mu0[2] (0 0);
   array Sigma0[2,2] (100 0 0 100);
   array S[2,2] (1 0 0 1);
   parm mu Sigma;
   prior mu ~ mvn(mu0, Sigma0);
   prior Sigma ~ iwish(2, S);
   model data ~ mvn(mu, Sigma);
run;

To use the multivariate distribution, you must specify parameters (or random variables in the MODEL statement) in an array form. The first ARRAY statement creates an one-dimensional array data, which contains two numeric variables, x1 and x2, from the input data set. The data variable is your response variable. The subsequent statements defines two array-parameters (mu and Sigma) and three constant array-hyperparameters (mu0, Sigma0, and S). The PARMS statement declares mu and Sigma to be model parameters. The two PRIOR statements specify the multivariate normal and inverse Wishart distributions as the prior for mu and Sigma, respectively. The MODEL statement specifies the multivariate normal likelihood with data as the random variable, mu as the mean, and Sigma as the covariance matrix.

Figure 74.14 lists the estimated posterior statistics for the parameters.

Figure 74.14: Estimated Mean and Covariance

The MCMC Procedure

Posterior Summaries and Intervals
ParameterNMeanStandard
Deviation
95% HPD Interval
mu130000.99410.17630.63381.3106
mu230002.11350.31121.49392.7165
Sigma130002.87260.40842.10013.6723
Sigma230003.75730.64182.57915.0223
Sigma330003.75730.64182.57915.0223
Sigma430009.39871.32247.015512.0969