I have a simple time series model.
C_{t+1} = C_t - (R / h_t)
C and h are observed, with a known error on the scaling term h.
Which I’ve modelled as
C_{t+1} = C_t + (R / h_t)
\hat{C} \sim N(C, \sigma)
\hat{h} \sim N(h, \theta)
R \sim N(0, 10)
\sigma \sim N(0, 1)
The model converges just fine…
But I’m surprised by the posterior distributions for R.
It appears to be independent of \theta, which given that h scales R this is not what I would expect.
The point being in the real world h Is poorly known, so I want my estimate for R to reflect that.
If I feed in a “wrong” value for h, but still well within \sim N(h, \theta) my estimate for R is pretty certain around the wrong R value, not the desired behaviour.
I suspect I’m not specifying my error model correctly, but I can’t see where I’ve gone wrong.
data {
int<lower=1> N;
vector[N] C_hat;
vector[N] h_hat;
real theta;
}
parameters {
real<lower=0> sigma;
real R;
vector<lower=1>[N] h;
real init;
}
transformed parameters {
real C[N];
C[1] = C_hat[1] + init;
for(i in 1:(N-1)){
C[i+1] = C[i] - (R / h[i]);
}
}
model {
sigma ~ normal(0, 1);
R ~ normal(0, 10);
init ~ normal(0, 1);
h_hat ~ normal(h, theta);
C_hat ~ normal(C, sigma);
}
R code to test below
h = 20
R = 0.2
C = rep(300, 1000)
for(i in 2:1000){
C[i] = C[i-1] - (R / h)
}
C = C + rnorm(1000, 0, 0.5)
plot(C, type="l")
theta=2
x = stan(model = "test.stan",
data = list(N = 1000, C_hat = C, h_hat = rep(20, 1000), theta = theta),
chains = 1)
x = extract(x)
hist(x$init)
C[1] - 300
hist(x$h)
sd(x$h) # theta = 2
hist(x$R)
hist((0.2 * 20) / rnorm(2000, 20, theta)) # expected minimum distribution of R.
sd(x$R)
sd((0.2 * 20) / rnorm(2000, 20, theta)) # order of magnitude larger than stan estimate