Hi guys, I would like to know how to estimate parameters Linf, t0 and k in an hierarchical model of growth von Bertalanffy http://www.pisces-conservation.com/growthhelp/index.html?von_bertalanffy.htm, incorporating the discrete variables “J” and “S”, given:

N: total of individuals

J: fishes that have been recaptured 1,2, …6 times

L: length at recapture (L)

dt: time between tagging and recapture

S: places (1 and 2)

cat(file = “VBN.stan”, "

data {

int<lower=1> N;

int S;

vector[N] L;

int<lower=1,upper=S> J[N];

}

```
parameters {
real<lower=0> k;
real<lower=40> Linf;
real t0;
real<lower=0> sd_k;
real<lower=0> sd_linf;
real<lower=0> sd_t0;
real<lower=0> sigma;
real z_k[S];
real z_linf[S];
real z_t0[S];
vector[N] A;
```

}

transformed parameters {

vector[S] r_linf = sd_linf * z_linf;

vector[S] r_k = sd_k * z_k;

vector[S] r_t0 = sd_t0 * z_t0;

vector[N] mu = r_linf[S] * (1 - exp( - r_k[S] * (A - r_t0[S])));

}

model {

Linf ~ normal(50, 10);

k ~ normal(0.3, 0.15);

t0 ~ cauchy(0, 0.01);

sigma ~ cauchy(0, 5);

sd_linf ~ cauchy(0, 5);

z_linf ~ normal(0, 1);

sd_k ~ cauchy(0, 1);

z_k ~ cauchy(0, 1);

sd_t0 ~ cauchy(0, 0.01);

z_t0 ~ normal(0, 1);

A ~ normal(0, 0.1);

L ~ normal(mu, sigma);

}

generated quantities {

vector[N] Y_pred;

for (i in 1:N) {

Y_pred[i] = normal_rng(mu[i], sigma);

}

}

")

I have problems with dimensions declarated

I appreciate any advice, thanks!