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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Drew Tyre
Hi all,

I'm teaching a population dynamics course for upper level undergraduates. I am using R for the first time (first time using it in this class, not my first time!). So I needed to make a small function to simulate a logistic population model, and it occurred to me that other's may have already solved this problem in a better way. I'm looking for pointers to other implementations, and/or feedback on how I've set it up. A bit of description of my goals and the function are at

http://atyre2.github.io/2017/02/22/whats-the-best-logistic-model.html

I have looked at Karline Soetaert and Peter Herman's book A practical guide to ecological modelling, as well as Henry Steven's book A primer of Ecology with R, and discuss their approaches at the above blog post.

Thank you for your time and attention!
-- 
Drew Tyre

School of Natural Resources
University of Nebraska-Lincoln
416 Hardin Hall, East Campus
3310 Holdrege Street
Lincoln, NE 68583-0974

phone: +1 402 472 4054 
fax: +1 402 472 2946
email: [hidden email]
http://snr.unl.edu/tyre
http://atyre2.github.io
ORCID: orcid.org/0000-0001-9736-641X

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Reply | Threaded
Open this post in threaded view
|

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

Jeremy Chacon
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 <[hidden email]> wrote:

> Hi all,
>
> I'm teaching a population dynamics course for upper level undergraduates.
> I am using R for the first time (first time using it in this class, not my
> first time!). So I needed to make a small function to simulate a logistic
> population model, and it occurred to me that other's may have already
> solved this problem in a better way. I'm looking for pointers to other
> implementations, and/or feedback on how I've set it up. A bit of
> description of my goals and the function are at
>
> http://atyre2.github.io/2017/02/22/whats-the-best-logistic-model.html
>
> I have looked at Karline Soetaert and Peter Herman's book A practical
> guide to ecological modelling, as well as Henry Steven's book A primer of
> Ecology with R, and discuss their approaches at the above blog post.
>
> Thank you for your time and attention!
> --
> Drew Tyre
>
> School of Natural Resources
> University of Nebraska-Lincoln
> 416 Hardin Hall, East Campus
> 3310 Holdrege Street
> Lincoln, NE 68583-0974
>
> phone: +1 402 472 4054
> fax: +1 402 472 2946
> email: [hidden email]
> http://snr.unl.edu/tyre
> http://atyre2.github.io
> ORCID: orcid.org/0000-0001-9736-641X
>
> _______________________________________________
> R-sig-ecology mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>



--

*___________________________________________________________________________Jeremy
M. Chacon, Ph.D.*

*Post-Doctoral Associate, Harcombe Lab*
*University of Minnesota*
*Ecology, Evolution and Behavior*

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Reply | Threaded
Open this post in threaded view
|

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

Thomas Petzoldt
Hi,

here a few slides about growth modelling from a recent course, that are
still online:

http://www.simecol.de/modecol/

and especially:

http://www.simecol.de/modecol/slides-odemodels.html

Besides this, the two books of Karline Soetaert and the book of Hank
Stevens are definitely an excellent choice for this topic.

Thomas

See also:
https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models


Am 23.02.2017 um 21:56 schrieb Jeremy Chacon:

> 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 <[hidden email]> wrote:
>
>> Hi all,
>>
>> I'm teaching a population dynamics course for upper level undergraduates.
>> I am using R for the first time (first time using it in this class, not my
>> first time!). So I needed to make a small function to simulate a logistic
>> population model, and it occurred to me that other's may have already
>> solved this problem in a better way. I'm looking for pointers to other
>> implementations, and/or feedback on how I've set it up. A bit of
>> description of my goals and the function are at
>>
>> http://atyre2.github.io/2017/02/22/whats-the-best-logistic-model.html
>>
>> I have looked at Karline Soetaert and Peter Herman's book A practical
>> guide to ecological modelling, as well as Henry Steven's book A primer of
>> Ecology with R, and discuss their approaches at the above blog post.
>>
>> Thank you for your time and attention!
>> --
>> Drew Tyre
>>
>> School of Natural Resources
>> University of Nebraska-Lincoln
>> 416 Hardin Hall, East Campus
>> 3310 Holdrege Street
>> Lincoln, NE 68583-0974
>>
>> phone: +1 402 472 4054
>> fax: +1 402 472 2946
>> email: [hidden email]
>> http://snr.unl.edu/tyre
>> http://atyre2.github.io
>> ORCID: orcid.org/0000-0001-9736-641X
>>
>> _______________________________________________
>> R-sig-ecology mailing list
>> [hidden email]
>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>>
>
>
>


--
Dr. Thomas Petzoldt
Technische Universitaet Dresden
Faculty of Environmental Sciences
Institute of Hydrobiology
01062 Dresden, Germany

E-Mail: [hidden email]
http://tu-dresden.de/Members/thomas.petzoldt

-- limnology and ecological modelling --

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology