Best way to write a growth model for particle filter

22 views
Skip to first unread message

Russell Almond

unread,
Feb 6, 2025, 12:43:10 PM2/6/25
to nimble-users
I'm building a hidden Markov model for some panel data.  I'm assuming that the latent variable evolves according to a Brownian motion process with a constant drift.

I can see two ways of writing the model code for the latent variable:
```
model1 <- nimbleCode({
   for (i in 1:N) {
      theta[i,1L] ~ dnorm(mu_0,sigma_0)
      for (it in 2:NT) {
          theta[i,it] ~dnorm(theta[i,it-1]+growthRate[i]*deltaT[i,it-1],
                                          growthSD[i]*sqrt(deltaT[i,it]))
          }
   }
# ... emission model for observations and priors for parameters
})
```
Where N is number of individuals, NT is number of observation times and `deltaT[N,NT-1]` is a matrix of difference between observation times.

According to my experience with MCMC, I am better off writing this model like:

```
model2 <- nimbleCode({
  for (i in 1L:N) {
    inc[i,1L] ~ dnorm(0,1)
    theta[i,1L] <- mu_0+sigma_0*int[i,1L]
    for (it in 2L:(NT)) {
      inc[i,it] ~dnorm(0,1)
      theta[i,it] <- theta[i,it-1L] +
        growthRate[i]*deltaT[i,it-1L] +
        inc[i,it]*growthSD[i]*sqrt(deltaT[i,it-1L])
    }
  }
## ... same as above
})
```

If I was running straight MCMC (or particle MCMC), model2 would have lower autocorrelation.

The drawback of model2 is that I need to base my particles on `inc`, where as what I care about is `theta`.

Two questions:
1) Is there some way to save the values of `theta` corresponding to my particles?
2) Am I right to think that model2 will be better behaved if I'm trying to estimate the variance parameters?




Perry de Valpine

unread,
Feb 6, 2025, 11:24:15 PM2/6/25
to Russell Almond, nimble-users
Hi Russell,

Thanks for the question. First, let me be sure to point you to our Michaud et al. paper on nimbleSMC in Journal of Statistical Software. It is linked from r-nimble.org (although I just noticed the link is broken but you can copy-paste the URL).

The first way to write the model is the most natural for nimbleSMC.

You can write it in a modified version of the second way if you want. The only requirement is that all elements of the state vector be in the same variable. But the notion of "state" here is fairly general. So I think you could pack elements of what are now inc and theta into rows of the same variable. I believe the setup for nimble's particle filters will take care that the simulation within a time step is done in topologically sorted order within that time step. (That means that an inc element will be drawn from its distribution before it is added to the theta element, etc. (but of course those names will change if you combine them into one matrix)).

Your comment about MCMC makes sense. However, if using samplers that update one (or a subset) of elements at a time, then the computational cost of your model2 is much higher than of your model1. That's because updating a single inc[i, it] element has the rest of the time series as its dependencies. That can make model1 sometimes a better choice.

HTH
Perry


--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/nimble-users/cf3824a8-2c0c-4708-bb90-4341b291f806n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages