********* Ecology ********* [status: some-substance-but-incomplete] Motivation, Prerequisites, Plan =============================== As I write this, in April of 2020 at the start of a lockdown caused by the COVID19 virus, it seems like a good opportunity to get comfortable with some of the equations that come up when we talk about growth. We will look at the growth of a population, or growth of the number of infected humans (which is related to the growth of the population that carries the infection). Ecology is a vast topic. Here we will look at :term:`population ecology`, the study of how populations of a species or group change over time. Let us start with `this crash course video `_ which discusses population ecology in general and uses the Texas nile virus "mystery" as an example. You should also go through this `very readable article on population growth from Nature `_. Our plan for this chapter is to look at a single species with infinite food and no constraints (exponential growth), then at constrained growth and the logistic equation, and then we will move to the multi-species ecologies and examine predator-prey dynamics. .. note:: We will make much use of differential equations, since they come up in discussion population dynamics. The examples in this chapter should be self-contained, but you will want to read the :ref:`differential-equations/differential-equations:Differential Equations` chapter for an overall introduction to the subject. And the topics here can also be studied with :term:`agent based models` which you can study in the chapter :ref:`agent-based-modeling-basics/agent-based-modeling-basics:Basic Agent-Based Modeling`. Factors that come up in modeling population ecology =================================================== .. _table-factors-population-ecology: .. table:: Factors in population ecology +---------------+-----------+---------------+ |name | variable | | +---------------+-----------+---------------+ |initial pop: | P | | +---------------+-----------+---------------+ |birth rate: | B | | +---------------+-----------+---------------+ |death rate: | D | | +---------------+-----------+---------------+ |growth rate: | r | = (B - D) / P | +---------------+-----------+---------------+ |predation | | | +---------------+-----------+---------------+ |immigration | | | +---------------+-----------+---------------+ |emigration | | | +---------------+-----------+---------------+ |mates | | | +---------------+-----------+---------------+ |food | | | +---------------+-----------+---------------+ |space | | | +---------------+-----------+---------------+ Exponential growth ================== Unlimited --------- Spend some time plotting exponentials in gnuplot. Show how they dwarf linear growth, and how you need log scale to compare them. The shift to looking at the differential equation for population growth. Note that this is also The equation that represents population growth is: .. math:: \frac{dP(t)}{dt} = r P(t) This is studied in detail in :numref:`sec-diffeq-population-growth`, with solutions looking like .. math:: P(t) = P_0 e^{r x} But if you could not solve it easily then you would write it out like this: .. math:: \frac{P_{n+1} - P_n}{\Delta t} = r P_n \\ \rightarrow \\ P_{n+1} = P_n + r P_n \times \Delta t This can be demonstrated with a simple program that calculates: .. code-block:: python P0 = 10 rate = 1.2 delta_t = 1 P = P0 print('## generation population') for generation in range(100): P = P + P * (rate-1) * delta_t print(generation, ' ', P) Resource-constrained - r-selection versus K-selection ----------------------------------------------------- r-selection A strategy in which you reproduce as quickly as you can. K-selection A strategy in which you reproduce less and put more effort into your children. Simulating with the logistic equation ..................................... The balance between these two is given by having large or small :math:`r` or :math:`k` in the *logistic equation:* .. math:: \frac{dP}{dt} = r P (1 - \frac{P}{K}) This can be solved with: .. math:: P(t) = \frac{K}{1 + A e^{-r t}} where .. math:: A = \frac{K - P_0}{P_0} This can be visualized with a simple program: .. literalinclude:: logistic_solution.py :caption: logistic_solution.py :language: python .. code-block:: console $ python3 logistic_solution.py > rk.out $ gnuplot plot [] [0:500] 'rk.out' using 1:2 title 'r = 0.1' replot 'rk.out' using 1:3 replot 'rk.out' using 1:4 replot 'rk.out' using 1:5 replot 'rk.out' using 1:6 History of the human population on earth ======================================== Let us take a tour of the history of human population on Earth. We can start by perusing the `Wikipedia page on historical population estimates `_ as well as this `PRB data study on how many people have lived on Earth `_. Also spend some time exploring the `"Our World in Data" interactive graphs `_ Expand the title on "All our charts on World Population Growth", and pick the population by country since 1500 and try to understand what areas are exponential. Then look at the link "World population since 10,000 BCE (OurWorldInData series)". Download the data for this graph and zoom in on some specific periods. Look at both linear and logarithmic scales. Following the indications shown in `this Nature article `_ we can look at the table below and seek certain interesting periods in the data. .. _table-human-population-history: .. table:: Periods of interest in human population history ========== ======== ================================= Start End What to look for ========== ======== ================================= -10000 -4000 Agricultural revolution -4000 -600 Early empires -1000 300 Alexander and Rome 1 300 Imperial Rome 1 1600 Largely steady world population 1200 1400 Medieval black death 1500 present Modern world 1850 present Industrial revolution 1900 present Large scale science ========== ======== ================================= Although the earth's population as a whole appears to still be in an exponential growth phase, the Pew Research Center predicts that it will `flatten by the end of the 21st century `_ This type of function is not exponential growth anymore: it shows exponential growth, but that then slows down and we end up with what is called the Logistic Function we have introduced. Predator-prey systems and the Lotka-Volterra differential equations =================================================================== The Lotka-Volterra equations describe how the populations of two species (where one is a predator to the other) change in time. The equations ------------- The equations are *coupled first order ordinary differential equations* and they look like this: .. math:: \frac{dx(t)}{dt} & = \alpha x(t) - \beta x(t) y(t) \\ \frac{dy(t)}{dt} & = -\gamma y(t) + \delta x(t) y(t) This system has two functions :math:`{\bf x(t)}` population density of prey :math:`{\bf y(t)}` population density of predator and it has four coefficients: :math:`\alpha` per capita growth rate of prey :math:`\beta` effect of presence of predators on the prey death rate (how viciously do predators kill prey) :math:`\gamma` per capita death rate of predator :math:`\delta` effect of presence of prey on predator's growth rate (how good are the prey as food) You should look at these equations and try to understand how the various quantities interact to model the situation. A reasonable guide is the `wikipedia discussion of the biological interpretation `_ (which is `archived here `_) Solving the equations --------------------- There is no known *analytic* solution for these equations, but following the example from :ref:`differential-equations/differential-equations:Differential Equations` we can implement a simple program in Python or in C to solve these equations using Euler's method. .. .. literalinclude:: lotka_volterra.py :caption: lotka_volterra.py :language: python Go ahead and download the program :download:`lotka_volterra.py` and run it, saving the output into a file, and then plotting it: .. code-block:: console $ chmod +x ./lotka_volterra.py $ ./lotka_volterra.py > l-v.out $ gnuplot # at the gnuplot> prompt you can type: set grid plot 'l-v.out' using 1:2 with lines title 'prey' replot 'l-v.out' using 1:3 with lines title 'predator' Further reading =============== * https://www.youtube.com/watch?v=NYq2078_xqc - Khan Academy video with pleasant intro to cycles and real examples, 5min. * https://www.youtube.com/watch?v=mFDiiSqGB7M - crash course on predator-prey ecology * https://en.wikipedia.org/wiki/Lotka%E2%80%93Volterra_equations#A_simple_example * http://www.scholarpedia.org/article/Predator-prey_model * http://mc-stan.org/users/documentation/case-studies/lotka-volterra-predator-prey.html Still have to look at articles on 3-way predator-prey: * http://emis.ams.org/journals/HOA/JAMDS/3/2155.pdf * chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/https://www.cs.unm.edu/~forrest/classes/cs365/lectures/Lotka-Volterra.pdf * http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.360.1552&rep=rep1&type=pdf * http://disi.unal.edu.co/~gjhernandezp/sim/lectures/DeterministicModelsAndChaos/PopulationModels/LotkaVolterra3species.pdf And how about simple models of a full society collapse? * https://en.wikipedia.org/wiki/Collapse:_How_Societies_Choose_to_Fail_or_Succeed * http://necsi.edu/projects/evolution/co-evolution/pred-prey/co-evolution_predator.html * https://www.ted.com/talks/jared_diamond_on_why_societies_collapse * https://arxiv.org/abs/1002.0068 * https://faustusnotes.wordpress.com/2014/05/15/mathematical-modeling-of-civilization-collapse/ Cliometrics * https://en.wikipedia.org/wiki/Cliometrics