# Estimation using particle filter

**URL:** https://forum.dynare.org/t/estimation-using-particle-filter/27138
**Category:** ML/Bayesian estimation
**Created:** [5 February 2025 08:02 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138 "2025-02-05T08:02:49Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![cheieun](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@cheieun](https://forum.dynare.org/u/cheieun)
#### Post date: [5 February 2025 08:02 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/1 "2025-02-05T08:02:49Z")

</div>

Dear all,

I am currently working on parameter estimation using particle filtering for my state-space model applying the following codes.

> **[GitHub - JohannesPfeifer/Particle\_Filtering: Matlab Particle Filtering and Smoothing Example...](https://github.com/JohannesPfeifer/Particle_Filtering)**
>
> Matlab Particle Filtering and Smoothing Example Code

I especially followed run\_filter\_and\_smoother\_AR1\_TaRB.m  
But I have encountered some unexpected results. My estimates for rho and rho sigma converge close to 1, with small volatility over iterations.

 ![rho plot](https://forum.dynare.org/uploads/default/original/3X/c/e/ce7a97f3a7fc061863b153e41c1a2f45627f4a05.png)

What would be the potential reasons for this results and how can I fix this?

I suspect this could be due to the choice of prior distributions or the number of observables.  
I used Uniform (-0.9999, 0.9999) for rho, and Beta (0.9, 0.1^2) for rho sigma (same setting as evaluate\_prior\_AR1).  
And the number of observables are only 49.

I would appreciate any advice on how to address this issue.

Thank you very much!

---

<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: [5 February 2025 09:24 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/2 "2025-02-05T09:24:59Z")

</div>

Unit roots like that usually happen if the data mean does not conform to the mean in the model, i.e. you did not make sure data and code are consistent.

---

<div class="post-metadata">

### Author: ![cheieun](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@cheieun](https://forum.dynare.org/u/cheieun)
#### Post date: [5 February 2025 10:13 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/3 "2025-02-05T10:13:25Z")

</div>

Does this mean that my data should be detrended or transformed before estimation to ensure consistency with the model? If so, would demeaning or normalizing the data be effective, or is there a more appropriate transformation?

How can I check whether my data and model are consistent?

Thank you!

---

<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: [5 February 2025 10:25 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/4 "2025-02-05T10:25:21Z")

</div>

How did you treat your data? The current code assumes data in deviations from the trend/mean, i.e. the data is mean 0.

---

<div class="post-metadata">

### Author: ![cheieun](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@cheieun](https://forum.dynare.org/u/cheieun)
#### Post date: [5 February 2025 11:46 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/5 "2025-02-05T11:46:21Z")

</div>

I changed the code slightly so that the AR(1) process for the observables is now specified as:  
`x_t=(1-\rho)\bar{x}+\rho x_{t-1} + e^{\sigma_t}v_t`  
where x\_bar is the mean of my data.  
Would this transformation be valid? Does it correctly account for the mean structure of the data, or would additional adjustments be necessary?

---

<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: [5 February 2025 12:23 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/6 "2025-02-05T12:23:14Z")

</div>

Usually, it does. Did you make sure your data it not trending?

---

<div class="post-metadata">

### Author: ![cheieun](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@cheieun](https://forum.dynare.org/u/cheieun)
#### Post date: [5 February 2025 22:29 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/7 "2025-02-05T22:29:17Z")

</div>

yes I detrended my series using hp-filter.

---

<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: [6 February 2025 07:32 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/8 "2025-02-06T07:32:08Z")

</div>

But then it must already be mean 0.

---

<div class="post-metadata">

### Author: ![cheieun](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@cheieun](https://forum.dynare.org/u/cheieun)
#### Post date: [7 February 2025 00:56 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/9 "2025-02-07T00:56:30Z")

</div>

Oh, I missed that point. Thank you.  
But even if I modify the model to have zero mean, I still get the same result.

---

<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: [7 February 2025 08:53 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/10 "2025-02-07T08:53:12Z")

</div>

How does a plot of your data look like?

---

<div class="post-metadata">

### Author: ![cheieun](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@cheieun](https://forum.dynare.org/u/cheieun)
#### Post date: [16 February 2025 06:34 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/11 "2025-02-16T06:34:56Z")

</div>

Like below. The first plot is my original data and the second is detrended one.

 ![plot1](https://forum.dynare.org/uploads/default/original/3X/4/1/41d4e4259df39013c3213ad174fc26ed3ede0ec1.png)  
 ![plot2](https://forum.dynare.org/uploads/default/original/3X/0/7/070febb526672e954c77cff907d67e98340ce8b4.png)

---

<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 February 2025 08:10 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/12 "2025-02-16T08:10:07Z")

</div>

What type of data is that? It looks a bit like a log transformation before filtering could help.

---

<div class="post-metadata">

### Author: ![cheieun](https://forum.dynare.org/letter_avatar_proxy/v4/letter/c/df788c/32.png) [@cheieun](https://forum.dynare.org/u/cheieun)
#### Post date: [19 February 2025 06:17 UTC](https://forum.dynare.org/t/estimation-using-particle-filter/27138/13 "2025-02-19T06:17:34Z")

</div>

It seems like taking logs solved my problem!  
Thank you so much.
