# Effective Sample Size for posterior in Matlab

I am trying to implement unsuccessfully a function in matlab, to compute the effective sample size after a MCMC chain, with a posterior with 3 coefficients. Source: Sims MCMC

$VAR(1) / Y_t=\mu +AY_{t-1}+ \epsilon_t$

I think that I need to compute $T\Gamma(0)/\sum_{i=1}^{n}(\Gamma(J)$

If a VAR(1) is stationary $\Gamma(J)=A^j\Gamma(0)$.

So the first step is to estimate the model. Second with the matrixes found, I need to compute $\Gamma(0)=V(y_t)=E(y_t'y_t)=A\Gamma(0)A'+\Omega$. Third compute the effective sample size

This is my try, a very basic code in Matlab to estimate the VAR(1) coefficients with the posterior load in betaProbit.

    Varprobit=betaProbit; % The posterior betas of x0 x1 x2
Varprobit_1=zeros(ndraws,3);% x0 x1 x2 ,t-1
for j=2:ndraws
Varprobit_1(j,:)=Varprobit(j-1,:);
end
epsilons=randn(ndraws,3);% generate Random normal numbers ( errors)
XVAR1=ones(ndraws,1),Varprobit_1(:,1),Varprobit_1(:,2),...
Varprobit_1(:,3),epsilons(:,1)];
XVAR2=[ones(ndraws,1) ,Varprobit_1(:,1),Varprobit_1(:,2),...
Varprobit_1(:,3),epsilons(:,2)];
XVAR3=[ones(ndraws,1) ,Varprobit_1(:,1),Varprobit_1(:,2),...
Varprobit_1(:,3),epsilons(:,3)];
% Estimate VAR coefficients;
BetasEc1= inv(XVAR1'*XVAR1)*XVAR1'*Varprobit(:,1);
BetasEc2= inv(XVAR2'*XVAR2)*XVAR2'*Varprobit(:,2);
BetasEc3= inv(XVAR3'*XVAR3)*XVAR3'*Varprobit(:,2)   ;
A=[BetasEc1(2:4,1)';BetasEc2(2:4,1)';BetasEc3(2:4,1)'];
OMEGA=eye(3,3);
Gam=Varprobit'*Varprobit;
acfj= VARacfLagj( Gam ,A, OMEGA,j);
%In this step I need to construct a function to solve Gamma(0)


The key issue is to find a function to solve $\Gamma(0)=V(y_t)=E(y_t'y_t)=A\Gamma(0)A'+\Omega$.

Thanks for your help.

• Did you intend to include some kind of more complete reference or link on ? Is this Matlab code? – Glen_b Aug 7 '14 at 2:59
• @Glen_b thank you for asking. Yes it is Matlab code. The hyperlink was corrected – EAguirre Aug 7 '14 at 3:51

I am unfamiliar with Matlab, but if you know R, then I think the R package mcmcse has coded the effective sample size similarly. They are also in their vignette using the VAR example as motivation, so you will find a lot of similarities.