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?