Skip to content

Instantly share code, notes, and snippets.

@jrnold
Created October 1, 2014 15:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrnold/5e0fb240369311bb2f3b to your computer and use it in GitHub Desktop.
Save jrnold/5e0fb240369311bb2f3b to your computer and use it in GitHub Desktop.
local level model in Stan reparameterized using Matt's trick
// Local Level model in Stan
// parameterized using Matt's Trick
data {
int n;
vector[n] y;
real<lower=0> theta1_mean;
real<lower=0> theta1_sd;
}
parameters {
real<lower=0> sigma_v;
real<lower=0> sigma_w;
vector[n] theta_innov;
}
transformed parameters {
vector[n] theta;
theta[1] <- theta1_mean + theta1_sd * theta_innov[1];
for (t in 2:n) {
theta[t] <- theta[t - 1] + sigma_w * theta_innov[i];
}
}
model {
theta_innov ~ normal(0, 1);
y ~ normal(theta, sigma_v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment