[R] Logistic population growth and deSolve

Gorillagorilla thomaskohlmann at gmail.com
Fri Feb 3 05:38:03 CET 2012


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.



More information about the R-help mailing list