# Bayesian Estimation Help

**URL:** <https://forum.dynare.org/t/bayesian-estimation-help/4540>\
**Category:** Dynare help (legacy posts)\
**Created:** [5 March 2015 17:16 UTC](https://forum.dynare.org/t/bayesian-estimation-help/4540 "2015-03-05T17:16:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![qazi.haque](https://forum.dynare.org/letter_avatar_proxy/v4/letter/q/c67d28/32.png) [@qazi.haque](https://forum.dynare.org/u/qazi.haque)\
**Post date:** [5 March 2015 17:16 UTC](https://forum.dynare.org/t/bayesian-estimation-help/4540/1 "2015-03-05T17:16:33Z")

</div>

Dear Johannes,

I am trying to learn how to do Bayesian estimation and to replicatie a prototypical NK model as found in Lubic and Schorfeide (2004) for the determinate version of their model. I have been able to successfully replicate the estimation for the determinate model in DYNARE. Now I am trying to do the same thing by writing up the codes in MATLAB and do the estimation manually myself in MATLAB without using DYNARE.

I have got stuck at some point while doing the posterior kernel optimization for finding the mode.

Will you be willing to have a look at my codes and perhaps suggest me what I am doing wrong? If you agree to have a look at my MATLAB codes at your convenience, I will post them.

Looking forward to your reply.

Thanks.

Regards,  
Qazi.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [8 March 2015 08:05 UTC](https://forum.dynare.org/t/bayesian-estimation-help/4540/2 "2015-03-08T08:05:35Z")

</div>

I cannot guarantee that I will find the time to look at this. Could you please provide more details on the problem you encounter?

---

<div class="post-metadata">

**Author:** ![qazi.haque](https://forum.dynare.org/letter_avatar_proxy/v4/letter/q/c67d28/32.png) [@qazi.haque](https://forum.dynare.org/u/qazi.haque)\
**Post date:** [12 March 2015 10:56 UTC](https://forum.dynare.org/t/bayesian-estimation-help/4540/3 "2015-03-12T10:56:04Z")

</div>

Hi Johannes,

When I try to do the log posterior kernel minimization by running the file ‘candidate.m’ by using csminwel, I get stuck since the log(prior) turn out to be (-ve) infinity and so the log(posterior kernel) becomes (-ve) infinity and the posterior mode ends up being weird and the hessian not being positive definite at the mode. My best guess is that the trouble is arising from incorrect re-parametrization, however, I couldn’t still fix it after trying different forms of re-parametrization. I have attached a zip file named ‘Bayesian LS’ containing the matlab codes used. Much of these codes are borrowed from Schorfeide’s webpage.

The starting values I use for the csminwel are the modes obtained from running the estimation in DYNARE. The mode values from DYNARE using mode\_compute = 4, ie, csminwel, for the Lubic and Schorfeide (2004) parameters are as follows:

psi1 = 2.1700  
psi2 = 0.2208  
rhoR = 0.8467  
piestar = 3.4212  
rstar = 3.0202  
kappa = 0.5262  
Tau = 1.7690  
rhoG = 0.8283  
rhoZ = 0.8593  
rhoGZ = 0.3355  
sigmaR = 0.1667  
sigmaG = 0.1711  
sigmaZ = 0.6030.

Please download the zip file and run the m file ‘candidate.m’ at your leisure. Then you will perhaps realize the problem I am encountering. I believe there is some subtle issue in the coding that’s creating the problem which I am not being able to figure out. ☹

Any help in fixing the problem would be much highly appreciated. 🙂

Thanks a bunch.

Sincerely,  
Qazi.

P.S. Sorry for the lengthy post. I had to describe what’s going on for the purpose of clarification of my issues.  
[Bayesian LS.zip](https://forum.dynare.org/uploads/default/original/2X/6/6d17bff125d29058ff0337703264d1f59ea99b63.zip) (36.9 KB)

---

<div class="post-metadata">

**Author:** ![qazi.haque](https://forum.dynare.org/letter_avatar_proxy/v4/letter/q/c67d28/32.png) [@qazi.haque](https://forum.dynare.org/u/qazi.haque)\
**Post date:** [17 March 2015 08:52 UTC](https://forum.dynare.org/t/bayesian-estimation-help/4540/4 "2015-03-17T08:52:52Z")

</div>

Hi Johannes,

I was wondering whether you have any clue of what I am doing wrong as stated in my previous post.

Thanks.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [18 March 2015 20:54 UTC](https://forum.dynare.org/t/bayesian-estimation-help/4540/5 "2015-03-18T20:54:57Z")

</div>

I will try to have a look at it. But this will require more time than I have in the next days. Have you checked whether your code and Dynare provide the same likelihood for the same data and parameter values for determinacy?

---

<div class="post-metadata">

**Author:** ![qazi.haque](https://forum.dynare.org/letter_avatar_proxy/v4/letter/q/c67d28/32.png) [@qazi.haque](https://forum.dynare.org/u/qazi.haque)\
**Post date:** [20 March 2015 00:30 UTC](https://forum.dynare.org/t/bayesian-estimation-help/4540/6 "2015-03-20T00:30:03Z")

</div>

Well, this is still actually the problem I am encountering while trying to estimate the determinate model, so these codes are trying to estimate the determinate version of Lubic and Schorfeide (2004). Since I got stuck into this, I haven’t been able to proceed and write up the LRE solution for indeterminacy.

Thanks for your consideration. Looking forward to your response at your favorable time.

Cheers.

---

<div class="post-metadata">

**Author:** ![qazi.haque](https://forum.dynare.org/letter_avatar_proxy/v4/letter/q/c67d28/32.png) [@qazi.haque](https://forum.dynare.org/u/qazi.haque)\
**Post date:** [20 April 2015 04:10 UTC](https://forum.dynare.org/t/bayesian-estimation-help/4540/7 "2015-04-20T04:10:25Z")

</div>

Dear Johannes,

Just to let you know, I have figured out where I was doing wrong and I can now successfully do Bayesian estimation on my own in MATLAB.

Thanks for you consideration.

Cheers,  
Qazi .
