Hey all,

I’ve been trying to fit this model for months, and can’t figure out what’s going wrong, but suspect a combination of non-identifiability and dynamical complexity.

Now, I’m trying to write a 1-step-ahead forecasting model, and keep getting syntax errors that don’t make sense to me? Anywhere, here’s the model…

```
functions{
real[] dZ_dt(
real t,
real[] Z,
real[] theta,
real[] x_r,
int[] x_i){
real P = Z[1];
real H = Z[2];
real r = theta[1];
real O = theta[2];
real h = theta[3];
real b = theta[4];
real c = theta[5];
real u = theta[6];
real dP_dt = P*r - H*(exp(O)*P/(1 + exp(O)*P*exp(h)));
real dH_dt = b + H*(c*(exp(O)*P/(1 + exp(O)*P*exp(h)))-u);
return({dP_dt,dH_dt});
}
}
data {
int<lower=0>N; // Define N as non-negative integer
real ts[N]; // Assigns time points to N
real<lower=0>y[N,2]; // Define y as real and non-negative
}
parameters {
real<lower=0>r;
real<lower=0,upper=1>O;
real<lower=0>h;
real<lower=0>b;
real<lower=0>c;
real<lower=0,upper=1>u;
real<lower=0>sigma[2];
}
transformed parameters{
for (i in 2:N){ // Start at 2nd time step because giving the first
real Z[i,2]
= integrate_ode_rk45(dZ_dt, // Function
y[i-1], // Initial value (empirical data point at previous time step)
ts[i-1], // Initial time step
ts[i], // Next time step (time step to be solved/estimated)
{r, exp(O), exp(h), b, c, u},
rep_array(0.0,2),rep_array(0,2),1e-10,1e-10,2e4);
}
}
model {
r~normal(2.5,1);
O~normal(log(0.01),2);
h~normal(log(0.07),2);
b~normal(35,1);
c~normal(0.3,1);
u~normal(0.4,1);
sigma~lognormal(-1, 1);
for (k in 1:2) {
y[ , k] ~ lognormal(log(Z[ , k]), sigma[k]);
}
}
generated quantities {
real y_rep[N, 2];
for (k in 1:2) {
for (n in 1:N)
y_rep[n, k] = lognormal_rng(log(Z[n, k]), sigma[k]);
}
}
```

O and h are logged because their true values are close to 0, and when multiplied (as they are in the mechanistic model) are VERY close to zero.

And here’s the syntax error I can’t seem to shake:

```
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Fourth argument to integrate_ode_rk45 must have type real[ ]; found type = real.
error in 'model2486523de9f_OSA_Lognormal' at line 51, column 49
-------------------------------------------------
49: ts[i], // Next time step (time step to be solved/estimated)
50: {r, exp(O), exp(h), b, c, u},
51: rep_array(0.0,2),rep_array(0,2),1e-10,1e-10,2e4);
^
52: }
-------------------------------------------------
PARSER EXPECTED: ")"
Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model 'OSA_Lognormal' due to the above error.
```

Despite a ton of incredible support from this community, I’ve been stuck on this model for way too long, so any help would be appreciated!

I’m also happy to update this topic with what I was trying before if that would be helpful :)