Here’s the same analysis of estimating population growth using Stan.

```
data {
int<lower=0> N; // number of observations
vector[N] y; // observed population
}
parameters {
real r;
}
model {
real k;
real p0;
real deltaT;
real sigma;
real mu0;
real sigma0;
vector[N] p;
k <- 1.0;
p0 <- 0.1;
deltaT <- 0.0005;
sigma <- 0.01;
mu0 <- 5;
sigma0 <- 10;
r ~ normal(mu0, sigma0);
for (n in 1:N) {
p[n] <- k * p0 * exp((n - 1) * r * deltaT) / (k + p0 * (exp((n - 1) * r * deltaT) - 1));
y[n] ~ normal(p[n], sigma);
}
}
```

Empirically, by looking at the posterior, this seems to do a better job than either extended Kalman or vanilla Metropolis.

Advertisements