Where are drawn parameters saved?

Hello,

I implemented 2 chains, each one having 20,000 replications.
The acceptance rates were around 25%.

  1. Where can I get the entire saved parameters drawn from kernels?
    I can only find part of them.

  2. After the estimation, how many are parameter values saved?
    Is it 5,000 or 5,000 * # of observed period?
    So, I guess if KF algorithm is used, the number should be the latter.

Many thanks in advance for help.

hi
as far as i understand, the acceptance rate only decides the ratio at which the MH algorithm accepts , as it moves around the parameter space and evaluates the posterior at each point. so if you find a 25 % rate, it does NOT mean that only 5000 draws are stored. it only means that dynare accepts the draws 25 % of the time , each time it finds new draws , as it moves around.
ALL draws that are accepted are stored in mat files file_name_blck#.mat in the current directory.
if you give the mh_drop option, dynare will discard that many percent of draws before it computes the moments

correct me if i am wrong.

cheers
reuben

Reuben is right.

If you set mh_replic = 20000 (this is the default value) the number of simulations in each Markov chain and mh_nblocks = 2 (this is the default value) the number of Markov Chains, then independently of the acceptation rate and the value of the mh_drop options, mh_replic*mh_nblocks (40000) will be saved on the disk.

You can load the files where the simulations are saved from matlab prompt

load ./<ModFileName>/metropolis/<ModFileName>_blck*_mh**

where * is the Markov chain (1 or 2 in our case) and ** is the file number. Depending on the size of the estimated model (the number of estimated parameters) dynare will save each Markov chain in a more or less important number of files (we want to keep these files not too big for memory efficiency reasons).

In each of these files you will find a matrix called xx (of dimension np) and one vector called logpo2 (of dimension n1) where n is the number of simulations saved in this file and p is the number of estimated parameters. Each line of xx is a draw from the posterior distribution (if you do not consider the first files – ie small values of ** – and if the number of simulations is large enough). The corresponding line of logpo2 is the associated value of the (logged) posterior density.

Now if you want to sample from the posterior distribution (without using all the draws of the metropolis) you just have to : (1) randomly select a chain (that is the value of *), (2) randomly select a file number (that is the value of **), (3) open the file designated by * and ** and (4) randomly choose a line in xx.

All these steps are done in a function that you should find in the matlab subfolder of dynare (v4) : selec_posterior_draws.m. You just have to read the code to understand how to call it (from the mod file, after the estimation command).

Best,
Stéphane.

1 Like

Thank both of you very much for help.
I found it.
Therefore, to my understanding, to get the target distribution is not related with Kalman filter. Is this right?

Best regards,

Jiho

hi jiho
the kalman filter only helps to evaluate the likelihood or posterior at each draw. it is a ‘filter’ because we have to take out the effect of the variables in the model that are statistically unobservable.

This will in turn decide the acceptance ratio and guide the MCMC.

the symmetric and reversible jumping distribution , which is a Normal in dynare, will ensure that with a large number of iterations, the simulated distribution will converge towards the target distribution, the ‘true’ posterior. So we are not really picking from the posterior itself.

cheers
reuben

Dear Jiho,

The target distribution (the posterior distribution of the parameters) depends on the Kalman filter because to compare different proposals in the mh algorithm we compare different likelihood weighted by the prior density. To evaluate the likelihood we generally need to use a kalman filter. Obviously the results depend on the size of the sample (for instance, we know that the bigger is the sample size the closer is the posterior distribution from a gaussian distribution).

Best Stépane.

[quote=“jiholee”]Thank both of you very much for help.
I found it.
Therefore, to my understanding, to get the target distribution is not related with Kalman filter. Is this right?

Best regards,

Jiho[/quote]

[quote=“reubenpjacob”]hi jiho
the kalman filter only helps to evaluate the likelihood or posterior at each draw. it is a ‘filter’ because we have to take out the effect of the variables in the model that are statistically unobservable.

This will in turn decide the acceptance ratio and guide the MCMC.

the symmetric and reversible jumping distribution , which is a Normal in dynare, will ensure that with a large number of iterations, the simulated distribution will converge towards the target distribution, the ‘true’ posterior. So we are not really picking from the posterior itself.

cheers
reuben[/quote]

Dear Reuben and Stépane,

As far as I understand,
KF is doing the following mechanism

E[state(i)|data(i-1)] -> Observe data(i)
-> Obtain new parameters which maximize likelihood given data(i)
-> With transition matrix which are expressed with new parameters, we update our previous prediction to E[state(i)|data(i)]
-> We predict E[state(i+1)|data(i)] using Kalman gain matrix

So we get n values for a parameter where n is the number of observation.

In MCMC,
From prior dist, draw parameter
-> Sample a proposal parameter from jumping distribution
-> If ratio of the density between one based on > 1, accept a proposal parameter

 -> At the end of the day, for example, we get 20000 draw for a parameters.

Then, in MCMC, should I think that we observed data at the beginning?
I mean that there is no prediction and updating mechanism in MCMC.
Whenever we draw, we just compare densities which are based on likelihood.
If ratio is less than 1, compare this with a draw from a unif(0,1).

So I can see the comparison between maximized likelihoods.
However, I cannot see any updating due to the newly observed data.
To my knowledge, KF is a sequential prediction and updating unobservable state vectors whenever we observe new data.

Best regards,

Jiho

You should read a book on Kalman filtering (the textbook by Harvey for instance). You are mixing variables and parameters. The Kalman filter does not provide “new parameters”. It is just a way to evaluate the density of the parameters given the sample (that is the likelihood).

Regards,
Stéphane.

[quote=“StephaneAdjemian”]You should read a book on Kalman filtering (the textbook by Harvey for instance). You are mixing variables and parameters. The Kalman filter does not provide “new parameters”. It is just a way to evaluate the density of the parameters given the sample (that is the likelihood).

Regards,
Stéphane.[/quote]

Dear Stéphane,

  1. Maybe I am wrong.
    I thought we can obtain parameters during the process of KF
    since anyway we need transition matrix which will be used to update our state vector.
    I will check the book you mention.

  2. My question was
    In MCMC, should I think that we observed all data at the beginning?

My thought is based on the following.
If we observe n data sequentially not at once at the beginning,
at time 1, we will calculate likelihood with only one observation.
Based on this, we will check ratio of densities.
At time 2, we will calculate likelihood with two observations.
And so on


I appreciate your helpful comments.

Jiho

The Kalman filter builds the prediction errors of the observed variables (ie the expectation of y_t given the sample up to time t-1 for t=1,
,T) for a given vector of parameters. The predictions errors are used to evaluate the likelihood (the posterior density is proportional to the product of the likelihood and the prior density).

No. The estimation is not recursive even if the likelihood is evaluated recursively.

Best,
Stéphane.

[quote=“jiholee”]
My thought is based on the following.
If we observe n data sequentially not at once at the beginning,
at time 1, we will calculate likelihood with only one observation.
Based on this, we will check ratio of densities.
At time 2, we will calculate likelihood with two observations.
And so on


I appreciate your helpful comments.

Jiho[/quote]