function w=matrictint(S,XXi,T) S: usually sample cross product matrix of LS residuals XXi: inv(X'X) matrix for rhs variables T: number of observations w: log of integrated posterior for SUR or RF VAR with det(Sigma)^(-(m+1)/2) Jeffreys-like prior To get the log of the integral of the likelihood for a VAR with T observations, k rhs variables in each equation, and m equations, set T=T-m-1 and subtract .5*m*(m+1)*log(2*pi). We are integrating the exponential of -.5*T*m*log(2*pi)-.5*(T+m+1)*log(det(Sigma))-.5*trace(Sigma\S(beta)).
0001 function w=matrictint(S,XXi,T) 0002 %function w=matrictint(S,XXi,T) 0003 % S: usually sample cross product matrix of LS residuals 0004 % XXi: inv(X'X) matrix for rhs variables 0005 % T: number of observations 0006 % w: log of integrated posterior for SUR or RF VAR with det(Sigma)^(-(m+1)/2) Jeffreys-like prior 0007 % To get the log of the integral of the likelihood for a VAR with T observations, 0008 % k rhs variables in each equation, and m equations, set T=T-m-1 and subtract .5*m*(m+1)*log(2*pi). 0009 % We are integrating the exponential of -.5*T*m*log(2*pi)-.5*(T+m+1)*log(det(Sigma))-.5*trace(Sigma\S(beta)). 0010 k=size(XXi,1); 0011 m=size(S,1); 0012 [cx,p]=chol(XXi); 0013 [cs,q]=chol(S); 0014 %cx=cschol(XXi); 0015 %cs=cschol(S); 0016 if any(diag(cx)<100*eps) 0017 error('singular XXi') 0018 end 0019 if any(diag(cs<100*eps)) 0020 error('singular S') 0021 end 0022 w=(-T+k+(m-1)/2)*m*.5*log(pi)-(T-k)*sum(log(diag(cs)))+m*sum(log(diag(cx)))+ggammaln(m,(T-k)/2); 0023 0024 function lgg=ggammaln(m,ndf) 0025 %function gg=ggamma(m,ndf) 0026 % From 8.2.22 on p.427 of Box and Tiao, this is the log of generalized 0027 % gamma divided by gamma(.5)^(.5*m*(m-1)) 0028 if ndf<=(m-1)/2 0029 error('too few df in ggammaln') 0030 else 0031 %lgg=.5*m*(m-1)*gammaln(.5); % normalizing factor not used in Wishart integral 0032 garg=ndf+.5*(0:-1:1-m); 0033 lgg=sum(gammaln(garg)); 0034 end 0035