class: center, middle, inverse, title-slide .title[ # Models & Density-independent growth ] .author[ ### Christopher Moore ] .date[ ### Week 02 ] --- class: inverse, center, middle # Introduction to models --- # Types of models Form | Time | Space | Predictability :----------:|:----------:|:------------------:|:--------------: Dynamical | Continuous | Non-spatial | Deterministic Verbal | Discrete | Spatially-implicit | Stochastic Graphical | | Spatial-explicit | Statistical | | | Etc. | | | --- ## Continuous and discrete time ### Continous * Variables in the model change all of the time * Generations are *overlapping* * There is no inherent delay between "events" * No built-in periodicity (e.g., seasonality) -- ### Discrete * Variables in the model change at predefined, constant increments * Generations can be *non-overlapping* * There is a delay between "events" * Commonly used for periodic (e.g., seasonal) systems --- ## Parts of dynamical models ### State variables: change over time * Examples in non-ecological models include: concentration, position, temperature, current, allele frequency, GDP * Examples in ecological models include: abundance, density, position, yield, resource concentration -- *** ### Parameters: constants that generally don't change over time * Examples in non-ecological models: slection coefficients, distance, viscosity, mutation, decay * Examples in ecological models: births, deaths, strength of density dependence, sign (e.g., predators always have a - effect on prey) --- ## General anatomy of a dynamical model ### State variable(s) * For this course, we are focused on abundance or density, commonly abbreviated as `\(N\)` * Time will be abbreviated as `\(t\)` -- ### Generally $$ \frac{\Delta N}{\Delta t} = f(N) $$ -- #### Some conventions * For discrete-time models we use `\(N_t\)` * For continuous-time models we use `\(N(t)\)`. Although for this class, and generally throughout the ecological literature (including in the book), we simply write `\(N\)` --- ## Anatomy of a dynamical model: discrete time * General dyanmic model $$f(N) = \frac{\Delta N}{\Delta t} = $$ -- * Geometric growth: constant growth, discrete time `$$N_{t+1} = \lambda N_t$$` -- * Writing a function in `R` ```r geom_growth <- function(Nt, lambda) { *Nt1 <- lambda*Nt return(Nt1) } ``` -- * An example with `\(N_t = 1\)` and `\(\lambda = 1.1\)`: ```r geom_growth(Nt = 1, lambda = 1.1) ``` ``` ## [1] 1.1 ``` --- ## Anatomy of a dynamical model: continuous time * General dyanmic model $$f(N) = \frac{\Delta N}{\Delta t} = $$ -- * Exponential growth: constant growth, continuous time `$$\frac{\mathrm{d}N}{\mathrm{d}t} = rN$$` -- * Writing a function in `R` ```r exp_growth <- function(Nft, r) { * dNdt <- r*Nft return(dNdt) } ``` -- * An example with `\(N = 1\)` and `\(r = 0.1\)`: ```r exp_growth(Nft = 1, r = 0.1) ``` ``` ## [1] 0.1 ``` --- ## Continuous and discrete time (with equations) ### Continous * Variables in the model change all of the time * Generations are *overlapping* * There is no inherent delay between "events" * No built-in seasonality `$$\frac{\mathrm{d}N}{\mathrm{d}t} = f(N)$$` -- ### Discrete * Variables in the model change at predefined, constant increments * Generations can be *non-overlapping* * There is a delay between "events" * Commonly used for periodic (e.g., seasonal) systems $$ N_{t+1} = f(N_t) $$ --- class: inverse, center, middle # Density-indepedent change --- # The simplest models: constant change .pull-left[ Geometric growth for `\(\lambda = 1.1\)` and `\(N_1 = 2\)`: $$ \vphantom{\frac{dN}{dt}} \lambda N_t $$ <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-5-1.png" width="300" height="300" /> ] -- .pull-right[ Exponential growth for `\(r = 0.1\)` and `\(N(1) = 2\)`: $$ \frac{\mathrm{d}N}{\mathrm{d}t} = rN $$ <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-6-1.png" width="300" height="300" /> ] --- # Note that continous time is always greater than discrete time <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-7-1.png" width="400" height="400" style="display: block; margin: auto;" /> --- # The simplest models: constant change .pull-left[ Geometric growth for `\(\lambda = 0.75\)` and `\(N_1 = 10\)`: $$ \vphantom{\frac{dN}{dt}} N_{t+1} = \lambda N_t $$ <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-8-1.png" width="300" height="300" /> ] -- .pull-right[ Exponential growth for `\(r = -0.25\)` and `\(N(1) = 10\)`: $$ \frac{\mathrm{d}N}{\mathrm{d}t} = rN $$ <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-9-1.png" width="300" height="300" /> ] --- # Note that continous time is always greater than discrete time <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-10-1.png" width="400" height="400" style="display: block; margin: auto;" /> --- class: inverse, center, middle # So I have a model, what do I do with it? --- # What do to with models <small>(including density-independent growth and everything we wil cover for this course)</small> * Analyze it! * Simulate it * Solve it * Find long-term behavior * Determine behavior if perturbed * Make predictions -- * Vizualize it! * Plot a time series of `\(t\)` and population size ( `\(N\)` ) * Plot population size ( `\(N\)` ) and population growth `\(\frac{\Delta N}{\Delta t}\)` * Plot population size ( `\(N\)` ) and growth per individual (per-capita) `\(\frac{1}{N}\frac{\Delta N}{\Delta t}\)` --- # Analyze it!: simulation .pull-left[ **Code and output** for discrete-time growth <small>(simulating it)</small>: ```r max_time <- 20 timesteps <- 1:100 N <- vector(mode = "numeric", length = max_time) N[1] <- 2 lambda <- 1.1 for (i in 2:max_time) { N[i] <- lambda*N[i-1] } round(N[1:3], 2) ## [1] 2.00 2.20 2.42 round(N[(max_time - 2):max_time], 2) ## [1] 10.11 11.12 12.23 ``` ] .pull-right[ **Code and output** for continuous-time growth <small>(not simulating it, but using the solution [simulating differential equations is a bit more involved])</small>: ```r N0 <- 2 r <- 0.1 timesteps <- seq(0, 20, by = 1) len_time <- length(timesteps) N <- N0*exp(r*timesteps) round(N[1:3], 2) ## [1] 2.00 2.21 2.44 round(N[(len_time - 2):len_time], 2) ## [1] 12.10 13.37 14.78 ``` ] --- # Analyze it!: solve it .pull-left[ **Discrete time**: `$$\begin{align} N_{t+1} &= \lambda N_t \\ N_{t+2} &= \lambda N_{t+1} \\ N_{t+2} &= \lambda (\lambda N_t) \\ N_{t+2} &= \lambda ^2 N_t \\ N_{t+3} &= \lambda ^3 N_t \\ ... \\ N_{t} &= \lambda ^t N_0 \end{align}$$` ] -- .pull-right[ **Continuous time**: `$$\begin{align} \frac{\mathrm{d}N}{\mathrm{d}t} &= rN \\ \frac{1}{N}\mathrm{d}N &= r \mathrm{d}t \\ \int_{N(0)}^{N(T)} \frac{1}{N}\mathrm{d}N &= \int_{0}^{T} r \mathrm{d}t \\ \log _e(N)\Big|_{N(0)}^{N(T)} &= rt\Big|_0^T \\ \log _e\left(\frac{N(T)}{N(0)}\right) &= rT \\ N(T) &= N(0)e^{rT} \end{align}$$` ] --- # Analyze it!: Find long-term behavior, determine behavior if perturbed, make predictions Not too much happening with this simple, linear model: * Long-term behavior: continues to grow or shrink at a constant rate * Determinted behavior if perturbed: continues to grow or shrink at a constant rate * Make predictions: continues to grow or shrink at a constant rate --- # Vizualize it!: Plot a time series <small>(already did it)</small> .pull-left[ Geometric growth for `\(\lambda = 1.1\)` and `\(N_1 = 2\)`: $$ \vphantom{\frac{\mathrm{d}N}{\mathrm{d}t}} N_{t+1} = \lambda N_t $$ <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-13-1.png" width="300" height="300" /> ] -- .pull-right[ Exponential growth for `\(r = 0.1\)` and `\(N(1) = 2\)`: $$ \frac{\mathrm{d}N}{\mathrm{d}t} = rN $$ <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-14-1.png" width="300" height="300" /> ] --- # Vizualize it!: Plot population growth against density .pull-left[ Geometric growth for `\(\lambda = 1.1\)` and `\(N_1 = 2\)`: <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-15-1.png" width="300" height="300" /> ] -- .pull-right[ Exponential growth for `\(r = 0.1\)` and `\(N(1) = 2\)`: <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-16-1.png" width="300" height="300" /> ] --- # Vizualize it!: Plot per-capita growth against density .pull-left[ Geometric growth for `\(\lambda = 1.1\)` and `\(N_1 = 2\)`: <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-17-1.png" width="300" height="300" /> ] -- .pull-right[ Exponential growth for `\(r = 0.1\)` and `\(N(1) = 2\)`: <img src="Wk02Models-DensIndGrowth_files/figure-html/unnamed-chunk-18-1.png" width="300" height="300" /> ] --- # A note about an assumption of *r* ### `\(\lambda\)` and `\(r\)` are the difference between births and deaths -- Specific to our discrete-time density-independent models, this means: `$$N_{t+1} = \lambda N_t = \left(B - D\right)N_t = BN_t - DN_t$$` -- And the solution would be: `$$N_t = N_0(B - D)^t$$` -- Specific to our continous-time density-independent models, this means: `$$\frac{\mathrm{d}N}{\mathrm{d}t} = rN = (b-d)N$$` -- And the solution would be: `$$N(t) = N(0)e^{t(b - d)}$$`