# Particle filter dynare

**URL:** <https://forum.dynare.org/t/particle-filter-dynare/5829>\
**Category:** ML/Bayesian estimation\
**Created:** [19 October 2016 11:56 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829 "2016-10-19T11:56:15Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![shengan28](https://forum.dynare.org/user_avatar/forum.dynare.org/shengan28/32/7453_2.png) [@shengan28](https://forum.dynare.org/u/shengan28)\
**Post date:** [28 December 2016 03:33 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/21 "2016-12-28T03:33:52Z")

</div>

That is good insight. Thanks.

My next question has to do with programming Particle filters.  
The command `filter_algorithm=sis`  
is the sequential importance sampling. However, by adding

`resampling=systematic or generic
`  
Doe this make the particle filter the sequential importance resampling filter? It seems obvious, but the manual does not explicitly say this.

Does this option work with any of the other filters? It must not do anything to the APF

Lastly, the `mode_compute=11` runs the on-line estimation. Does this option over ride the particle filters in the `filter_algorithm= `  
command?

---

<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:** [1 January 2017 07:57 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/22 "2017-01-01T07:57:35Z")

</div>

Concerning the first question on `filter_algorithm=sis` and `resampling=systematic` the answer is yes. And it is the default.

`resampling_threshold `only works with `generic `and is useless with `systematic `or `none`. With `apf `it induces a second resampling step on current particles which is not necessary. The literature then recommands `resampling=none` for apf.

Keep in mind that maximum likelihood will not function in presence of resampling since it generates a discontinuity of the criterion with respect to the structural parameters. In that case, avoid gradient-based methods.

Concerning `mode_compute=11` it is an auxiliary particle filter and it overrides the other options that control other particle filters. It is useful to obtain fast estimation on parameters by including them as extra states but suffers from a severe lack of theoretical foundations.

---

<div class="post-metadata">

**Author:** ![shengan28](https://forum.dynare.org/user_avatar/forum.dynare.org/shengan28/32/7453_2.png) [@shengan28](https://forum.dynare.org/u/shengan28)\
**Post date:** [10 January 2017 05:40 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/23 "2017-01-10T05:40:26Z")

</div>

Thank you for the detailed reply. That makes things clear.  
Can someone check the NKLF option with the linear\_model.mod . It runs for several minutes before crashing.

---

<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:** [17 January 2017 11:23 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/24 "2017-01-17T11:23:54Z")

</div>

Could you please provide the mod-file

---

<div class="post-metadata">

**Author:** ![shengan28](https://forum.dynare.org/user_avatar/forum.dynare.org/shengan28/32/7453_2.png) [@shengan28](https://forum.dynare.org/u/shengan28)\
**Post date:** [21 January 2017 19:27 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/25 "2017-01-21T19:27:19Z")

</div>

The NLKF filter starts out strong, but then crashes at Simplex iteration number: 4964-4-3, maybe after 20 minutes.

[linear\_model\_nlkf.mod](https://forum.dynare.org/uploads/default/original/2X/0/0f864057e532c1c5c8d287fb9eada5f5185efe03.mod) (1.44 KB)

Notice that this file expects the linear\_model.mode.mat file, but This board won’t let me upload .mat files. Be sure to eliminate the `mode_file=linear_model_mode` in the estimation command.

Thanks for looking into this bug.

~Shawn

---

<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:** [23 January 2017 11:21 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/26 "2017-01-23T11:21:03Z")

</div>

You may try it again with the proposed change at [github.com/DynareTeam/particles/pull/8](https://github.com/DynareTeam/particles/pull/8)

---

<div class="post-metadata">

**Author:** ![HouseC](https://forum.dynare.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HouseC](https://forum.dynare.org/u/HouseC)\
**Post date:** [29 March 2020 12:01 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/27 "2020-03-29T12:01:44Z")

</div>

Dear Professor Pfeifer,

I learn that dynare 4.6.1 is able to do estimation for order higher than 1. While I try to implement the estimation which I have specified as log-linear model. However, the dynare reports that higher order estimation cannot deal with log-lineared model.

_error: non\_linear\_dsge\_likelihood (line 59)_  
_non\_linear\_dsge\_likelihood: It is not possible to use a non linear filter with the option loglinear!_

I understand that the higher-order estimation or particle filter is relatively new. But is it possible to find any simple example or instruction in the dynare manual on the issue—how to use the estimation command with higher-order properly?

Best,  
House

---

<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:** [30 March 2020 12:01 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/28 "2020-03-30T12:01:48Z")

</div>

Examples are at [tests/particle · master · Dynare / dynare · GitLab](https://git.dynare.org/Dynare/dynare/-/tree/master/tests%2Fparticle)

Note that the problem is not with using a log-linearized model, but rather you asking to log-linearize a model using Dynare functionality. It is usually better to work with auxiliary equations to get a log-linearization. See

> [@Question about understanding irfs in dynare](https://forum.dynare.org/t/question-about-understanding-irfs-in-dynare/10622/4):
>
> To be more precise: it depends on how the variables in your model are measured. As @stepan-a says, Dynare conducts a linearization. If you for example have a nonlinear model and your model variable is simply the level of output, the IRF will measure the difference between the variable and its steady state (or its mean at higher order). This is the case with [https://github.com/DynareTeam/dynare/blob/master/examples/example1.mod](https://github.com/DynareTeam/dynare/blob/master/examples/example1.mod) In contrast, if your model variable already measures percentage…

---

<div class="post-metadata">

**Author:** ![HouseC](https://forum.dynare.org/letter_avatar_proxy/v4/letter/h/f475e1/32.png) [@HouseC](https://forum.dynare.org/u/HouseC)\
**Post date:** [31 March 2020 01:31 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/29 "2020-03-31T01:31:34Z")

</div>

Dear Professor,

Many thanks for your reply. It helps!

Best,  
House

---

<div class="post-metadata">

**Author:** ![vahagn](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/cc9497/32.png) [@vahagn](https://forum.dynare.org/u/vahagn)\
**Post date:** [13 August 2021 13:15 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/30 "2021-08-13T13:15:26Z")

</div>

Dear Professor Pfeifer,

I try to run the .mod files from [tests/particle · master · Dynare / dynare · GitLab](https://git.dynare.org/Dynare/dynare/-/tree/master/tests%2Fparticle). However, after running the .mod files and choosing the mode - finder I get the following error message.

Reference to non-existent field ‘ghs2’.

Error in non\_linear\_dsge\_likelihood (line 179)  
ReducedForm.constant = ReducedForm.steadystate + .5\*dr.ghs2(restrict\_variables\_idx);

Error in initial\_estimation\_checks (line 153)  
[fval,info] =  
feval(objective\_function,xparam1,DynareDataset,DatasetInfo,DynareOptions,Model,EstimatedParameters,BayesInfo,BoundsInfo,DynareResults);

Error in dynare\_estimation\_1 (line 164)  
oo\_ =  
initial\_estimation\_checks(objective\_function,xparam1,dataset\_,dataset\_info,M\_,estim\_params\_,options\_,bayestopt\_,bounds,oo\_);

Error in dynare\_estimation (line 105)  
dynare\_estimation\_1(var\_list,dname);

Error in noisy\_ar1.driver (line 177)  
oo\_recursive\_=dynare\_estimation(var\_list\_);

Error in dynare (line 293)  
evalin(‘base’,[fname ‘.driver’]) ;

I am using dynare 4.6.4. How can I fix it?

Best,  
Vahagn

---

<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:** [14 August 2021 17:33 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/31 "2021-08-14T17:33:39Z")

</div>

Could you please try the unstable version?

---

<div class="post-metadata">

**Author:** ![vahagn](https://forum.dynare.org/letter_avatar_proxy/v4/letter/v/cc9497/32.png) [@vahagn](https://forum.dynare.org/u/vahagn)\
**Post date:** [16 August 2021 07:25 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/32 "2021-08-16T07:25:39Z")

</div>

Hi Professor,

Thank You for Your reply, I installed dynare 4.8 the latest unstable version. And now after running the same code I get such an error.  
Error using initial\_estimation\_checks (line 99)  
initial\_estimation\_checks:: particle filtering requires measurement error on the observables

Error in initial\_estimation\_checks (line 99)  
error(‘initial\_estimation\_checks:: %s requires measurement error on the observables’,disp\_string)

Error in dynare\_estimation\_1 (line 154)  
oo\_ =  
initial\_estimation\_checks(objective\_function,xparam1,dataset\_,dataset\_info,M\_,estim\_params\_,options\_,bayestopt\_,bounds,oo\_);

Error in dynare\_estimation (line 118)  
dynare\_estimation\_1(var\_list,dname);

Error in noisy\_ar1.driver (line 179)  
oo\_recursive\_=dynare\_estimation(var\_list\_);

Error in dynare (line 281)  
evalin(‘base’,[fname ‘.driver’]);

---

<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:** [16 August 2021 14:10 UTC](https://forum.dynare.org/t/particle-filter-dynare/5829/33 "2021-08-16T14:10:10Z")

</div>

You picked exactly one the files that is not supposed to work. Try e.g. the `first_spec.mod`.

[Previous page](https://forum.dynare.org/t/particle-filter-dynare/5829.md?page=1)
