Setting individual parameter priors in SIR Model

Hi there. I’m working with using a SIR Model and having trouble coding the priors for the parameters of the states in the model. I’m working off of the Stan code found here: https://jrmihalj.github.io/estimating-transmission-by-fitting-mechanistic-models-in-Stan/

The ODE solver is strongly typed, which I believe to mean that the parameters has to be an array. As you can see in the referenced code, the prior for the parameters is set across all parameters in the line in the model block:

parameters {
    real<lower = 0> params[n_params]; // Model parameters
}
model {
    params ~ normal(0,2);
}

In my the SIR model, there are two parameters, let’s call them b and h. What I’m trying to do is to declare those parameters in the parameters block, concatenate them in the transformed parameters block and then set individual priors in the model block:

parameters {
    real<lower=0> b;
    real<lower=0> h;
}
transformed parameters {
    real<lower=0> params = append_array(b,h);
}
model {
    b~normal(0,1);
    h~normal(5,10);
}

When I do this, I get an error stating that there are no matches for: “append_array(real, real)”. and then it lists out the available append_array argument signatures.

How can I make this work?

Thanks in advance.

Hi Bacross,

There are two ways I would look at doing this. The first is to keep the parameters as an array and declare separate priors for the components:

parameters {
    real<lower = 0> params[n_params]; // Model parameters
}
model {
    params[1] ~ normal(0,1);
    params[2] ~ normal(5,10);
}

Alternatively, you can construct the array of reals using the {} syntax:

parameters {
    real<lower=0> b;
    real<lower=0> h;
}
transformed parameters {
    real<lower=0> params[2] = {b, h};
}
model {
    b~normal(0,1);
    h~normal(5,10);
}
2 Likes