%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This code generates samples of HIW(bG,DG) for decomposable graphs %
% as defined in Carvalho, Massam and West (2007). %
% %
% The example here is based on the exchange rate example in the paper %
% Code uses the Matlab Statistics Toolbox function wishrnd %
% Carlos Carvalho & Mike West, May 1st 2007 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear
load HIWcodeData.mat
who % graph G is a cell array with 2 cells -
% the prime component and separator structures
% G = {components,separators}
[n,p]=size(X); X=X-repmat(mean(X),n,1); % zero mean each variable
M = 1000; % Monte Carlo sample size
bG = n; % degrees of freedom b in case of a reference posterior HIW
DG = X'*X; % "sum of squares" location matrix D in case of a reference posterior HIW
[Omega,Sigma] = HIWsim(G,bG,DG,M); % samples M precision and corresponding variance
% matrices on the graph G
%-------------------------------------------------------------------------------------
% mean of Omega when Sigma~HIW(bG,DG):
OmG = meanOmegaHIW(G,bG,DG); SiG = inv(OmG);
% mean of Sigma and mean of Omega on "full graph":
Sifull = DG/(bG-2); Omfull=(bG+p-1)*inv(DG);