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.

enter image description here

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 
    epsilons=randn(ndraws,3);% generate Random normal numbers ( errors)
    XVAR2=[ones(ndraws,1) ,Varprobit_1(:,1),Varprobit_1(:,2),...
    XVAR3=[ones(ndraws,1) ,Varprobit_1(:,1),Varprobit_1(:,2),...
    % Estimate VAR coefficients;
    BetasEc1= inv(XVAR1'*XVAR1)*XVAR1'*Varprobit(:,1);
    BetasEc2= inv(XVAR2'*XVAR2)*XVAR2'*Varprobit(:,2);
    BetasEc3= inv(XVAR3'*XVAR3)*XVAR3'*Varprobit(:,2)   ; 
    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.

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

You are probably no longer looking for an answer. But here it is, anyway.

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.

It looks like most of their code is also in C++, so if you know that as well, you might be able to translate the logic.

Basically, they are using batch means estimators to estimate the infinite sum variance. This is a strongly consistent estimator, and is much better than using the naive estimator. You can find more information here, including some of the math for the VAR model.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.