Apologies for such a dull issue. I would like to use rstan (of which I know little) to solve a logistic growth model exact to this great example but instead of two unkown parameters , I would like to treat theta2 as a quantity that influence the ODE but for which I have a different but known real number at each time step. Any help on how to actually modify the code int he link would be very much appreciated.
This is the kind of thing for which we set these boards up. To answer the question, you will need to modify the logisticgrowth
system function defining the ODE.
functions {
real[] logisticgrowth(real t,
real[] y,
real[] theta,
real[] x_r,
int[] x_i
) {
real dydt[x_i[1]];
for (i in 1:x_i[1]){
dydt[i] = theta[1] * y[i] * (1-y[i]/theta[2]);
}
return dydt;
}
}
This would be easy if theta[2]
were simply fixed as you’d just move it from theta
to x_i
. As is, you want to retrieve a different one for each t
. Is it theta[2]
a function of t
that you could define? If so, define that function and call it inside the ODE system. If not, then you have to do something similar, but it’s going to have to use something like binary search in a lookup table. What you’ll need is a sequence of (t, theta[2])
parsed passed in through x_r
and then you’ll have to do a search to find the t
for a specific call in the list.
Otherwise, it looks like your system will be the same size, so I don’t think a lot else needs to change other than the declaration of theta
.