[R] Problems with the deSolve package

Alexandre Suire alexandresuire at hotmail.fr
Fri Feb 19 09:42:55 CET 2016

Hello R-users,

I'm trying to build a SIR-like model under R, 
using the "deSolve" package. I'm trying to do simulations of its dynamic
 over time, with three differential equations. I'm also looking to 
calculate the equilibrium state. 

So far, my code looks like this 

#This is my system, with three differential equations
system<-function(times, init, parameters){
with(as.list(c(init, parameters)),{

# Initials values and parameters
init<-c(i1=10, i2=10, i12=0) 
parameters<-c(alpha1=0.7, alpha2=0.5, beta1=0.5, beta2=0.3, gamma1=0.5, gamma2=0.5, delta=0.5, N=100) 
times<-seq(0,200, by=1)
simul <- as.data.frame(ode(y = init, times = times, func = system, parms = parameters, method="ode45"))
simul$time <- NULL

#Plotting the results
 simul, type = "l", xlab = "Time", ylab = "i1 i2 i12", main = 
"Simulation", lwd = 2, lty = 2, bty = "l", col=c("darkblue", 
legend("bottomright", c("i1", "i2","i12"), lty=2,lwd=2, col = c("darkblue", "darkred", "mediumseagreen"))

 first, I just tried studying with only the first two equations, and it 
seems to work completely fine, but when I wanted to add the 3rd 
equation, I sometimes get this message, even when I juggle the 
parameters, when i launch the line:
#simul <- as.data.frame(ode(y = init, times = times, func = system, parms = parameters))
Warning messages:
1: In lsode(y, times, func, parms, mf = 10, ...) :
  an excessive amount of work (> maxsteps ) was done, but integration was not successful - increase maxsteps
2: In lsode(y, times, func, parms, mf = 10, ...) :
  Returning early. Results are accurate, as far as they go

Have I overlooked something ? I tried to use methods="ode45" and methods="adams", without any sucess.
Thank you for your time
	[[alternative HTML version deleted]]

More information about the R-help mailing list