Unknown "time" parameter of ODE system

Hi everyone,
I am working on an infectious disease model, describing the introduction of a new infection strain into a population. This new strain has a reduced fitness but it remained undetected until its discovery, so that cases infected with this strain were not treated and could spread the strain further (thereby increasing the proportion of the new strain). We have data about the proportion of that particular strain compared to the “old” infection strain at specific time points after its discovery. I assume that the overall prevalence of infection at the moment that the new strain was introduced is known and in steady state, but the time from introduction to discovery of the new strain (parameter “par_t2discovery”) is unknown. To find its value, I simulate the dynamics of the new and old strains from the introduction of the new strain to 10 years after its discovery using a system of ODE’s. This means: the time that I run the ODE’s is a parameter of the model itself.
My model gives compilation errors in this case. It seems that the parameter “par_t2discovery”, which modifies the “time” parameter of the integrate_ode_bdf function every iteration, cannot be set as a parameter.
Any suggestions for how to solve this problem would be greatly appreciated!
Thank you!
Joostnewstrain_stan.R (5.2 KB)

The time argument of the integrate ode functions can never be a parameter which is what you are doing. How about you formulate things differently using a step-like function. So you could integrate from the time-origin to the time point where you need to evaluate the ode and you switch this strain on using the logistic function with a steep slope and the time-point when the new strain occurs is fitted using the intercept in the logit space.

Sebastian

Hi Sebastian,

Thanks for your suggestion. You suggested to use a logistic function as a time step function. Could I not just use a discrete time step function (if statement with time as argument)? Or does this give problems with the ODE solver?

best
Joost

Using if statements is easy, yes, but can pose problems. You are running a gradient based algorithm, so its not the best thing to do an if statement. The ode integrator can handle if statements, but that needs some care. The logistic step which I suggested will give you a good continuous approximation to the step which you are looking for.

That is clear. However, in my program error messages are produced when using the continuous time step function (line 38 and 46), but not when using the if statement (lines 39-43 and 47-51, now unmarked). Then it works all right. I don’t understand why.

Thanks for taking time to help!

Joosterrormessage_newstrain2_stan.txt (2.8 KB)
newstrain2_stan.R (4.7 KB)

Your program does not start due to rejections with the initial or because there is a programming error. Try to run the program with rstan 2.14 which should give you more information on the error which is happening. This non-reporting of errors is a bug 2.15 to be fixed in 2.16.