Hello, I am new to R and I am having problems trying to model logistic
population growth with the deSolve package. I would like to run the model
for four populations with the same initial population and carrying capacity
but with different growth rates and put the results into a data frame. When
I run the following lines of code I get unexpected results from "output" but
the format is more or less what I am looking for. When I run the function, I
get the results I expected but for only one time step. I haven't been able
to discern what the problem is and haven't gotten any error messages to clue
me in on where I am making a mistake. Advice would be grealty appreciated.
Thanks.
library(deSolve)
parameters = c(K=305,
ra=0.8,
rb=1.5,
rc=2.1,
rd=2.6)
state = c(Na=5,
Nb=5,
Nc=5,
Nd=5)
logGrowth = function(time, state, parameters)
{
with(as.list(c(state,parameters)),
{
dNa.dt = ra * Na * (1-(Na/K))
dNb.dt = rb * Nb * (1-(Nb/K))
dNc.dt = rc * Nc * (1-(Nc/K))
dNd.dt = rd * Nd * (1-(Nd/K))
return(list(c(dNa.dt, dNb.dt, dNc.dt, dNd.dt)))
})
}
times = 1:20
output = ode(y = state,
times = times,
func = logGrowth,
parms = parameters)
print(output)
logGrowth(times,state,parameters)
--
View this message in context: http://r.789695.n4.nabble.com/Logistic-population-growth-and-deSolve-tp4353655p4353655.html
Sent from the R help mailing list archive at Nabble.com.
Logistic population growth and deSolve
2 messages · Gorillagorilla, Thomas Petzoldt
19 days later
Hi Thomas, I've been out of office for a time, but maybe you are still waiting ... As far as I see your model is a correctly implemented ODE (!!!) system and I don't understand what you mean with "unexpected results". Would it be possible that your original intention was not a *continuous* ODE but a discrete system instead? In this case, just use the "euler" method: ## continuous system (ordinary differential equation, ODE) output = ode(y = state, times = times, func = logGrowth, parms = parameters) plot(output) ## discrete system (difference equation) output = ode(y = state, times = times, func = logGrowth, parms = parameters, method="euler") plot(output) Note also that you can write your problem more elegantly using vector and matrix notation. Thomas Petzoldt