# Why the stan code of two-way random effects wiener model is error

The two-way random effects wiener model is
y_{ij} \sim N(\mu_{i}t_{ij}, \sigma_{i}^{2}t_{ij}),\mu_{i}\sim N(\eta,\tau^2),\sigma_{i}^{2}\sim invgamma(\alpha,\beta),i=1,\dots,N,j=1,\dots,M
where matrix t and t are observation data.

I have implement this model in OpenBUGs software with code

model
{
for( i in 1 : n) {
for( j in 1 : m) {
dy[i , j] ~ dnorm(mu1[i , j], sigma21[i,j])
mu1[i , j] <- mu[i]*dt[i,j]
sigma21[i,j] <- 1/(dt[i,j]*sigma22[i])
}
mu[i] ~ dnorm(eta, tau21)
sigma2[i] ~ dgamma(alpha, beta)
sigma22[i] <-  1/sigma2[i]
}
alpha ~ dgamma(0.001,0.001)
beta ~ dgamma(0.0001,0.001)
eta ~ dnorm(0.0,1.0E-6)
tau21 <- 1/tau2
tau2 ~ dgamma(0.001,0.001)
}


However, when I rewrite according to stan syntax with code

data {
int<lower=2> N;
int<lower=2> M;
matrix[M, N] y;
matrix[M, N] t;
}
parameters {
real eta;
real<lower=0> tau;
real<lower=1> alpa;
real<lower=0> beta;
real mu[N];
real<lower=0> sigma2[N];
}
model {
for (i in 1:N)
mu ~ normal(eta,tau);
sigma2 ~ inv_gamma(alpa, beta);
for (j in 1:M)
y[i,j] ~ normal(mu*t[i,j], sigma2^.5*t[i,j]);
}


it seems not work. How can I modify the above stan code?

mu[i] ... sigma2[i]

What is the error message?

Thanks for ahartikainen, the error message,
SYNTAX ERROR, MESSAGE(S) FROM PARSER:

Oh, you need to wrap multiline for -loops in {}

for (i in 1:N) {
....
....
}


Also, on RStan there was a problem with i as a variable name, but I think that is fixed.

Also, this is unrelated, but given that your array is y[M,N] but you are indexing it y[i,j] with i in 1:N and j in 1:M, something is probably backward.