I am trying to fit a system of two ODEs model with two time-varying parameters. Trajectory of these parameters is approximated by polynomials. Using rstan.

When compiling, I get the message:

Error in stanc(file = file, model_code = model_code, model_name = model_name, :

0

Syntax error in ‘string’, line 56, column 53 to column 54, parsing error:

Ill-formed expression. Found identifier. There are many ways to complete this to a well-formed expression.

When I tried to modify the code, simplify it to only one ODE with one time-varying parameter, the problem remains the same (only the line # shifts), so that it seems that I miss something deep and/or obvious. Could you point me somehow what it can be?

I am listing my Stan code below.

By the way, the line 56 is within the transformed parameters block and looks comletely innocent:

vector <lower=0> [n_radon] mu_rn;

This increases my confusion substantially (seems that the problem propagates from some other places, but could not figure from where) …

All the Best

Marek B.

```
functions {
real k(real t, vector beta_k){
real k0 = beta_k[1];
real k1 = beta_k[2];
real k2 = beta_k [3];
real k3 = beta_k[4];
real k4 = beta_k [5];
real k5 = beta_k [6];
real k6 = beta_k[7];
real k7 = beta_k [8];
real k8 = beta_k [9];
k=1/(1+exp(-(k0+k1*t+k2*t^2+k3*t^3+k4*t^4+k5*t^5+k6*t^6+k7*t^7+k8*t^8)));
return k;
}
real G(real t, vector beta_G){
real G0 = beta_G[1];
real G1 = beta_G[2];
real G2 = beta_G [3];
real G3 = beta_G[4];
real G4 = beta_G [5];
real G5 = beta_G [6];
real G6 = beta_G[7];
real G7 = beta_G [8];
real G8 = beta_G [9];
G=exp(G0+G1*t+G2*t^2+G3*t^3+G4*t^4+G5*t^5+G6*t^6+G7*t^7+G8*t^8);
return G;
}
vector sysode(real t, real y, vector beta_k, vector beta_G, real G_tracer) {
real tracer =y[1];
real radon = y[2];
vector[2] dy_dt;
dy_dt[1] = G_tracer-k*tracer;
dy_dt[2] = G-k*radon;
return dy_dt;
}
}
data {
int < lower =0> n_tracer;
int < lower =0> n_radon;
vector [n_tracer] tracer;
vector [n_radon] rn;
vector [n_tracer] times_tracer;
}
parameters {
real<lower=0> sigma_tracer;
real<lower=0> sigma_rn;
real<lower=0> G_tracer;
vector [9] beta_k;
vector [9] beta_G;
vector [2] y0;
}
transformed parameters {
vector <lower=0> [n_tracer] l_tracer;
vector <lower=0> [n_tracer] l_rn;
vector <lower=0> [n_radon] mu_rn;
array[n_tracer] vector[2] y = ode_rk45(sysode, y0, t0=0, ts=times_tracer, beta_k, beta_G, G_tracer);
l_tracer=y[,1];
l_rn=y[,2];
for(j in 2:(n_radon-1)){
mu_rn[j]=sum(l_rn[((j-2)*12+2):((j-1)*12+1)]);
//mu_rn[j]=sum(l_rn[((j-2)*12+2):((j-1)*12+1)])/12;
}
mu_rn[1]=mu_rn[2];
mu_rn[n_radon]=sum(l_rn[((n_radon-2)*12+2):((n_radon-1)*12)]);
//mu_rn[n_radon]=sum(l_rn[((n_radon-2)*12+2):((n_radon-1)*12)])/12;
}
model {
G_tracer ~ normal(0, 10);
beta_k~normal(0,1);
beta_G~normal(0,10);
sigma_tracer ~ normal(0, 10);
sigma_rn ~ normal(0, 10);
y0[1]~lognormal(log(50),log(50));
y0[2]~lognormal(log(500),log(500));
for(i in 1:n_tracer){
tracer[i] ~ normal (l_tracer[i], sigma_tracer);
}
for(j in 1:n_radon){
rn[j] ~ normal (mu_rn[j], sigma_rn);
}
}
```

[edit: escaped Stan code and auto-indented]