Skip to content
Prev 5558 / 7420 Next

what's the best R implementation of a Logistic population model?

Hi Drew,

Since there is a closed-form solution to the logistic model, it's easy, you
can just code the solution into a function:

logistic <- function(times, r, K, Y0){
  numer = K * Y0 * exp(r * times)
  denom = K + Y0 * (exp(r * times) - 1)
  return(numer / denom)
}

times = seq(from = 0, to = 100, by = 1)
r = 0.4
K = 1000
Y0 = 1

plot(times, logistic(times, r, K, Y0), type = "l")

If, however, you want them to do numerical simulation, then the deSolve
package (which you've been reading about) is the way to go:

install.packages('deSolve')
library(deSolve)

logistic_de <- function(times, y, parms){
  dN = y * parms[1] * (1 - y / parms[2])
  return(list(dN))
}

y0 = 1
parms = c(0.4, 1000)
times = seq(from = 0, to = 100, by = 1)

out = ode(y = y0, times = times, func = logistic_de, parms = parms)
plot(out)

Note that there are better (i.e. easier to read) ways to code the function
for the logistic for deSolve numerical solving, but this is the easiest.


Jeremy
On Thu, Feb 23, 2017 at 1:35 PM, Drew Tyre <atyre2 at unl.edu> wrote:

            

  
    
Message-ID: <CAH65v73z7ivtpPgST9FTMrK-c=dQGt6+GVb=3b9Ju_GZqifwFQ@mail.gmail.com>
In-Reply-To: <BN3PR08MB1907C2D411F1D0DC85C6860F9E530@BN3PR08MB1907.namprd08.prod.outlook.com>