Hi Benny, welcome to Stan!

There are a few things here. Firstly, I’d highly recommend reading the User’s Guide chapter on transitioning from BUGS: https://mc-stan.org/docs/2_25/stan-users-guide/stan-for-bugs-appendix.html

Now, onto your model:

### Vectors

When working with multiple values for a single parameter, it is more efficient to use vectors, rather than arrays of `real`

, see this section of the manual for more information on the various data types: https://mc-stan.org/docs/2_25/reference-manual/data-types-chapter.html.

So instead of:

```
real<lower=0> u[N];
```

Use:

```
vector<lower=0>[N] u;
```

### Indexing

Something to be very careful with your models is how you use indexes. Take the following statement for example:

```
delta[N]~normal(mu,beta);
```

This is not putting a prior on the whole vector of `delta`

values, only on the sixth value. This is because `N`

is passed as the single integer 6, which means that statement is equivalent to:

```
delta[6]~normal(mu,beta);
```

If you want the prior (or any function) to apply to the whole vector, then you can just specify it without any indexing:

```
delta ~ normal(mu,beta);
```

### Normal Distribution

Just a quick one. Stan parameterises the normal distribution using the mean and standard deviation, not the variance, so you don’t need to square the SD parameter (`u`

)

### Predicted Values

To generate the model-predicted values, you should use the `_rng`

function of your desired distribution in the `generated quantities`

block, rather than declaring them as a new parameter.

So rather than having in the `model`

block:

```
pred[N]~normal(mu,uu[N]);
```

You would instead have in the generated quantities:

```
pred = normal_rng(mu, u);
```

### The Fixed Model

I’ll post a corrected version of your model below, but make sure you take some time to see the changes I’ve made and why, and I’d also recommend reading the Stan documentation here: https://mc-stan.org/users/documentation/ to get more familiar with the language.

```
data {
int<lower=0> N;
vector[N] x;
vector<lower=0>[N] u;
}
parameters {
real mu;
real<lower=0> beta;
vector<lower=0>[N] delta;
}
model {
mu ~ normal(0,1E-6); //prior for mu
beta ~ gamma(1E-5,1E-5); //prior for beta
delta ~ normal(mu,beta);
x ~ normal(delta,u);
}
generated quantities{
real pred[N];
vector[N] DOE;
pred = normal_rng(mu, u);
// The vectorised rng returns a real[],
// need to convert to vector for subtraction
DOE = x - to_vector(pred);
}
```