Hi,

I am new to stan, I am trying to replicate this, yet for an SEIR model with two infected compartments, one for asymptomatic and one for symptomatic. I have including my file here, the issue is when I run it I get the following error:

`Error in stanc(file = file, model_code = model_code, model_name = model_name, : c++ exception (unknown reason)`

here is my code:

seir_test.R (8.4 KB)

and here is my stan part:

```
functions {
real[] SI(real t,
real[] y,
real[] params,
real[] x_r,
int[] x_i) {
real dydt[5];
dydt[1] = - params[1] * y[1] * y[3] - params[2] * params[1] * y[1] * y[4];
dydt[2] = params[1] * y[1] * y[3] + params[2] * params[1] * y[1] * y[4] - y[2] / params[3];
dydt[3] = params[4] * y[2] / params[3] - y[3] / params[5];
dydt[4] = (1 - params[4]) * y[2] / params[3] - y[4] / params[6];
dydt[5] = y[3] / params[5] + y[4] / params[6];
return dydt;
}
}
data {
int<lower = 1> n_obs; // Number of days sampled
int<lower = 1> n_params; // Number of model parameters
int<lower = 1> n_difeq; // Number of differential equations in the system
int<lower = 1> n_sample; // Number of hosts sampled at each time point.
int<lower = 1> n_fake; // This is to generate "predicted"/"unsampled" data
int y[n_obs]; // The binomially distributed data
real t0; // Initial time point (zero)
real ts[n_obs]; // Time points that were sampled
real fake_ts[n_fake]; // Time points for "predicted"/"unsampled" data
}
transformed data {
real x_r[0];
int x_i[0];
}
parameters {
real<lower = 0> params[n_params]; // Model parameters
real<lower = 0, upper = 1> S0; // Initial fraction of hosts susceptible
}
transformed parameters{
real y_hat[n_obs, n_difeq]; // Output from the ODE solver
real y0[n_difeq]; // Initial conditions for both S and I
y0[2] = 1 / 1000;
y0[3] = 1 / 10000;
y0[4] = 1 / 100000;
y0[2] = 1 - Is0;
y0[5] = 0;
y_hat = integrate_ode_rk45(SI, y0, t0, ts, params, x_r, x_i);
}
model {
params[1] ~ uniform(0.5, 0.9); //constrained to be positive
params[2] ~ uniform(0.2, 0.55); //constrained to be positive
params[3] ~ uniform(1, 20); //constrained to be positive
params[4] ~ uniform(0.1, 0.99); //constrained to be positive
params[5] ~ uniform(1, 4); //constrained to be positive
params[6] ~ uniform(1, 2); //constrained to be positive
S0 ~ normal(0.5, 0.5); //constrained to be 0-1.
y ~ binomial(n_sample, y_hat[, 2]); //y_hat[,2] are the fractions infected from the ODE solver
}
generated quantities {
// Generate predicted data over the whole time series:
real fake_I[n_fake, n_difeq];
fake_I = integrate_ode_rk45(SI, y0, t0, fake_ts, params, x_r, x_i);
}
```